Strange $ _SESSION var behivor in PHP
I've been struggling with this for 2 days now. the code below works fine on my localhost (WampServer Version 2.5, Apache v2.4.9, PHP 5.5.12)
but not on my host server. I am trying to transfer $_SESSION
from one page to another (both files are in the same folder.) During registration for a new user.
page 1:(stepOne.php)
to appoint $_SESSION['userid']:
<?php
session_start();
include_once (dirname(__FILE__) .'/classes/data.php');
$_SESSION['userID'] = $user->id; /*user->id is set.*/
?>
page 2: (steps .php)
<?php
session_start();
include_once (dirname(__FILE__) .'/classes/data.php');
$data = new data();
error_log("session at start=".print_r($_SESSION,true));
?>
result:
[14-Jul-2015 23:31:40 America/Denver] session at start=Array
(
)
already tested:
1.session_start()
on every page.
2.sessions are
...
3.session.save_handler = files on php.ini
4.session.save_path = "/tmp" - I've created "tmp" folder
I also cannot find the session file in the "tmp" folder. Would be grateful for any suggestions and answers
UPDATE 7/15/15 - SOLVING After checking with my host server, figure out a few things:
- there was a .htaccess that apparently pointed to a different php.ini and then the one I wanted
- there was a rule in that .htaccess that redirects pages by calling $ _SESSION reset.
so what i learned from this:
- Always check if you are pointing to the correct php.ini
- Find .htaccess around ALL of your folders - maybe the old one messing around with configurations.
source to share
Solved After checking with my host server, figure out a few things:
- there was a .htaccess that apparently pointed to a different php.ini then the one I wanted
- there was a rule in this .htaccess that redirects pages calling $ _SESSION - reset.
So what I learned from this:
- Always check if you are pointing to the correct php.ini
- Find .htaccess around ALL of your folders - maybe the old one messing around with configurations.
Additional suggestions I have chosen to find a solution:
When using AJAX try adding
session_set_cookie_params (0, '/', '.yourWebsite.com')
; before session_start ()
source to share