I can access my SESSIONS from subfolders eg. /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 my SESSIONS
session_regenerate_id(true); $_SESSION['signature'] = $signature;
My PHP.ini
session.save_path = '/home/mysite/cvsessions'
What am I getting wrong?
3 Answers
Answers 1
Clarification: This answer is about using php.ini files in the same folders that contain the PHP files in order to overwrite the system-wide default settings, this answer assumes that you already have a standard default php.ini file whose settings you either can not or should not edit.
I have had similar issues to what you're describing and would hazard a guess that you do not have php.ini
files in each active folder, whereas you may only actually be having ONE php.ini file in your root folder and so any of the subfolders (/students
, etc.) are not using the root php.ini
and simply using the account- or system- default.
Depending on what server system you have set up (for example CPanel install?) then in order to change settings from the default server-wide php.ini
, a new php.ini file containing just the custom settings (such as in your case account specific session storage location) needs to be installed into every directory needing to use non-default php.ini settings.
So, step by step:
Do you have a php.ini in every folder, such as
/
,/teachers
,/students
etc.?Are all these
php.ini
files the same?All folders should be the same, so all should have their own php.ini copy or none of them should. Otherwise this sort of change in behaviour which is causing your inconsistency issues will occur when changing between one (custom) php.ini setting and another (system default) php.ini setting.
If any folder is missing them or prehaps only your public html root folder has the php.ini
file then that means all the other folders are using the default, and so the public html root is looking for sessions in the wrong place -- It's looking in the '/home/mysite/cvsessions'
address whereas the default address for PHP sessions is something like /home/tmp
.
Does this help or is this well off the mark ?
Better way of checking if session is started:
PHP >= 5.4
if (session_status() == PHP_SESSION_NONE) { session_start(); }
For versions of PHP < 5.4.0
if(session_id() == '') { session_start(); }
Answers 2
Hi please go through the code
$lifetime=time()+86400000; session_start(); setcookie(session_name(),session_id(),$lifetime,'/', '.mysite.com');
Answers 3
Sop changing settings and start trying to diagnose the issue.
There is nothing in the information you have supplied to point to a cause. Your first step is to create a simple script like this:
<?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 session_name doesnot change and no errors are reported.
Most likely the error is in your code - something emit body content before the call to session_start() (and hence flushing the headers) or the session save path is being overridden somewhere.
0 comments:
Post a Comment