我的php文件片段
session_start(); // Bring in old sessionID
$sess_id = session_id(); // assign old session variable to $sess_id var
if(empty($sess_id)){ # If no sessionID redirect back home.
header('Location: ../index.php');
}
else(!empty($sess_id)){
文件中的第9行:
else(!empty($sess_id)){
为什么要扔这个?
答案 0 :(得分:2)
在声明的if和else之间不能有任何内容:
if ($condition) {
doSomething();
}
// Nothing can go here!
else {
doSomethingElse();
}
答案 1 :(得分:2)
echo
和if
之间不能有else
。拿出来。
if(empty($sess_id)) { # If no sessionID redirect back home.
header('Location: ../index.php');
} else {
答案 2 :(得分:1)
session_start(); // Bring in old sessionID
$sess_id = session_id(); // assign old session variable to $sess_id var
if(empty($sess_id)){ # If no sessionID redirect back home.
header('Location: ../index.php');
}
else(!empty($sess_id)){
将其更改为
else if(!empty($sess_id)){
简单修复:)
答案 3 :(得分:0)
或者使用带有die()的多个if语句,如:
session_start(); // Bring in old sessionID
$sess_id = session_id(); // assign old session variable to $sess_id var
if(empty($sess_id)){ # If no sessionID redirect back home.
die(header('Location: ../index.php')); #Stop script and go to ../index.php
}
if(!empty($sess_id)){
....
die('some.php');
}
....other statements.....