[英]i am trying to redirect a user after a succesful login to another page(homeDemo.php) but it doesnt seem to be redirecting. i am using php
這是我的login.php,只是一個簡單的哈希密碼,可在成功登錄后重定向用戶。
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($db , $_POST['umail']);
$userQuery = "SELECT username, password FROM users WHERE username = '$username'";
$result = mysqli_query($db, $userQuery);
$queryRow = mysqli_fetch_array($result, MYSQLI_ASSOC);
$queryCount = mysqli_num_rows($result);
$verifyPassword = password_verify($_POST['upassword'], $queryRow['password']);
if ($verifyPassword){
$_SESSION['username'] = $username;
header("Location:homeDemo.php");
}else{
echo "Username Or Password is invalid";
}
mysqli_close($db);
}
這是用戶重定向到的頁面
if (isset($_POST['sendList'])) {
/* $itemName = $_POST['itemName'];
$itemQuantity = $_POST['itemQuantity'];
print_r($itemName);
print_r($itemQuantity);*/
print_r($_SESSION['username']);
$itemList = $_POST['itemList'];
print_r($itemList);
/* foreach($itemName as $key => $iName ){
print_r($iName);
echo " ";
}
foreach($itemQuantity as $key=> $iQuantity){
print_r($iQuantity);
echo " ";
}*/
}
<div class="container">
<form class="col s12" action="" method="POST">
<div class="center-align">
<button type="button" name="button" class="waves-effect #ff3d00 deep-orange accent-3 waves-red btn-large addField">Add a new row</button>
</div>
<table>
<thead>
<tr>
<th class="center-align" data-field="name">Item Name</th>
<th class="center-align" data-field="price">Item Quantity</th>
</tr>
</thead>
<tbody class="listWrapper">
<tr>
<td>
<div class="input-field col s6">
<input type="text" class="validate" name="itemList[]">
</div>
</td>
<td>
<div class="input-field col s6">
<input type="text" class="validate" name="itemList[]">
</div>
</td>
</tr>
<tr>
<td>
<div class="input-field col s6">
<input type="text" class="validate" name="itemList[]">
</div>
</td>
<td>
<div class="input-field col s6">
<input type="text" class="validate" name="itemList[]">
</div>
</td>
</tr>
</tbody>
</table>
<div class="center-btn">
<div class="input-field col s12">
<select class="" name="shopCenters" multiple>
<option value="" disabled select>Select Your Preferred Shopping Center</option>
<option value="Shoprite">Shoprite Accra Mall</option>
<option value="MaxMart">MaxMart Osu</option>
<option value="Marina">Marina Mall</option>
<label for="">Shopping Center</label>
</select>
</div>
<input type="submit" class="btn #ff3d00 deep-orange accent-3 center-align" name="sendList" value="SEND">
</div>
</form>
和我的身份驗證文件,以防止用戶未登錄就訪問homeDemo.php文件
<?php
if(!isset($_SESSION['username']))
{
session_start();
header('location:Login.php');
exit;
}
?>
確保session_start()
在$_SESSION['username']
否則$_SESSION['username']
將沒有值。
您沒有提及,但我敢打賭,您會再次重定向到登錄頁面。
<?php
session_start();
if(!isset($_SESSION['username']))
{
header('location:Login.php');
exit;
}
?>
使用會話數據之前,請確保調用session_start()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.