作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有我的 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/
我是一名优秀的程序员,十分优秀!