[英]php echo text using session variable, and unset session variable when other session variable is set?
我正在尝试使用会话变量而不是使用jquery执行以下功能。 我的页面invoice.php中有一些文本:
Text A
当用户第一次进入该页面时,我通过使用会话变量在页面上将此文本作为标头回显:
<?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上回显两个新会话:
$_SESSION['message2'] = '<div id="message_box3"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">✖</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");
因此,如您所见,我正在尝试取消设置为“文本A”的会话“ ref”并隐藏此文本,以便在显示会话“ 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
而不是Text A
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.