Due to cross site session management, firstly I sent session id through url. Please note I had a $username variable created. First code is just a snap of a larger code.
ini_set("session.use_cookies",0);
ini_set("session.use_trans_sid",1);
session_start();
$session_id = $username;
header("location: http://somedomain.com/receive.php?session_id=". $session_id );
Now I received it here and creating a new session I have forwarded the session variable in same site:
ini_set("session.use_cookies",0);
ini_set("session.use_trans_sid",1);
session_id($_GET['session_id']);
$some_var=session_id();
session_destroy();
session_start();
$_SESSION["var_name"] = $some_var;
//echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
header("location: anotherfile.php");
When I uncomment the echo line above and comment header line, then I can see the session array successfully. But when I pass it to anotherfile.php I loose the session.
session_start();
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
Any help why I am unable to fetch the session in last file.
change the second file
<?php
ini_set("session.use_cookies",0);
ini_set("session.use_trans_sid",1);
session_id($_GET['session_id']);
$some_var = session_id(); // remove session_destroy code because no session is set before.
session_start();
$_SESSION["var_name"] = $some_var;
header("location: anotherfile.php");
to this it will be fine
<?php
session_id($_GET['session_id']);
$some_var = session_id(); // remove session_destroy code because no session is set before.
session_start();
$_SESSION["var_name"] = $some_var;
header("location: anotherfile.php");