解析错误:语法错误,意外'如果'(T_IF),如何解决?

时间:2015-04-06 12:15:24

标签: php html syntax

我制作了一个登录脚本,它是索引:

<?php
        session_start() 
        if(isset($_POST['username'])&&!empty($_POST['username'])){
        header("location:login.php");
    }
    echo "selamat datang ".$_SESSION['username'];
    ?>
    <br/><br/><br/>
    <a href="logout.php">Logout</a>

当我尝试它时,它会告诉我:

  

解析错误:语法错误,意外&#39;如果&#39; (T_IF)

有人知道吗?

3 个答案:

答案 0 :(得分:0)

空格不合适,请在;

之后使用session_start
<?php
session_start();
if(isset($_POST['username']) && !empty($_POST['username'])){
    header("location:login.php");
}
echo "selamat datang ".$_SESSION['username'];
?>
<br/><br/><br/>
<a href="logout.php">Logout</a>

答案 1 :(得分:0)

MISSING ; AFTER_start

<?php
        session_start(); 
        if(isset($_POST['username'])&&!empty($_POST['username'])){
        header("location:login.php");
    }
    echo "selamat datang ".$_SESSION['username'];
    ?>
    <br/><br/><br/>
    <a href="logout.php">Logout</a>

答案 2 :(得分:0)

试试这个......

<?php
        session_start(); //miss semicolon
        if(isset($_POST['username'])&&!empty($_POST['username'])){
        header("location:login.php");
    }
    echo "selamat datang ".$_SESSION['username'];
    ?>
    <br/><br/><br/>
    <a href="logout.php">Logout</a>