0

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

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

where $this_session is just a microtime stamp in php; and then on form-page-2.php when handling input data I use this to try and get this info back:

$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); 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

brendosthoughts
  • 1,683
  • 5
  • 21
  • 38

1 Answers1

1

You should call function session_start() on top of all pages where you use session.

When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers. These will either be a built-in save handler provided by default or by PHP extensions (such as SQLite or Memcached); or can be custom handler as defined by 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.

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

Farid Movsumov
  • 12,350
  • 8
  • 71
  • 97