简体   繁体   English

回应PHP会话

[英]Echo a PHP Session

I have a form that is supposed to store some of its data into a session. 我有一个表单,应该将其某些数据存储到会话中。 For the purpose of this example. 就本示例而言。

This information is then collected on another page. 然后在另一页上收集此信息。

<?php
session_start();
print_r($_SESSION['booking-form']);   ########### for debugging purposes  ###########

if ($_SESSION['booking-form']) {

    echo $_POST['GT_title'] 

    ?>
    <!DOCTYPE html>
    <html>
    <?php
}
elseif ($_SESSION['booking-form']) {
}?>
</html>

Now although the debug is working the echo is not working ie. 现在,尽管调试有效,但回声无效。 echo S_POST['GT_title']. 回声S_POST ['GT_title']。

  1. How do I echo the information on the second page. 如何回显第二页上的信息。
  2. Can I echo it wherever I want it in the html (ie. in the middle of the body somewhere with 我可以在html中的任何地方回声它吗(即,在身体中间某处
  3. On the first page some data in the form can be changed with options. 在首页上,可以使用选项更改表格中的某些数据。 This would need to update the session before the page is changed. 这将需要在更改页面之前更新会话。

CLARIFICATION 澄清

For the purpose of a booking form. 用于预订表格。 The user filled in a series of options that were then echo'd on the next page. 用户填写了一系列选项,然后在下一页回显了这些选项。 At this point they need to log in so the form data must enter into a session. 此时,他们需要登录,因此表单数据必须进入会话。 The session data should then be returned on a third page. 然后应在第三页上返回会话数据。

1) what information? 1)什么信息? $_POST['GT_title'] would refer to a form element, presumably on the previous page. $_POST['GT_title']将引用一个表单元素,大概在上一页。 Does it exist? 它存在吗? Is it filled in? 是否填写? what are you expecting? 你有什么期待?

2) You can echo where ever you like. 2)你可以echo

3) clarify? 3)澄清? you can update a session with post values easily. 您可以轻松更新具有帖子值的会话。

$_SESSION['foo'] = $_POST['bar']

your question isn't really that clear. 你的问题不是那么清楚。

You can echo it wherever you want but if it doesn't exist or doesn't have a value then it might appear to be not working. 您可以在任何需要的地方回显它,但是如果它不存在或没有值,则它似乎无法正常工作。 To know for sure use var_dump($_POST['GT_title']); 要确定要使用var_dump($_POST['GT_title']);

For your echo question: Are you sure that GT_title is set? 对于你的回音问题:你确定GT_title已设置好吗? Posting the form on your previous page might help. 在上一页上发布表单可能会有所帮助。

You can echo wherever you want, you can just put 你可以随心所欲地回音,你可以放

<?=$varname?> 

anywhere in your html. 在你的HTML中的任何地方。

You can also update your session wherever you want. 您还可以随时随地更新会话。

$_SESSION['abc'] = value;
echo '<pre>';
print_r($_POST);
echo '</pre>';

Print it after your header. 在标题后打印。 I hope this helps a little :) 希望这会有帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM