I want to load my content dynamically. It contains php with session variables. I suppose that php works great, but the session variables are not accessible. There is everything wrong with my session_id:
index.php:
<?php
$session_name = 'sec_session_id';
$secure = SECURE;
$httponly = true;
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$secure,
$httponly);
session_name($session_name);
session_start();
session_regenerate_id();
?>
<div class="sidebar">
<ul id="nav">
<li><a class="selected" href="#" data-target="page1">Dashboard</a></li>
<li><a href="#" data-target="page2">Pages</a></li>
</ul>
</div>
<?php echo session_id(); Print_r ($_SESSION); ?>
<div class="content" id="main-content">
<?php
include('pages/page1.php');
?>
My Javascript:
<script>
$(document).ready(function(){
// Set trigger and container variables
var trigger = $('#nav li a'),
container = $('#main-content');
// Fire on click
trigger.on('click', function(){
// Set $this for re-use. Set target from data attribute
var $this = $(this),
target = $this.data('target');
if (!$this.hasClass("selected")) {
$("#nav li a").removeClass("selected");
$this.addClass("selected");
}
else {
event.preventDefault();
}
// Load target page into container
container.load('pages/' + target + '.php');
// Stop normal link behavior
return false;
});
});
</script>
And my loading content php file:
<?php
session_start();
echo session_id();
Print_r ($_SESSION);
echo ' php works';
?>
If I refresh my index.php at first everything loads normally. Ouput:
fodnkd14c3l4jkeunlakg81he5 Array ( [user_id] => 2 )
fodnkd14c3l4jkeunlakg81he5 Array ( [user_id] => 2 ) php works
If I load my page1.php via jquery load, i get this output:
fodnkd14c3l4jkeunlakg81he5 Array ( [user_id] => 2 )
ti7eqnmrrjmeckg5tln3ml2c83 Array ( ) php works
It looks like the session change in page1.php, after jQuery .load. Without session_regenerate_id(); it still does not work. How can I fix this?