gpt4 book ai didi

php - 登录后使用 session 检索单个用户数据

转载 作者:行者123 更新时间:2023-11-29 00:09:40 25 4
gpt4 key购买 nike

<分区>

我是这个领域的新手,这是我第一次使用 session ,这个问题可能看起来很基本,但如果有人能帮助我,我将不胜感激。目前我已经使用 session 创建了一个登录和注销页面,并希望显示已登录的特定用户的数据。用户在登录后被重定向到 retailer_login.php,除了登录表单之外,整个登录有 4 个页面和注销过程。

retailer_login.php, retailer_session.php, retailer_profile.php, retailer_logout.php

每个页面都工作正常,但我只能显示数据库中用户的单个数据列,但我希望显示存储的有关该特定用户的全部信息。

数据库

    Id  name  email          password  country  city   state  occupation
1 sam sam@gmail.com sam XYZ ZBC QWE student

零售商_登录页面

<?php
session_start(); // Starting Session

if (isset($_POST['submit'])) {
try {
if (empty($_POST['email']) || empty($_POST['password'])) {
throw new Exception("email or Password is invalid");
} else {
// Define $email and $password
$email = $_POST['email'];
$password = $_POST['password'];
// To protect MySQL injection for Security purpose
$email = stripslashes($email);
$password = stripslashes($password);
$mail = mysql_real_escape_string($email);
$password = mysql_real_escape_string($password);
//Etablishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("abc.com", "abc", "abc");
// Selecting Database
$db= mysql_select_db("abc", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from retailerregister where password='$password' AND email='$email'", $connection);
$rows = mysql_num_rows($query);

if ($rows != 1)
throw new Exception("email or Password is invalid");

$_SESSION['login_user'] = $email; // Initializing Session
header("location: retailer_profile.php"); // Redirecting To Other Page
mysql_close($connection); // Closing Connection
}
}
catch (Exception $e) {
$_SESSION['login_error'] = $e->getMessage();
header("Location: index.html");
}
}
?>

retailer_profile 页面

<?php
include('retailer_session.php');
?>

<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Welcome to your homepage</title>

<meta name="viewport" content="width=device-width", initial-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/styles.css" rel="stylesheet" />
<link href="css/carousel.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>

<body>
<div id="profile">
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
<a href="#" class = "navbar-brand"> <id="welcome">Welcome : <i><?php echo $login_session; ?></i> </a>

<button class = "navbar-toggle" data-toggle = "collapse" data-target = ".navHeaderCollapse">
<span class = "icon-bar"> </span>
<span class = "icon-bar"> </span>
<span class = "icon-bar"> </span>
</button>

<div class="collapse navbar-collapse navHeaderCollapse">
<ul class = "nav navbar-nav navbar-right">
<li class ="active"> <a href="retailer_profile.php">Home</a></li>
<li> <a href="#">Profile</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Property <b class ="caret"></b></a>
<ul class="dropdown-menu">
<li> <a href="retailer_property_add.php">Add property</a> </li>
<li> <a href="#">View property</a> </li>
</ul>
</li>
<li> <a href="retailer_logout.php"><id="logout">Log Out</a></li>
</ul>
</div>
</div>
</div>
</div>

<div name="container">


</div>

<script src = "js/jquery-1.11.1.js"> </script>
<script src = "js/bootstrap.js"> </script>

</body>
</html>

retailer_logout 页面

    <?php
session_start();
if(session_destroy()) // Destroying All Sessions
{
header("Location: index.html"); // Redirecting To Home Page
}
?>

retailer_session 页面

<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("abc.com", "abc", "abc");
// Selecting Database
$db = mysql_select_db("abc", $connection);
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$ses_sql=mysql_query("select * from retailerregister where email='$user_check'", $connection);

$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['email'];

if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: index.html'); // Redirecting To Home Page
}
?>

现在我只能使用$login_session 来在个人资料页面上显示电子邮件。谁能告诉我如何通过 session 在 retailer_profile 页面上显示登录用户的其他数据

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com