简体   繁体   English

PHP会话无法在页面之间传输

[英]php sessions not transferring between pages

Okay so I am not entirely sure why this isn't working but any insight would be helpful . 好的,所以我不能完全确定为什么这不能奏效,但是任何见识都会有所帮助。 I am making a html web form with php as back end and it's spread out over multiple pages, So my paln is to use a php session to helkp sync data for a user with data in databse between pages (not storing all the form data in session) so i Have this code after first section of form has been entered in database 我正在制作一个以php为后端的html网络表单,它分布在多个页面上,所以我的习惯是使用php会话为用户同步数据,页面之间的数据在databse中(不存储所有表单数据在会话),因此我在数据库的第一部分表格输入后有此代码

    session_start();
    $_SESSION["session_id"]=$this_session;
include 'form-page-2.php';

where $this_session is just a microtime stamp in php; 其中$ this_session只是php中的微型时间戳; and then on form-page-2.php when handling input data I use this to try and get this info back: 然后在处理输入数据时在form-page-2.php上,我使用它来尝试获取此信息:

$this_session =  $_SESSION["session_id"]; 

and I get the error Notice: Undefined variable: _SESSION in C:\\wamp\\www\\Karen-forms\\form-page-2.php on line 30 however if i do a vardump($_SESSION); 我收到错误Notice: Undefined variable: _SESSION in C:\\wamp\\www\\Karen-forms\\form-page-2.php on line 30但是如果我执行vardump($_SESSION); on I get the expected value I would expect 我得到了我期望的期望值

  array (size=1)
    'session_id' => string '1390976355.1481' (length=15)`

so How cqan I properly pull out the session_id one form-page-2.php as clearly I am doiing something wrong just unsure as to what any help would be greatly appreciated 所以我如何正确地从一个form-page-2.php中取出session_id,因为我显然在做错事,只是不确定什么帮助会很感激

You should call function session_start() on top of all pages where you use session. 您应该在使用会话的所有页面的顶部调用函数session_start()

When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers. 当调用session_start()或自动启动会话时,PHP将调用打开并读取会话保存处理程序。 These will either be a built-in save handler provided by default or by PHP extensions (such as SQLite or Memcached); 它们要么是默认提供的内置保存处理程序,要么是PHP扩展(例如SQLite或Memcached)提供的; or can be custom handler as defined by session_set_save_handler(). 或者可以是session_set_save_handler()定义的自定义处理程序。 The read callback will retrieve any existing session data (stored in a special serialized format) and will be unserialized and used to automatically populate the $_SESSION superglobal when the read callback returns the saved session data back to PHP session handling. 读回调将检索任何现有的会话数据(以特殊的序列化格式存储),并且将被反序列化,并在读回调将已保存的会话数据返回给PHP会话处理时自动填充$ _SESSION超全局变量。

Source: http://tr2.php.net/manual/en/function.session-start.php 来源: http : //tr2.php.net/manual/en/function.session-start.php

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

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