dpp34603 2016-12-05 01: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

<?php
session_start();
$_SESSION['roles'] = $_POST['ext_roles'];
var_dump($_SESSION);

session.php

<?php
session_start();
var_dump($_SESSION);

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

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

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

/var/www/default/session.php:3:
array (size=1)
  '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

<html>
<body>
<form action="index.php" method="post">
    <input type="hidden" name="oauth_consumer_key" value="00000000000000000"/>
    <input type="hidden" name="oauth_signature_method" value="00000000000000000"/>
    <input type="hidden" name="oauth_timestamp" value="00000000000000000"/>
    <input type="hidden" name="oauth_nonce" value="00000000000000000"/>
    <input type="hidden" name="oauth_version" value="00000000000000000"/>
    <input type="hidden" name="context_id" value="00000000000000000"/>
    <input type="hidden" name="context_label" value="00000000000000000"/>
    <input type="hidden" name="context_title" value="00000000000000000"/>
    <input type="hidden" name="custom_canvas_api_domain" value="00000000000000000"/>
    <input type="hidden" name="custom_canvas_assignment_id" value="00000000000000000"/>
    <input type="hidden" name="custom_canvas_assignment_points_possible" value="00000000000000000"/>
    <input type="hidden" name="custom_canvas_assignment_title" value="00000000000000000"/>
    <input type="hidden" name="custom_canvas_course_id" value="00000000000000000"/>
    <input type="hidden" name="custom_canvas_enrollment_state" value="00000000000000000"/>
    <input type="hidden" name="custom_canvas_user_id" value="00000000000000000"/>
    <input type="hidden" name="custom_canvas_user_login_id" value="00000000000000000"/>
    <input type="hidden" name="ext_ims_lis_basic_outcome_url"
           value="00000000000000000"/>
    <input type="hidden" name="ext_outcome_data_values_accepted" value="00000000000000000"/>
    <input type="hidden" name="ext_outcome_result_total_score_accepted" value="00000000000000000"/>
    <input type="hidden" name="ext_outcomes_tool_placement_url"
           value="00000000000000000"/>
    <input type="hidden" name="ext_roles"
           value="00000000000000000"/>
    <input type="hidden" name="launch_presentation_document_target" value="00000000000000000"/>
    <input type="hidden" name="launch_presentation_locale" value="00000000000000000"/>
    <input type="hidden" name="launch_presentation_return_url"
           value="00000000000000000"/>
    <input type="hidden" name="lis_course_offering_sourcedid" value="00000000000000000"/>
    <input type="hidden" name="lis_outcome_service_url"
           value="00000000000000000"/>
    <input type="hidden" name="lis_person_contact_email_primary" value="00000000000000000"/>
    <input type="hidden" name="lis_person_name_family" value="00000000000000000"/>
    <input type="hidden" name="lis_person_name_full" value="00000000000000000"/>
    <input type="hidden" name="lis_person_name_given" value="00000000000000000"/>
    <input type="hidden" name="lis_person_sourcedid" value="00000000000000000"/>
    <input type="hidden" name="lti_message_type" value="00000000000000000"/>
    <input type="hidden" name="lti_version" value="00000000000000000"/>
    <input type="hidden" name="oauth_callback" value="00000000000000000"/>
    <input type="hidden" name="resource_link_id" value="00000000000000000"/>
    <input type="hidden" name="resource_link_title" value="00000000000000000"/>
    <input type="hidden" name="roles" value="00000000000000000"/>
    <input type="hidden" name="tool_consumer_info_product_family_code" value="00000000000000000"/>
    <input type="hidden" name="tool_consumer_info_version" value="00000000000000000"/>
    <input type="hidden" name="tool_consumer_instance_contact_email" value="00000000000000000"/>
    <input type="hidden" name="tool_consumer_instance_guid"
           value="00000000000000000"/>
    <input type="hidden" name="tool_consumer_instance_name" value="00000000000000000"/>
    <input type="hidden" name="user_id" value="00000000000000000"/>
    <input type="hidden" name="user_image"
           value="00000000000000000"/>
    <input type="hidden" name="oauth_signature" value="00000000000000000"/>
    <button type="submit" name="submitButton">Go</button>
</form>    
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dpo60833 2016-12-05 01: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.

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

报告相同问题?

悬赏问题

  • ¥50 ZYNQ7020双核FLAHS烧写的问题
  • ¥20 ue 5 中想要实现第一人称人物左右行走摆动的效果,摄像头只向右摆动一次(关键词-结点)
  • ¥15 钢岔管添加弹性约束模拟围岩作用
  • ¥15 AD9164瞬时带宽1.8G,怎么计算出来?
  • ¥20 为什么安装CSiBridge时出现了这个问题,尝试了很多方法都不行,求详细操作步骤?
  • ¥15 鼠标右键,撤销删除 复制 移动,要怎样删除
  • ¥15 使用MATLAB进行余弦相似度计算加速
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题