第35行意外结束文件错误

时间:2016-02-07 17:50:29

标签: php mysql

错误是

  

解析错误:语法错误,第35行的C:\ xampp \ htdocs \ project \ inc \ header.inc.php中的文件意外结束

以下代码适用于错误的头文件:

<?php 
include ("./inc/connect.inc.php");
session_start();
if (!isset($_SESSION["user_login"])){
}
else
{
header("location: home.php")
?>


<html>
     <head>
         <title>Memory Lane</title>
         <link rel="stylesheet" type="text/css" href="./css/style.css"
 </head>
     <body>
         <div class="HeaderMenu">
         <div id="wrapper">
             <div class="logo">
                 <img src="./Image/Memorylane_logo.jpg"/>
             </div>
             <div class="search_box"> 
                <form action="search.php" method="GET" ID="search"> 
                <input type="text" name="q" size="60" placeholder="Search ..."/>
                </form>
             </div>
             <div id="menu"> 
             <a href ="#"/>Home</a>
             <a href ="#"/>About</a>
             <a href ="#"/>Sign Up</a>
             <a href ="#"/>Sign In</a>
             </div>
         </div>
    </div>

3 个答案:

答案 0 :(得分:1)

您错过文件末尾的结束}以关闭else块:

         </div>
    </div>
<?php
}

?>

编辑:注意到您正在尝试重定向。在这种情况下,}应该在以下行之后:

header("location: home.php")

答案 1 :(得分:1)

你在这里搞了一个结束}

<?php 
include ("./inc/connect.inc.php");
session_start();
if (!isset($_SESSION["user_login"])){
}
else
{
header("location: home.php"); // <-- You were also missing a semicolon here 
exit; // <-- and an exit is a good thing to use after an header
} // <--- You should add this one
?>

如果你缩进你的代码,也会更容易找到丢失的blosing括号,如下所示:

<?php 
   include ("./inc/connect.inc.php");
   session_start();
   if (!isset($_SESSION["user_login"])){
    //Also putting some code here would be a good idea
   } else {
     header("location: home.php");
     exit;
   }
?>

答案 2 :(得分:0)

使用以下代码更改您的身份。没有提到else结束,在此行header("location: home.php")之后给出了半克隆。

<?php 
include ("./inc/connect.inc.php");
session_start();
if (!isset($_SESSION["user_login"])){
}
else
{
header("location: home.php");
}
?>