-3

我的 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)){

为什么要扔这个???

4

4 回答 4

2

语句的 if 和 else 之间不能有任何内容:

if ($condition) {
    doSomething();
}
// Nothing can go here!
else {
    doSomethingElse();
}
于 2012-04-09T00:18:57.633 回答
2

echo之间不能有一个。把它拿出来。ifelse

if(empty($sess_id)) {    # If no sessionID redirect back home.
    header('Location: ../index.php');
} else {
于 2012-04-09T00:19:19.447 回答
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)){

简单的修复:)

于 2012-04-09T00:28:24.647 回答
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.....
于 2012-04-09T00:39:26.247 回答