我有一个真正的问题,那就是语法问题。通常,当我需要重定向任何页面时,我只是使用头函数。有时我会在需要的时候使用变量,如下所示:
if(condition) header("Location: home.php?wrong=1");
有时可能是:
if(condition) header("Location: home.php?wrong=1&&success=2");
直接使用变量没有问题(错误或成功)。当我需要通过post方法重定向html表单中的值时,我使用以下代码,它可以工作:
if (condition) header("Location: home.php?id=".$_POST['topic_id']);
但是我需要更多,我还需要传递另一个值。所以我使用:
if (condition) header("Location: home.php?id=".$_POST['topic_id']&&wrong=1);
这一次我变成了一个哑巴。有没有人可以通过提供正确的语法来帮助我?我只需要传递WRONG=1部分。
发布于 2012-12-19 05:17:21
您需要:
if (condition) header("Location: home.php?id=" . $_POST['topic_id'] . "&wrong=1");
或
if (condition) header("Location: home.php?id={$_POST['topic_id']}&wrong=1");
发布于 2012-12-19 05:23:33
有时候它可能是
if (condition) {
$_SESSION['error']['topicId'] = $_POST['topic_id'];
$_SESSION['error']['otherData'] = array('sadfasdfasdfasd' => 'adsfasdf');
header("Location: home.php?wrong=1");
exit;
}
然后:
//home.php
if (!empty($_SESSION['error'])) {
$topicId = $_SESSION['error']['topicId'];
//... do someth ...
}
发布于 2012-12-19 05:25:54
如果PHP头函数有任何问题,请记住,您可以在脚本HTML输出中打印出刷新元标记。
<meta http-equiv="refresh" content="0;url=http://yoursite.com/thepath/you/want/file.php?parames=anything">
这是一个关于元刷新标签的资源:
http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm
https://stackoverflow.com/questions/13941642
复制相似问题