session - Strange $_SESSION var behivor in PHP -


i've been struggling 2 days now. code below works perfect on localhost (wampserver version 2.5, apache v2.4.9, php 5.5.12) not on host server. trying pass $_session 1 page (both files under same folder.) during sign new user.

page 1:(stepone.php) 

assign $_session['userid']:

<?php session_start(); include_once (dirname(__file__) .'/classes/data.php');  $_session['userid'] = $user->id; /*user->id set.*/ ?> 

page 2:(steps.php)

<?php session_start(); include_once (dirname(__file__) .'/classes/data.php'); $data = new data(); error_log("session @ start=".print_r($_session,true)); ?> 

result is:

[14-jul-2015 23:31:40 america/denver] session @ start=array ( ) 

already checked: 1.session_start() on each page`.

2.sessions are enabled.

3.session.save_handler = files on php.ini  4.session.save_path = "/tmp" - i've created "tmp" folder 

i can't find session file under "tmp" folder. appreciate suggestions , answers

update 15/7/15 - solved after checking host server figure out couple of things:

  • there .htaccess apparently pointed different php.ini 1 wanted
  • in .htaccess there rule redirect pages causing $_session reset.

so, i've learnt this:

  1. always check if pointing right php.ini
  2. search .htaccess around of folders - there might old 1 messing around configurations.

solved after checking host server figure out couple of things:

  1. there .htaccess apparently pointed different php.ini 1 wanted
  2. in .htaccess there rule redirect pages causing $_session reset.

so, i've learnt this:

  • always check if pointing right php.ini
  • search .htaccess around of folders - there might old 1 messing around configurations.

additional suggestions i've picked through search of solution:

when using ajax try add

session_set_cookie_params(0, '/', '.yourwebsite.com')

; before session_start()


Comments