我面臨我的登錄系統的問題。 主頁(index2.php)無法從登錄頁面(index.php)重定向。雖然我輸入了正確的ID和密碼,但當點擊「登錄」按鈕時,登錄頁面不會重定向到主頁。PHP - 無法從登錄頁面重定向到主頁
這裏是我的代碼:
的index.php
<?php
session_start();
?>
<form action="checklogin.php" method="POST">
<div align="center">
<table style="background-color:#9FF781" width="285" border="1">
<tr>
<td width="130"><div align="right"><strong>ID :</strong></div></td>
<td width="159"><label for="admid"></label>
<input type="text" name="admid" id="admid"></td>
</tr>
<tr>
<td><div align="right"><strong>PASSWORD :</strong></div></td>
<td><label for="admpwd"></label>
<input type="password" name="admpwd" id="admpwd"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<button type="submit" name="login">Login</button>
</div></td>
</tr>
</table>
</div>
</form>
checklogin.php
<?php
include('../../../Connections/fyp.php');
session_start();
$admid = $_POST["admid"];
$admpwd = $_POST["admpwd"];
$result = mysql_query("SELECT * FROM acc_login WHERE id = '$admid' AND pwd = '$admpwd'");
$row = mysql_num_rows($result);
if($admid != "" && $admpwd != "")
{
if ($row != "")
{
$_SESSION['loggedin'] = $admid;
header("Location: index2.php");
}
else
{
echo "<script type='text/javascript'>alert('Invalid ID or Password! Please try again!')</script>";
exit('<a href="index.php"><strong>Go Back</strong></a> to Login Page');
}
}
else
{
echo "<script type='text/javascript'>alert('ID or Password field cannot be blank! Please try again!')</script>";
exit('<a href="index.php"><strong>Go Back</strong></a> to Login Page');
}
?>
index2.php
<?php
include("session.php"); //check whether user was logged in.
?>
session.php文件
<?php
include('../../../Connections/fyp.php');
session_start();
$verify = $_SESSION['loggedin'];
$session = mysql_query("SELECT * FROM acc_login WHERE id = '$verify'");
$row = mysql_fetch_array($session);
$login_session = $row['id'];
if(!isset($login_session))
{
header("Location: index.php");
}
?>
嘗試給完整路徑例如。 http://abcd.com/login.php – amoeba
謝謝..如果是本地網絡,我只需將路徑名更改爲「localhost/smth/smth/index.php」? –
這是來自session.php的所有代碼嗎? PHP部分之後的任何其他輸出? –