Php session variable value is null when hosted on server

I had a strange problem in sessions. This works on a WAMP server on my local machine. My problem is that it is not working on a server in the USA.

im doing the following:

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

on another page I'm doing:

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

but I only get my session value:

my session value is not set.

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

Help. thanks in advance.

+4
source share
4 answers

Perhaps your script is dying because session_start fails with "already sent headers"? This can happen, for example, if your test computer and production server do not encode newlines in the same way ...

Errors probably don't appear on your production server, try something like this:

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

and see if you get something useful.

+2
source

Check permissions on session.save_path . This location must be writable by the Apache / httpd user.

Also check to see if there are any sess_ prefix files in session.save_path .

0
source

thanks for the help.

my problem was security permission in the / tmp folder. as soon as he corrected his work.

The average time does not use only numeric values โ€‹โ€‹for SESSION identifiers (for example, $ _SESSION ['12345']), since in linux hosting it does not accept a numeric index and skips it. (so use $ _SESSION ['ACS12345']) ..

0
source

The opening php tag must be written on the first line of the php file. This method helps me solve this problem.

0
source

All Articles