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>