Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义索引';邀请';注册页面出错_Php_Joomla_Joomla2.5 - Fatal编程技术网

Php 未定义索引';邀请';注册页面出错

Php 未定义索引';邀请';注册页面出错,php,joomla,joomla2.5,Php,Joomla,Joomla2.5,我只是在进入注册页面时出现此错误 Undefined index: invite 但是当我进入同一页时 url?invite=2000 this error is not shown... 下面代码的第二行显示了错误 $mySess = JFactory::getSession(); $_SESSION['fromid'] = $_GET['invite']; $fromid = $_SESSION['fromid']; 如果“invite”未在url

我只是在进入注册页面时出现此错误

Undefined index: invite
但是当我进入同一页时

url?invite=2000 this error is not shown...
下面代码的第二行显示了错误

    $mySess = JFactory::getSession();       
    $_SESSION['fromid'] = $_GET['invite'];
    $fromid = $_SESSION['fromid'];

如果“invite”未在url中使用,我如何初始化它…

使用
isset
函数,如下所示:

$mySess = JFactory::getSession();       
$_SESSION['fromid'] = isset($_GET['invite']) ? $_GET['invite'] : '';
$fromid = $_SESSION['fromid'];

使用
isset
功能,如下所示:

$mySess = JFactory::getSession();       
$_SESSION['fromid'] = isset($_GET['invite']) ? $_GET['invite'] : '';
$fromid = $_SESSION['fromid'];

这基本上是Matt的解决方案,但没有复杂的
if-then-else
-速记

$mySess = JFactory::getSession();       

// this value will be used if you did not pass the parameter invite to your script
$inviteDefaultValue = -1;

// isset checks if the variable exists. 
// you can also use array_key_exists("invite", $_GET)
if (isset($_GET['invite']))
{
    // $_GET['invite'] is set, so we can use it
    $_SESSION['fromid'] = $_GET['invite']);
}
else
{
    // $_GET['invite'] is not set, so use your default value here
    $_SESSION['fromid'] = $inviteDefaultValue;
}

$fromid = $_SESSION['fromid'];


这基本上是Matt的解决方案,但没有复杂的
if-then-else
-速记

$mySess = JFactory::getSession();       

// this value will be used if you did not pass the parameter invite to your script
$inviteDefaultValue = -1;

// isset checks if the variable exists. 
// you can also use array_key_exists("invite", $_GET)
if (isset($_GET['invite']))
{
    // $_GET['invite'] is set, so we can use it
    $_SESSION['fromid'] = $_GET['invite']);
}
else
{
    // $_GET['invite'] is not set, so use your default value here
    $_SESSION['fromid'] = $inviteDefaultValue;
}

$fromid = $_SESSION['fromid'];


也许简洁,但我不会说复杂。:)尽管如此,对可能的解决方案还是有很好的补充。我只是想,不知道
isset
的用户也不会知道条件的速记。肯定不会受伤的!:-也许是凤蝶,但我不会说复杂。:)尽管如此,对可能的解决方案还是有很好的补充。我只是想,不知道
isset
的用户也不会知道条件的速记。肯定不会受伤的!:-P