phpsessionsession-variablesshared-hosting

php session variable value is null when hosted to server


i having a strange issue in sessions.. this is working in WAMP server in my local machine.. my problem is wen hosted to a server in US it's not working..

im doing like this:

session_start();
$_SESSION['test'] = 'testing login..';

in another page i'm doing:

session_start();
echo('my session value is : '.$_SESSION['test']);

but i'm getting only my session value is :

my session value is not setting..

i checked the session.save_path in cPanel of the server it says /tmp.

pls help.. thanks in advance.


Solution

  • Maybe your script dies because session_start fails with "headers already sent" ? This could happen, for example, if your test machine and production server don't encode new lines the same way...

    The errors are probably not displayed on your production server, try something like that :

    ini_set('display_errors', 1);
    session_start();
    

    and see if you get something useful.