登录后我在检索个人资料页面时遇到问题,我不知道如何开始 我有所有登录代码我不知道登录后如何使用会话显示个人资料信息请帮助我我不知道还能做什么
登录.php
<?php
include('com.php');
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$email = $_POST['email'];
$password = $_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysql_real_escape_string($email);
$password = mysql_real_escape_string($password);
$sql = "SELECT * FROM $tbl_name WHERE email='$email' AND password='$password'";
$result = mysql_query($sql);
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $email and $password, table row must be 1 row
if ($count == 1) {
// Register $email, $password and redirect to file "report.php"
session_register("email");
session_register("password");
header("location:profile.php");
} else {
echo "Wrong Username or Password";
}
?>
1.在标头中使用 get 方法发送用户电子邮件 ID
登录.php
header("Location: profile.php?email=$email");
^ must be a space here
然后在个人资料页面中获取它
简介.php
$email= $_GET["email"];
在此处显示与$email匹配的数据库中的数据
2.会话的另一种使用方式
登录.php
session_start();
$_SESSION["email"] = $email;
$_SESSION["password"] = $password;
header("Location: profile.php");
从"配置文件"页获取此值
简介.php
session_start();
$email = $_SESSION["email"];
在此处显示与$email匹配的数据库中的数据
session_register
自 PHP 5.3 起已被弃用,并从 PHP 5.4 开始被删除。不要使用它。
要回答您的问题,您需要首先将用户分配给会话变量...
$_SESSION['user_id'] = $user_id;
然后在后续页面请求中...
$q = "SELECT * FROM users WHERE id = " . (int) $_SESSION['user_id'];
有更好的方法来写这个。这只是一个简单的例子,让你走上正确的轨道。