gpt4 book ai didi

php - "You must be logged in to access this page"错误

转载 作者:行者123 更新时间:2023-12-04 05:44:01 25 4
gpt4 key购买 nike

我有我的 login.php设置为每当登录成功时,它会自动定向到 profile.php .但是,即使登录成功,每次去profile.php它仍然显示“您必须登录才能访问此页面”。为什么?

这是我的 login.php :

$email = $_POST['email-field'];
$password = $_POST['password-field'];

if ($email && $password)
{
$connect = mysql_connect("xx", "xx", "xx") or die("Couldnt connect!");
mysql_select_db(xx) or die("Couldnt find db");

$query = mysql_query("SELECT * FROM users WHERE email = '$email'");

$numrows = mysql_num_rows($query);

if ($numrows != 0)
{

while ($row = mysql_fetch_assoc($query))
{
$email = $row['email'];
$md5password = $row['password'];
}

if ($email == $email && $md5password == md5($password))
{
header("Location: profile.php");
$_SESSION['email']==$email;
}
else
echo "Incorrect password";
}
else
die("That user doessnt exist!");
}
else
die("Please enter a username and a password");

还有我的 profile.php :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php

include('get-info.php');

session_start();

if ($_SESSION['email'])
echo "<a href=logout.php>Logout</a>";
else
die("You must be logged in to access this page");


?>


<html>

<head>

<title>

R-A | Profile

</title>

<link href='css.css' rel='stylesheet' type='text/css' />

</head>

<body class='body3' >

<div class='logo-bar'>

<div class='menu'>

<img src='images/rateaway.png' class='logo-bar-img' />

<div class='menu-options'>

<a href='index.php' class='menu-links' >Home</a>

<a href='profile.php' class='menu-links' >Profile</a>

<a href='profile.php' class='menu-links' >Friends</a>

</div>

</div>

</div>

<div class='profile-main-content' >

<div class='profile-current-info'>

<p class='profile-name'> <?php get_info('iran_mateu@yahoo.com', 'name'); ?> </p>

<img src='<?php get_info('iran_mateu@yahoo.com', 'profilepic'); ?>' class='profile-pic'/>

<p class='profile-dob' > Born: <?php get_info('iran_mateu@yahoo.com', 'dob'); ?> </p>

<p class='profile-country' > Currently lives in: <?php get_info('iran_mateu@yahoo.com', 'country'); ?> </p>

<p class='profile-gender' > Gender: <?php get_info('iran_mateu@yahoo.com', 'gender'); ?> </p>

</div>

<div class='profile-edit-info' >



</div>

</div>

</body>

最佳答案

成功登录后,您不会写入 session 。考虑这部分:

if ($email==$email&&$md5password==md5($password))
{
header("Location: profile.php");
$_SESSION['email']==$email;
}

您应该使用 =而不是 == .既然你不是,你就是 不是 分配 $email$_SESSION['email'] .您没有分配任何内容,只是进行比较(并丢弃其返回值)。所以应该是:
$_SESSION['email'] = $email;

另外,您应该添加 session_start();到 login.php 的顶部,正如 minitech 在他的回答中所建议的那样。

关于php - "You must be logged in to access this page"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10924486/

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