嘿,我都在为一个简单的会员系统而苦苦挣扎。我已经编码了一段时间,但在 php(主要是 java)中编码不多,所以如果有任何关于查看内容的帮助或建议,我将不胜感激。我似乎总是检查简单的错误,虽然我已经在语法检查器中检查过它,但我确信它是非常小的
开始..
我的 login.php 文件允许用户登录,如果他们有用户名和密码,如果没有发送适当的响应。但是,当我使用现有的用户名和密码登录时,它会转到显示您的姓名和链接以转到成员部分的下一页,但是当单击链接时,成员部分似乎无法识别我的 $_SESSION 值,因此要求用户再次登录。
<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['$userid'];
$username = $_SESSION['$username'];
?>
<html>
<head>
<title>Member system - login</title>
</head>
<body>
<?php
$form = "<form action='./login.php' method='post'>
<table>
<tr>
<td>username :</td>
<td><input type='text' name='user'/></td>
</tr>
<tr>
<td>password :</td>
<td><input type='password' name='password'/></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='loginbtn' value='Login'/></td>
</tr>
</table>
</form>";
if($_POST['loginbtn']) {
$user = $_POST['user'];
$password = $_POST['password'];
if($user) {
if($password) {
require("connect.php");
$password = md5(md5("12345".$password."54321"));
//make sure login info correct
$query = mysql_query("SELECT * FROM user WHERE username='$user'");
$numrows = mysql_num_rows($query);
if($numrows == 1) {
$row = mysql_fetch_assoc($query);
$dbid = $row['id'];
$dbuser = $row['username'];
$dbpass = $row['password'];
$dbactive = $row['active'];
if($password == $dbpass) {
if($dbactive == 1) {
//set seesion info
$_SESSION['userid'] = $dbid;
$_SESSION['username'] = $dbuser;
echo "you have been logged in as <b>$dbuser</b> <a href='./member.php'>click here</a> to go to the member page";
}
else
echo "You must be an active member. $form";
}
else
echo "you did not enter the correct password. $form";
}
else
echo "The user name you entered was not found. $form";
mysql_close();
}
else
echo "you must enter your password. $form";
}
else
echo "you must enter a user name. $form";
}
else
echo $form;
?>
这是我完成大部分工作的登录表单
<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['$userid'];
$username = $_SESSION['$username'];
?>
<html>
<head>
<title> Member system : Members</title>
</head>
<body>
<?php
if($username && $userid) {
echo "Welcome <b>$username</b>, <a href='./logout.php'>logout</a>";
}
else
echo "Please login in to veiw this page <a href='./login.php'>Login in</a>";
?>
</body>
</html>
这是我的成员表单,它似乎无法识别会话并要求用户再次登录。
我知道这对某人来说是显而易见的尴尬,我为我的无知道歉,但我会从中吸取教训,所以如果有人能帮助我,我将不胜感激。
问候迈克