繁体   English   中英

PHP标头网址重定向

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM