Does the include() command break sessions?
Posted: Sun Jun 03, 2007 4:59 pm
feyd | Please use
File b.php:
The output is:
Is there a way to make this work?
Thanks,
Griff
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am unable to get a session to persist through an include() command. I have distilled the problem down to file a.php that includes file b.php. a.php starts a session, sets a session variable and includes b.php. b.php starts the session, changes the session variable and completes. a.php prints out the session variable. The change made by b.php to the session variable is not evident in the output of a.php.
File a.php:Code: Select all
<?php
session_start();
?>
<html><head><title>a</title></head><body>
<?php
$_SESSION['MySession'] = 'initial_MySession';
include("http://localhost/b.php");
print '$_SESSION["MySession"] is: '.$_SESSION['MySession'];
?>
</body></html>Code: Select all
<?php
session_start();
$_SESSION['MySession'] = 'new_MySession';
?>Code: Select all
$_SESSION["MySession"] is: initial_MySessionIs there a way to make this work?
Thanks,
Griff
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]