PHP Session not working

jeremy5357

New Member
Messages
5
Reaction score
0
Points
0
I am having problems with PHP sessions. If anyone can tell me what I'm doing wrong, it will be greatly appreciated.

I could not get PHP sessions to work so I made a very simple test at http://cookies.x10.mx/sesstest.php.

It creates a session and stores a session variable as $_SESSION['test']. It then redirects the user to http://cookies.x10.mx/sessreceive.php where it will try to read the stored session and display to user.

The code to the pages are listed below.

This is all the code of sesstest.php
PHP:
<?php
session_start();
$_SESSION['test']="TEST SESSION TEXT";
header('location:sessreceive.php');
?>

This is all the code of sessreceive.php
PHP:
<?php
echo $_SESSION['test'];
?>

The output is blank.

Could someone tell me what I'm doing wrong?
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
The issue is that you have failed to start the session in the second script named sessreceive.php. Quoted from php.net: "Also note that you must start your session using session_start() before use of $_SESSION becomes available.".

Therefore, try changing the contents of sessrecieve to the following:
Code:
session_start();
echo $_SESSION['test'];
 
Last edited:
Top