In my local machine and online server, i have a folder 'test' and three files in it (one.php,two.php,three.php) .
<?php
ob_start();
session_start();
$_SESSION['one'] = 1;
header('Location:two.php');
exit();
?>
<?php
ob_start();
session_start();
$_SESSION['two'] = 2;
header('Location:three.php');
exit();
?>
<?php
ob_start();
session_start();
echo '<pre>';print_r($_SESSION);
?>
while i take one.php in browser i getting an output
//Local machine
array[one] =1
array[two] =2
this is correct
// Online Server
array[one] =1
this is not correct
What is wrong with this? i donot getting any warning,
Anyone please tell me, what is the problem?
I got the reason for this issue.
It was related to the session.save_path of php.ini file .
Make sure that the session save path directory is setup in php.ini, exists and is writable.
try calling session_write_close(); before sending the header.
You should always add *session_start();* in the first line of your code. There is a problem in php 5.2.11 that have been fixed with version 5.2.17.
This code does not work:
<?php
session_start();
?>
This code works fine:
<?php session_start();?>
So if you check your php host version and the version is 5.2.11 or previous to that one, that could be the problem!