dpp34603 2016-12-04 17:33
浏览 48
已采纳

会话变量未设置

I'm trying to store a lot of POST data in a php session. The data appears to be saved without any problem, but when I try to access the data on the next page load, it is unset. I have no idea what I'm doing wrong. This is the minimum working example that I can make:

index.php

  1. <?php
  2. session_start();
  3. $_SESSION['roles'] = $_POST['ext_roles'];
  4. var_dump($_SESSION);

session.php

  1. <?php
  2. session_start();
  3. var_dump($_SESSION);

When I make a POST to index.php, the data is shown as expected:

  1. /var/www/default/index.php:4:
  2. array (size=1)
  3. 'roles' => string '00000000000000000' (length=17)

but when I load session.php, I get this:

  1. /var/www/default/session.php:3:
  2. array (size=1)
  3. 'roles' => null

It doesn't happen with all data either, just the data that I actually care about. If I just use postman to submit random POST data, it works just as expected, but the data that comes into the initial POST from the external source that I'm trying to save is consistently set to null or an empty array. I am at a complete loss here.

here is the form data that I'm trying to persist with the session:

form.html

  1. <html>
  2. <body>
  3. <form action="index.php" method="post">
  4. <input type="hidden" name="oauth_consumer_key" value="00000000000000000"/>
  5. <input type="hidden" name="oauth_signature_method" value="00000000000000000"/>
  6. <input type="hidden" name="oauth_timestamp" value="00000000000000000"/>
  7. <input type="hidden" name="oauth_nonce" value="00000000000000000"/>
  8. <input type="hidden" name="oauth_version" value="00000000000000000"/>
  9. <input type="hidden" name="context_id" value="00000000000000000"/>
  10. <input type="hidden" name="context_label" value="00000000000000000"/>
  11. <input type="hidden" name="context_title" value="00000000000000000"/>
  12. <input type="hidden" name="custom_canvas_api_domain" value="00000000000000000"/>
  13. <input type="hidden" name="custom_canvas_assignment_id" value="00000000000000000"/>
  14. <input type="hidden" name="custom_canvas_assignment_points_possible" value="00000000000000000"/>
  15. <input type="hidden" name="custom_canvas_assignment_title" value="00000000000000000"/>
  16. <input type="hidden" name="custom_canvas_course_id" value="00000000000000000"/>
  17. <input type="hidden" name="custom_canvas_enrollment_state" value="00000000000000000"/>
  18. <input type="hidden" name="custom_canvas_user_id" value="00000000000000000"/>
  19. <input type="hidden" name="custom_canvas_user_login_id" value="00000000000000000"/>
  20. <input type="hidden" name="ext_ims_lis_basic_outcome_url"
  21. value="00000000000000000"/>
  22. <input type="hidden" name="ext_outcome_data_values_accepted" value="00000000000000000"/>
  23. <input type="hidden" name="ext_outcome_result_total_score_accepted" value="00000000000000000"/>
  24. <input type="hidden" name="ext_outcomes_tool_placement_url"
  25. value="00000000000000000"/>
  26. <input type="hidden" name="ext_roles"
  27. value="00000000000000000"/>
  28. <input type="hidden" name="launch_presentation_document_target" value="00000000000000000"/>
  29. <input type="hidden" name="launch_presentation_locale" value="00000000000000000"/>
  30. <input type="hidden" name="launch_presentation_return_url"
  31. value="00000000000000000"/>
  32. <input type="hidden" name="lis_course_offering_sourcedid" value="00000000000000000"/>
  33. <input type="hidden" name="lis_outcome_service_url"
  34. value="00000000000000000"/>
  35. <input type="hidden" name="lis_person_contact_email_primary" value="00000000000000000"/>
  36. <input type="hidden" name="lis_person_name_family" value="00000000000000000"/>
  37. <input type="hidden" name="lis_person_name_full" value="00000000000000000"/>
  38. <input type="hidden" name="lis_person_name_given" value="00000000000000000"/>
  39. <input type="hidden" name="lis_person_sourcedid" value="00000000000000000"/>
  40. <input type="hidden" name="lti_message_type" value="00000000000000000"/>
  41. <input type="hidden" name="lti_version" value="00000000000000000"/>
  42. <input type="hidden" name="oauth_callback" value="00000000000000000"/>
  43. <input type="hidden" name="resource_link_id" value="00000000000000000"/>
  44. <input type="hidden" name="resource_link_title" value="00000000000000000"/>
  45. <input type="hidden" name="roles" value="00000000000000000"/>
  46. <input type="hidden" name="tool_consumer_info_product_family_code" value="00000000000000000"/>
  47. <input type="hidden" name="tool_consumer_info_version" value="00000000000000000"/>
  48. <input type="hidden" name="tool_consumer_instance_contact_email" value="00000000000000000"/>
  49. <input type="hidden" name="tool_consumer_instance_guid"
  50. value="00000000000000000"/>
  51. <input type="hidden" name="tool_consumer_instance_name" value="00000000000000000"/>
  52. <input type="hidden" name="user_id" value="00000000000000000"/>
  53. <input type="hidden" name="user_image"
  54. value="00000000000000000"/>
  55. <input type="hidden" name="oauth_signature" value="00000000000000000"/>
  56. <button type="submit" name="submitButton">Go</button>
  57. </form>
  58. </body>
  59. </html>

展开全部

  • 写回答

1条回答 默认 最新

  • dpo60833 2016-12-04 17:53
    关注

    Try to change:

    $_SESSION['post-data'] = $_POST;
    

    into:

    if ($_POST) $_SESSION['post-data'] = $_POST;
    

    Otherwise, post-data will get set to empty array with any $_GET call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 ceph的对象、块、文件相关问题求解答
  • ¥50 如果使用python进行ERA5 10米风场预报检验
  • ¥15 navicat解析mysql密码
  • ¥15 SDAPI(关键词-table)
  • ¥15 unity安卓打包出现问题
  • ¥15 爱快路由器端口更改错误导致无法访问
  • ¥20 安装catkin时遇到了如下问题请问该如何解决呢
  • ¥15 VAE模型如何输出结果
  • ¥15 编译python程序为pyd文件报错:{"source code string cannot contain null bytes"
  • ¥20 关于#r语言#的问题:广义加行模型拟合曲线后如何求拐点
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部