我有一个account.php页面,用户可以在其中更改mySQL数据库中保存的帐户信息。当我点击链接时,我收到一条消息,说“在您访问此页面之前返回并登录!”我的代码如下。
pro.php(页面定向登录后)
<?php
//STEP 1 Connect To Database
$connect = mysql_connect("Localhost","mlec2013_danny","8764963d");
if (!$connect)
{
die("MySQL could not connect!");
}
$DB = mysql_select_db('mlec2013_database');
if(!$DB)
{
die("MySQL could not select Database!");
}
//STEP 2 Declare Variables
$Name = $_POST['username'];
$Pass = $_POST['password'];
$Query = mysql_query("SELECT * FROM Users WHERE Username='$Name' AND Password='$Pass'");
$NumRows = mysql_num_rows($Query);
$_SESSION['username'] = $Name;
$_SESSION['password'] = $Pass;
//STEP 3 Check to See If User Entered All Of The Information
if(empty($_SESSION['username']) || empty($_SESSION['password']))
{
die("Go back and login before you visit this page!");
}
if($Name && $Pass == "")
{
die("Please enter in a name and password!");
}
if($Name == "")
{
die("Please enter your name!" . "</br>");
}
if($Pass == "")
{
die("Please enter a password!");
echo "</br>";
}
//STEP 4 Check Username And Password With The MySQL Database
if($NumRows != 0)
{
while($Row = mysql_fetch_assoc($Query))
{
$Database_Name = $Row['username'];
$Database_Pass = $Row['password'];
}
}
else
{
die("Incorrect Username or Password!");
}
//end of PHP scripting. Information displayed below is in the form of HTML, CSS, or Javascript.
?>
account.php
<?php
session_start()
?>
答案 0 :(得分:1)
也将session_start()
放在pro.php
页面的顶部。