各位大虾,php提示红色代码部分,有parse error,语法错误,但是没有具体错在哪里了??我想了半天,还是找不到答案,拜托各位GGJJDDMM,帮我看看,小妹先谢了:-)<?php
session_start();//启动会话
if(isset($_COOKIE["username"])){ //若在cookie中保存着用户名
$username=$_COOKIE["username"]; //则从cookie中读取用户名,赋值给变量username
} else { //否则
$username="游客"; //访问者的身份为“游客”
}
if (isset($_GET["action"])){
setcookie ("username", false , time()-3600);
header ("Location: cookie.php");
exit;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>网站首页</title>
</head><body>
<?php //该段代码,用于连接数据库,也可以直接将db_connectin.php的内容写在这里
include_once("db_connection.php");
/* include()语句只有在被执行时才会读入要包含的文件。在错误处理方便,使用include语句,如果发生包含错误,程序将跳过include语句,虽然会显示错误信息但是程序还是会继续执行!include_once()只包含一次
*/
mysql_query("set names GBK");
?><strong>网站首页</strong>
<?php
echo "<a href=\"cookie.php\">登录</a>\n";
if ($username<>"游客") //对登录用户显示注销链接 {
echo "<a href=\"cookie.php?action=logout\">注销</a>\n";
}
echo "<p>{$username},欢迎您!</p>\n";
?>
</body></html>
session_start();//启动会话
if(isset($_COOKIE["username"])){ //若在cookie中保存着用户名
$username=$_COOKIE["username"]; //则从cookie中读取用户名,赋值给变量username
} else { //否则
$username="游客"; //访问者的身份为“游客”
}
if (isset($_GET["action"])){
setcookie ("username", false , time()-3600);
header ("Location: cookie.php");
exit;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>网站首页</title>
</head><body>
<?php //该段代码,用于连接数据库,也可以直接将db_connectin.php的内容写在这里
include_once("db_connection.php");
/* include()语句只有在被执行时才会读入要包含的文件。在错误处理方便,使用include语句,如果发生包含错误,程序将跳过include语句,虽然会显示错误信息但是程序还是会继续执行!include_once()只包含一次
*/
mysql_query("set names GBK");
?><strong>网站首页</strong>
<?php
echo "<a href=\"cookie.php\">登录</a>\n";
if ($username<>"游客") //对登录用户显示注销链接 {
echo "<a href=\"cookie.php?action=logout\">注销</a>\n";
}
echo "<p>{$username},欢迎您!</p>\n";
?>
</body></html>
...
}
...
}
或者 if ($username <>"游客") 都不行的,还是提示有错误啊,拜托各位大哥大姐再帮我看看,多谢多谢
1.你第一段PHP代码和下面的HTML代码是在一个面页?如果是看第2,不是的话,你就要问问自己username哪来的?
2.检查if ($username <>"游客")附近有没有特殊字符或者是汉字的字符,比如;是不是汉字;等.
我用的 Zend Studio for Eclipse 就比较好用
if ($username <>"游客") //对登录用户显示注销链接 {