使用header()从页面到页面传递变量;
问题描述:
Im使用以下代码来验证(很差,我知道)表单的$_POST[]
ed数据。如何将$auth
传递到新页面,以便我可以为用户打印? (short of using my-account.php?auth=You Must......)
使用header()从页面到页面传递变量;
if (!$_POST['supportarea'] || !$_POST['supportbody']) {
$auth = 'You must provide some information if we are ever to help you with your support ticket';
header('Location: ../pages/my-account.php');
}
谢谢。亚历克斯。
答
您应该使用会话。在你的脚本:
session_start();
$_SESSION['flash'] = 'You must ...';
在我-account.php脚本:
session_start();
if (!empty($_SESSION['flash'])) {
$flash_message = htmlspecialchars($_SESSION['flash']);
unset($_SESSION['flash']);
} else {
$flash_message = null;
}
然后,如果!empty($flash_message)
,它显示给用户。
不要使用(!$ _ POST ['foo']),因为它会产生PHP错误。使用(!isset($ _ POST ['foo']))。 – FoneyOp 2011-05-24 16:55:16