Session lost after 302 redirection

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Locked
maxwell44
New Member
New Member
Posts: 3
Joined: Mon Sep 29, 2008 8:04 am

Session lost after 302 redirection

Post by maxwell44 »

Hi,

I have a very strange issue.
I add a rule into my htaccess, which is the following one:

Code: Select all

# Session rule
RewriteRule ^([0-9]+)/(.*) session_script.php?source_traffic=$1&page_name=$2 [L]
Into the script "session_script.php" I have this code :

Code: Select all

<?php
if(!isset($_SESSION))session_start();

include(dirname(__FILE__).'/config.php');

if ( isset($_GET['source_yad']) && isset($_GET['page_yad']) ){

	if (isset($_SESSION['s_landing_page']))	unset('s_landing_page']);
	if (isset($_SESSION['i_source_id']))	unset('i_source_id']);

	$_SESSION['i_source_id'] = $_GET['source_traffic'];
	$_SESSION['s_landing_page'] = $_GET['page_name'];

	header("Location:http://".$_SERVER['HTTP_HOST']."/".$_GET['page_name']);
}
else{
	header("Location:http://".$_SERVER['HTTP_HOST']);
}

?>
At this point if I check the value of the session variable I get the right data.

Code: Select all

<?php
[...]
	$_SESSION['i_source_id'] = $_GET['source_traffic'];
	$_SESSION['s_landing_page'] = $_GET['page_name'];

	var_dump($_SESSION['i_source_id']);

	//header("Location:http://".$_SERVER['HTTP_HOST']."/".$_GET['page_name']);
[...]
?>
result :

Code: Select all

int(2)
Now if I uncomment the redirection. let day the page alias is test, and the template name used is test also.
http://www.mywebsite.com/test


into the template I call just one tag and that's it. the tag name is "session_test"
into this tag I have the following code:

Code: Select all

sesssion_start();
var_dump($_SESSION['i_source_id']);
and the result is:

Code: Select all

NULL
I don't understand. I am loosing the data after the redirection. Maybe the CMS destroy the session ?
Have you got the same problem ? Where it comes from ?

thanks guys.
maxwell44
New Member
New Member
Posts: 3
Joined: Mon Sep 29, 2008 8:04 am

Re: Session lost after 302 redirection

Post by maxwell44 »

I fix the issue, but I still don't know where it comes from.

I have added this line into the index.php (first line):

Code: Select all

if(!isset($_SESSION)){session_start();}
and now it's working.
Locked

Return to “Developers Discussion”