PHP SESSION is only available in subfolders

I can access my SESSIONS from subfolders, e.g. / teachers / students on my website, but not from files directly under /.

My setup:

Above my pages:

session_set_cookie_params(time()+86400000, '/', '.mysite.com', 0, 1); ini_set('session.use_only_cookies', 1); if(!isset($_SESSION)) { session_start(); } 

How I set up my SESSIONS

 session_regenerate_id(true); $_SESSION['signature'] = $signature; 

My php.ini

 session.save_path = '/home/mysite/cvsessions' 

How am I wrong?

+6
source share
3 answers

Explanation . This answer concerns the use of php.ini files in the same folders that contain PHP files to overwrite system-wide default settings, this answer assumes that you already have a standard default php.ini file, settings of which you either cannot, or do not have to edit.

I had similar problems with what you are describing and it may hinder to assume that you do not have php.ini files in each active folder, whereas in reality there can only be ONE php. ini is in the root folder, and therefore any of the subfolders ( /students , etc.) does not use the php.ini root and just uses the default account or system.

Depending on which server system you configured (for example, CPanel install?), And then to change the default settings for the php.ini server, a new php.ini file containing only user settings (for example, in your data store for an account of a specific case) it is necessary to install in the directory each one where it is necessary to use the php.ini settings that are different from the default settings.

So, step by step:

  • Do you have php.ini in each folder, for example / , /teachers , /students , etc.?

  • Are all these php.ini files the same?

  • All folders should be the same, so everyone should have their own copy of php.ini or none of them should. Otherwise, such a change in behavior that causes inconsistency problems will occur when one (custom) php.ini parameter changes and the other (default) php.ini parameter.

If any folder doesn’t have them, or perhaps only your public html root folder has the php.ini , then this means that all other folders use the default value, and therefore the public html-root is looking for sessions in the wrong place - - It looks for the address '/home/mysite/cvsessions' , while the default address for PHP sessions is something like /home/tmp .

Does it help or is it good?


The best way to verify session start:

PHP> = 5.4

 if (session_status() == PHP_SESSION_NONE) { session_start(); } 

For PHP versions <5.4.0

 if(session_id() == '') { session_start(); } 

Source: fooobar.com/questions/18813 / ...

+7
source

Hi, please view the code

  $lifetime=time()+86400000; session_start(); setcookie(session_name(),session_id(),$lifetime,'/', '.mysite.com'); 
0
source

Change the settings again and start trying to diagnose the problem.

The information you provide is nothing to indicate a reason. Your first step is to create a simple script as follows:

 <?php error_reporting(E_ALL); session_start(); $_SESSION['visits'][]=$_SERVER['PHP_SELF']; print "<pre>" . var_export($_SESSION['visits'],true) . "</pre><br />" . session_name() . "\n<br />" . ini_get('session.save_path'); 

Then copy the script to each directory.

Visit the URLs for each deployed instance, checking that the connection_name is not changed and no error messages are reported.

Most likely, the error in your code is that something emits the contents of the body before calling session_start () (and, therefore, flushes the headers), or the path to save the session is redefined somewhere.

0
source

All Articles