PHP session variables are not supported

I have an application that works with session variables without problems. I start a session in front of the headers on every page that uses when it was good, then it seems to me that I get an undefined index error when going to a page other than the one that sets the session variables. But only on some browsers . Sometimes sessions are supported, and sometimes not.

Cookies do not seem to be stored for a while. I did checks using different browsers, and sometimes cookies are stored, and sometimes not.

I did an experiment. I used Firefox for use in the application, and I kept track of the tmp folder where the sessions are stored. I cleaned it. Using firefox, I started using the application using all the pages on which the sessions were, and in the end I checked the tmp folder and there was one session file.

The same thing happened with Internet Explorer, and now there are 7 different session files.

I am using PHP 5.3.0 with a WAMP stack. Apache 2.2.11. Session support is included in my phpinfo ().

I call the var dump on the first page and prints the session data. On any subsequent pages, the session variable is empty.

<?php var_dump($_SESSION); ?> array(0){} 

Can someone help me figure out the solution?

UPDATE - PHP INI SESSION settings

 Directive Local Value Master Value session.auto_start Off Off session.bug_compat_42 On On session.bug_compat_warn On On session.cache_expire 180 180 session.cache_limiter nocache nocache session.cookie_domain 82.68.26.169 82.68.26.169 session.cookie_httponly Off Off session.cookie_lifetime 0 0 session.cookie_path / / session.cookie_secure Off Off session.entropy_file no value no value session.entropy_length 0 0 session.gc_divisor 1000 1000 session.gc_maxlifetime 1440 1440 session.gc_probability 1 1 session.hash_bits_per_character 5 5 session.hash_function 0 0 session.name PHPSESSID PHPSESSID session.referer_check no value no value session.save_handler files files session.save_path c:/wamp/tmp c:/wamp/tmp session.serialize_handler php php session.use_cookies On On session.use_only_cookies On On session.use_trans_sid 0 0 

UPDATE - Solution

Since my application used an iframe that was pulling pages from another domain (which I created), the cookies I was trying to set were blocked. Adjust the P3P header and the problem seems to be resolved!

+3
php cookies session-cookies session-variables wamp
source share
5 answers

My suggestion from your previous question is still worth it: please compare the session identifiers.

The solution may be as simple as your browser does not accept session cookies.

You retrieve the session id by calling session_id() . Do it right after session_start() , it should give you a constant value if , the session is the same. Otherwise, a new session is created for each request.

Also check out C:\wamp\tmp . The gazillion files in this directory may indicate fresh sessions for each request.

EDIT . Since we have confirmed new sessions for each request, it's time to find out if session cookies are accepted. Check your browser settings and make sure that the cookie for your domain (I think it is "localhost") with the name PHPSESSID can be found.

+3
source share

Do you call session_start() on every page that accesses session data?

Edit: And you get the same session id every time?
Also, there may be some error or warning that you are missing (for example, already sent headers) due to the settings?

+3
source share

that’s the point in

 while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) { $_SESSION['saveddata'] = $row; } 

it overwrites the value of $_SESSION['saveddata'] at each iteration. maybe you mean something like

  $_SESSION['saveddata'][] = $row; 

makes sense for $atid = $_SESSION['saveddata']['autotaskid'];

+1
source share

View your session settings. You have a complete list:

 <?php phpinfo(); ?> 

Scroll down to the Session table.

In particular, verify that the session.save_path directory exists and is writable.

+1
source share

When a new session identifier is created with each request, this is most likely a problem with your session paths (save_path and cookie_path), and the chances are greater if you host different applications on the same server (shared hosting) and some of these applications also run sessions . This leads to conflicts in your / tmp directory. You can change the configuration of your ini file, but it is best to configure these parameters at runtime.

 session_set_cookie_params(0, "/app", ".domain.com");//set session cookie parameters session_save_path("/home/../public_html/app/sess");//set directory of this app session data session_start();//start session 

I hope this helps everyone who has this problem. #CodeOn

0
source share

All Articles