use*_*600 18 php error-handling
这是我的PHP代码:
<?php include("inc/incfiles/header.inc.php")?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Index</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Welcome <?php echo ($_SESSION['SESS_fname']);?></h1>
<a href="member-profile.php">My Profile</a> | <a href="logout.php">Logout</a>
<p>This is a password protected area only accessible to members. </p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我知道错误的代码,但我不知道如何解决它.我的错误说:"注意:未定义的变量:第9行的C:\ xampp\htdocs\Smasher\member-index.php中的_SESSION"
如何修复错误,以便说出用户的名字?调用mySQL数据库表中的第一个名称fname.
Yas*_*azk 37
加
session_start();
Run Code Online (Sandbox Code Playgroud)
在任何HTML之前的页面开头
你会有类似的东西:
<?php session_start();
include("inc/incfiles/header.inc.php")?>
<html>
<head>
<meta http-equiv="Content-Type" conte...
Run Code Online (Sandbox Code Playgroud)
不要忘记删除之前的空间
首先,您需要在要session_start()在其上使用SESSION变量的任何页面的顶部添加。
此外,您应该检查以确保在使用变量之前先设置变量:
if(isset($_SESSION['SESS_fname'])){
echo $_SESSION['SESS_fname'];
}
Run Code Online (Sandbox Code Playgroud)
或者,简单地说:
echo (isset($_SESSION['SESS_fname']) ? $_SESSION['SESS_fname'] : "Visitor");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87134 次 |
| 最近记录: |