[英]Submitting a Form in an included page does not refresh the page
我有一個PHP頁面: index.php
在此頁面內,我包括另一個充當側邊欄的PHP頁面。
在此邊欄中,有一個登錄表單。
sidebar.php頁面首先檢查會話,如果有會話,則不會顯示該表單,如果沒有會話,則將顯示該表單,以便訪客可以登錄。
session_start();
$guest = true;
if(!isset($_SESSION["id"])){
//This is a Guest
$guest = true;
} else {
//This is not a Guest
$guest = false;
}
//Then there's the PHP codes that handles form submitting
if(isset($_POST["submit"])){
//In the end, if everything is valid
$_SESSION["id"] = $userID;
}
通常,頁面會在提交表單后刷新,在這種情況下,我希望包含的文件刷新,而在重新加載后,我希望登錄表單消失,因為$_SESSION["id"]
現在已設置,但是沒有。
如果刷新頁面(F5),則表單消失了,並且可以使用,但是在我提交表單之后,它無法直接使用,因此我嘗試添加。
header("Location: http://localhost/index.php");
但是,它不起作用。
請在會話檢查之前調用提交操作,
session_start();
$guest = true;
if(isset($_POST["submit"])){
$_SESSION["id"] = $userID;
}
if(!isset($_SESSION["id"])){
//This is a Guest
$guest = true;
} else {
//This is not a Guest
$guest = false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.