你好我现在在welcome.php中有这个代码,当用户使用login.php登录时,他被redirect.php重定向到welcome.php
<?php session_start();
if(isset($_SESSION['userName']))
{
echo'<h1>WELCOME ' . $_SESSION['userName'] . '</h1>';
echo'<h1>WELCOME ' . $_SESSION['R'] . '</h1>';
echo'<br> <h1> <a href="logout.php">LOGOUT</a> </h1>';
}
else
{
echo 'You are not logged In <br>';
echo'<a href="index.php">LOGIN</a>';
} ?>
我想从我的mysql数据库中显示R,但我无法搜索很多时间,但我无法找到答案吗?
答案 0 :(得分:0)
当成员登录时,我使用类似的东西。查询该用户的数据库,然后设置会话变量
//Retrieve username and password from login feilds
$uname = clean($_POST['uname']);
$password = clean($_POST['password']);
//Query Database
$qry="SELECT * FROM tbl_members WHERE userName='$uname' AND pass='".md5($_POST['password'])."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
// Set session variables
$_SESSION['SESS_USER_ID'] = $member['id'];
$_SESSION['SESS_USER_NAME'] = $member['userName'];
$_SESSION['SESS_USER_DATE'] = $member['R'];
session_write_close();
$result=mysql_query($sql) or die(mysql_error());
//goto member homepage
header("location: ../index.php");
}else {
//Login failed - try again
header("location: ../login.php");
exit();
}
}else {
die("Query failed");
}