Php 使用header()将变量从一页传递到另一页;

Php 使用header()将变量从一页传递到另一页;,php,Php,我使用下面的代码来验证表单的$\u POST[]ed数据(我知道很糟糕)。如何将$auth传递到新页面,以便为用户打印(不使用my account.php?auth=您必须……) 谢谢。Alex.您应该使用该会话。在脚本中: session_start(); $_SESSION['flash'] = 'You must ...'; 在my-account.php脚本中: session_start(); if (!empty($_SESSION['flash'])) { $flash_

我使用下面的代码来验证表单的
$\u POST[]
ed数据(我知道很糟糕)。如何将
$auth
传递到新页面,以便为用户打印
(不使用my account.php?auth=您必须……)


谢谢。Alex.

您应该使用该会话。在脚本中:

session_start();
$_SESSION['flash'] = 'You must ...';
在my-account.php脚本中:

session_start();
if (!empty($_SESSION['flash'])) {
    $flash_message = htmlspecialchars($_SESSION['flash']);
    unset($_SESSION['flash']);
} else {
    $flash_message = null;
}

然后,如果
!空($flash_message)
,将其显示给用户。

您应该使用该会话。在脚本中:

session_start();
$_SESSION['flash'] = 'You must ...';
在my-account.php脚本中:

session_start();
if (!empty($_SESSION['flash'])) {
    $flash_message = htmlspecialchars($_SESSION['flash']);
    unset($_SESSION['flash']);
} else {
    $flash_message = null;
}
然后,如果
!空($flash\u message)
,将其显示给用户。

不要使用(!$\u POST['foo']),因为它会生成PHP错误。使用(!isset($\u POST['foo'])。不要使用(!$\u POST['foo']),因为它会生成PHP错误。使用(!isset($\u POST['foo'])。