0

i have working on a php project.I am using session variables.

i have made 2 file to test this issue.

In Test1 file i have set value in session.below is the code.

<?php
session_start();
$_SESSION['test']="demo";
?>

In test2 file i have print this session.

<?php
session_start();
echo $_SESSION['test'];
?>

The session value is display blank in test2 file but it display value in test1 file where session is set.which session value is not carry on other page.this is working perfect on localhost but not working on server.is there issue on server? i have attached server session detail image.enter image description here

Naitik Mistry
  • 299
  • 1
  • 2
  • 10

3 Answers3

1

Have you tried to "tell" PHP which session it should track?

For example: if your session id variable is passed in the $_GET['session'];

run the following before executing session_start():

session_id($_GET['session']);

EDIT

try this:

<?php
if( $_GET['SID'] != '' ) session_id($_GET['SID']);
session_start();
$sid = session_id();
print '<script>window.location = window.location + "&SID="' . $sid . '</script>';
?>
Leandro Barreto
  • 361
  • 2
  • 18
  • Leandro Barreto i have print ur code and it displayed the following output. also now the warnings are displayed. output : ebe3blnb4jta25rq3gd3jm2hf4 – Naitik Mistry Nov 29 '12 at 14:31
  • Notice: Undefined index: session in /var/www/vhosts/test.com/httpdocs/test1.php on line 5 Warning: Unknown: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0 – Naitik Mistry Nov 29 '12 at 14:33
  • PHP is telling you the session id is invalid, are you passing the correct session id or is the variable empty? – Leandro Barreto Nov 29 '12 at 14:34
1

Check to see if the session save path is writable by the web server.

Make sure you have cookies turned on.. (I forget when I turn them off to test something)

Use firefox with the firebug extension to see if the cookie is being set and transmitted back.

chipmunk
  • 944
  • 8
  • 19
0

This has happened to me in the past. You have to be sure nothing is being outputted to the browser prior to session_start(). This seems obvious, but sometimes you have leading whitespace characters at the beginning of the file (before your opening <?php tag). Or another possibility is that you're using a text editor / encoding that is outputting some characters before the <?php session_start();

Of course, I'm sure there are other possibilities as well, but this one has happened to me before.

Ryan
  • 144
  • 8