我为 login.php 拥有的 PHP 脚本是下面的代码。
<?php
include 'dbc.php';
$user_email = mysql_real_escape_string($_POST['email']);
if ($_POST['Submit']=='Login')
{
$md5pass = md5($_POST['pwd']);
$sql = "SELECT id,user_email FROM users WHERE
user_email = '$user_email' AND
user_pwd = '$md5pass' AND user_activated='1'";
$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
session_start();
list($user_id,$user_email) = mysql_fetch_row($result);
// this sets variables in the session
$_SESSION['user']= $user_email;
if (isset($_GET['ret']) && !empty($_GET['ret']))
{
header("Location: $_GET[ret]");
} else
{
header("Location: myaccount.php");
}
//echo "Logged in...";
exit();
}
header("Location: login.php?msg=Invalid Login");
//echo "Error:";
exit();
}
?>
<link href="styles.css" rel="stylesheet" type="text/css">
<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>
<p> </p><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#d5e8f9" class="mnuheader" >
<div align="center"><font size="5"><strong>Login
Members</strong></font></div></td>
</tr>
<tr>
<td bgcolor="#e5ecf9" class="mnubody"><form name="form1" method="post" action="">
<p> </p>
<p align="center">Your Email
<input name="email" type="text" id="email">
</p>
<p align="center"> Password:
<input name="pwd" type="password" id="pwd">
</p>
<p align="center">
<input type="submit" name="Submit" value="Login">
</p>
<p align="center"><a href="register.php">Register</a> | <a href="forgot.php">Forgot</a></p>
</form></td>
</tr>
我想创建一个会话变量,如 $_SESSION['user']= $user_email; 我可以在其他页面中使用。问题是我不知道该怎么做,我想从我的数据库中选择一个不同的行,称为点。所以它会像 $sql = "SELECT id,user_email,points FROM users WHERE user_email = '$user_email' AND user_pwd = '$md5pass' AND user_activated='1'";
就像我说的,我希望它选择点数,以便可以在会话开始的所有页面上使用它。
这是一个与登录用户相呼应的帐户页面。但我希望它也能从我的数据库中回显点行。
<?php
session_start();
if (!isset($_SESSION['user']))
{
die ("Access Denied");
}
?>
<h2>My Account </h2>
<?php if (isset($_SESSION['user'])) { ?>
<p>Logged as <?php echo $_SESSION['user']; ?>
<a href="settings.php">Settings</a>
<a href="logout.php">Logout</a> </p>
<?php } ?>
谢谢您的帮助!