有人可以帮忙,我在PHP error.log中有以下错误
[Tue Dec 19 12:08:22.887574 2017] [:error] [pid 32196] [client xx.xx.xx.x:20560] PHP Notice: Undefined offset: 8 in /var/www/html/page.php on line 55, referer: view.php?1x=8
和我认为导致这个问题的PHP代码是:
$i = isset($_SESSION['i']) ? $_SESSION['i'] : 0;
// echo $_SESSION['websites'][$i];
$website = explode(";", $_SESSION['websites'][$i]);
// echo $website[0];
$i++;
$_SESSION['i'] = $i;
我真的不知道$i = isset($_ SESSION [‘i’])? $_SESSION [‘i’]:0;不
谢谢
session_start();
$i = isset($_SESSION['i']) ? $_SESSION['i'] : 0;
if ($_SESSION['i'] < $sesioni1x) {
// echo $_SESSION['websites'][$i];
$website = explode(";", $_SESSION['websites'][$i]);
// echo $website[0];
$i++;
$_SESSION['i'] = $i;
header("Location: $website[0]"); //redirect
die();
// echo $website[0];
// echo $sesioni1x;
// echo $website[0]." Frame-URL<br>";
// $_SESSION['actual_website'] = $website[0];
}
if ($_SESSION['i'] == $sesioni1x) {
$handle = fopen($list1x, "a"); //open file to append content to csv file
fputcsv($handle, $_SESSION['addwebsite'], ";"); //insert line in opened file
fclose($handle); //close file
header("Location: index.php"); //redirect
die();
// echo "session = var";
}
这是我得到这个警告的完整代码,我必须说脚本正在完成他的工作,但我想摆脱错误
源中的$_SESSION [‘i’]为0
解决方法:
这是三元运算符.基本上它是一个简单的if / else.
$i = (isset($_SESSION['i']) ? $_SESSION['i'] : 0);
为了帮助您理解它,这个代码在一行
if(isset($_SESSION['i'])){
$i=$_SESSION['i'];
}
else{
$i=0;
}