[英]PHP header url redirect
我已在互聯網之間進行搜索,但無法找到解決我問題的方法。 這是我的問題,我有一個發布腳本,可以在數據庫中輸入用戶的發布和用戶ID。 我要做的是在網站發布后從網站上的其他頁面重定向到用戶所在的頁面。 而且所有操作都將在用戶登錄網站后進行,因此這不是重定向到登錄頁面的方法,而是返回到提交帖子后用戶所在的頁面的方法。 問題是,即使我從homepage.php發布,它也會進入profile_test2.php。
這是表格中的代碼:
<form name="form" id="form" method="POST" action="add_post.php?bev=1">
<input type="text" name="textbox" id="textbox" spellcheck="true">
<input type="submit" value="submit">
</form>
這是php腳本中的代碼:
// Get the page the user posted from
$page = $_GET['bev'];
//Redirect this user to the page that displays user information
if ($_GET['bev'] == '1') {
$url = 'homepage.php';
} else if ($_GET['bev'] == '2') {
$url = 'profile_test2.php';
} else {
$url = 'profile_test2.php';
}
header('Location: '. $url);
exit();
先感謝您!
不能使用帶有$_GET
網址的表單action
。 不過,您可以使用<input type='hidden' name='bev' value='1' />
。 由於您的方法是$_POST
我將使用$_POST['bev']
。
+1表示Pekka在表單中使用不可見元素而不是讓GET變量通過POST表單進行評論。
<input type="hidden" name="bev" value="1">
如果頁面始終重定向到profile_test2.php,則最有可能是GET函數無法正常工作,並且它始終處於php腳本中的ELSE
條件下。 您可能想echo the $url
只是要仔細檢查一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.