我试图在php会话中存储大量的POST数据。数据似乎保存没有任何问题,但当我尝试访问下一页加载时的数据时,它是未设置的。我不知道我做错了什么。这是我可以做的最小工作示例:
<?php
session_start();
$_SESSION['roles'] = $_POST['ext_roles'];
var_dump($_SESSION);
<?php
session_start();
var_dump($_SESSION);
当我向index.php
发布POST时,数据会按预期显示:
/var/www/default/index.php:4:
array (size=1)
'roles' => string '00000000000000000' (length=17)
但是当我加载session.php
时,我明白了:
/var/www/default/session.php:3:
array (size=1)
'roles' => null
所有数据都不会发生,只是我真正关心的数据。如果我只是使用邮递员提交随机POST数据,它可以正常工作,但是从我尝试保存的外部源进入初始POST的数据始终设置为null或空数组。我在这里完全失败了。
这是我试图在会话中坚持的表单数据:
<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>
答案 0 :(得分:0)
尝试改变:
$_SESSION['post-data'] = $_POST;
成:
if ($_POST) $_SESSION['post-data'] = $_POST;
否则,任何$ _GET调用都会将post-data设置为空数组。