Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php使用会话变量回显文本,并在设置其他会话变量时取消设置会话变量?_Php_Session_Session Variables - Fatal编程技术网

php使用会话变量回显文本,并在设置其他会话变量时取消设置会话变量?

php使用会话变量回显文本,并在设置其他会话变量时取消设置会话变量?,php,session,session-variables,Php,Session,Session Variables,我尝试使用session变量而不是jquery来执行以下函数。 我的页面invoice.php上有一些文本: Text A $_SESSION['message2'] = '<div id="message_box3"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">&#10006;</div

我尝试使用session变量而不是jquery来执行以下函数。 我的页面invoice.php上有一些文本:

Text A
    $_SESSION['message2'] = '<div id="message_box3"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">&#10006;</div><h23>Thank You!</h23><p>You have successfully submitted your invoice.</p> </div>';

    $_SESSION['ref2'] = '<div class="inv_ref"><h23>REF: 12345678</h23></div>';
    unset($_SESSION['ref']);

header("location:../invoice.php"); 
当用户第一次进入该页面时,我使用会话变量将此文本作为标题在我的页面上进行回音,如下所示:

<?php $_SESSION['ref'] = '<div class="inv_ref"><h23>Text A</h23></div>'; ?>
<?php if (isset($_SESSION['ref'])) {
echo $_SESSION['ref'];
unset($_SESSION['ref']); } ?>

但是,一旦用户在该页面上提交以下表单:

<form action="include/process_invoice.php" method="post" enctype="multipart/form-data">
<input type="text" id="partNumber" placeholder="e.g. PO012345" class="login_form" />  
<input type="submit" value="Upload Invoice" name="submit" class="file">
</form>

然后在我的页面“process_invoice.php”上处理表单,完成后,我将两个新会话回送到我的页面invoice.php上:

Text A
    $_SESSION['message2'] = '<div id="message_box3"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">&#10006;</div><h23>Thank You!</h23><p>You have successfully submitted your invoice.</p> </div>';

    $_SESSION['ref2'] = '<div class="inv_ref"><h23>REF: 12345678</h23></div>';
    unset($_SESSION['ref']);

header("location:../invoice.php"); 
$\u会话['message2']='✖;谢谢大家! 您已成功提交发票。

; $_SESSION['ref2']='REF:12345678'; 取消设置($_会话['ref']); 标题(“位置:../invoice.php”);
如您所见,我正在尝试取消设置会话“ref”,这是我的“文本A”,并隐藏此文本,以便在会话“ref2”可见时它不可见


这可能吗?如果可能的话,有人能告诉我哪里出了问题吗?谢谢

在您的invoice.php中,替换此:

<?php if (isset($_SESSION['ref'])) {
 echo $_SESSION['ref'];
 unset($_SESSION['ref']); } ?>

为此:

<?php if (isset($_SESSION['ref2'])) {
echo $_SESSION['ref2'];
} else {
echo $_SESSION['ref'];
} ?>


重新加载invoice.php时,您将看到
REF:12345678
而不是
文本A

您能在取消设置后退出以查看它是否会回显吗?并尝试在取消设置之前退出。我想你的重定向有问题。你似乎真的很难使用
$\u会话。为什么像第一个示例中一样,只想在输出后立即将其取消设置而将其存储在会话中?我建议删除消息传递和HTML等会话外存储,只需使用一个变量,如
$\u session['invoice\u status']
,您可以更改该变量的值,以表示您在流程中的位置(即,使用“submitted”、“processed”等值)。您只需根据需要更改状态,并根据该状态有条件地发送消息。“我正在尝试使用会话变量而不是使用jquery来执行以下功能。”-从逻辑角度看,这实际上没有多大意义,就像说“我正在尝试使用直升机而不是鱼竿来绘制此围栏”-完全不同的事物以完全不同的方式使用。你说“可见”是什么意思?如果您只想清除var,那么您的代码已经完成了。但是,如果您试图删除页面上已打印的某些内容,则取消设置var将不会执行此操作。一旦打印出来,PHP将不会在没有JavaScript帮助或重新加载页面的情况下对其进行更改。@LuisSimioni这就是我要做的,我希望能够在用户登陆页面并提交表单后立即使用会话变量回显一些文本,这些文本将被重定向回页面,并且文本已从会话“ref”中存储的文本更改为会话“ref2”中存储的文本。我想这样做,因为如果用户禁用了javascript,该函数仍然可以工作