Re: Aren't session variable preserved using "Header('Location: xxx')"?
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Wed, 18 Jan 2006 11:05:33 -0500
lwoods wrote:
Wow,
Thanks, Jerry. Kinda' crude, no?
Larry
"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> wrote in message news:Z4ydnfUhzcQz_1PeRVn-pw@xxxxxxxxxxxxxx
lwoods wrote:
Thanks, but I still can't get it to work. Check the following:
Originating Page:
<?
if($_POST['repost']=='y') {
session_start();
$_SESSION['xxx']='test';
session_write_close();
header('Location: http://www.mysite.com/test/testsess2.php');
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action=<? echo $_SERVER['PHP_SELF']; ?> method="post">
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="repost" value="y" />
</form>
</body>
</html>
Target Page - testsess2.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body> <? echo "xxx=".$_SESSION['xxx']; ?> </body> </html>
Try these pages and see if they work for you....
Larry Woods
"d" <d@xxxxxxxxxxx> wrote in message news:T2rzf.3315$wl.1860@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"lwoods" <larry@xxxxxxxxxx> wrote in message news:RPqzf.8953$JT.6285@xxxxxxxxxxxxx
I am trying to pass some info to another page on my site. I set "session_start()" in page 1, assign a session variable to a value, then execute a "header('Location: ....')." But on the target page I don't get any session variable values! BTW, I used a relative location in the Location header, not an absolute URL. The behavior looks like it started another session, but it should not have.
Ideas?
Before the header("location: "), call session_write_close().
That gave me some serious headaches with mac-based browsers hanging. Terrible stuff :)
Oh, and you should always use absolute URLs with location. Relative ones do work, but that's not guaranteed. You could make a function like this to take care of that for you:
function bounce($url) { if (sustr($url, 0, 1)=="/") $url="http://".$_SERVER["HTTP_HOST"].$url; session_write_close(); header("Location: ".$url); exit(); }
or just use that one :-P
TIA,
Larry Woods
Larry,
You need to call session_start() at the beginning of EVERY page which needs session support.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
Not really. You call session_start() on those pages which require session support, and don't on those which don't need sessions. Saves a little unnecessary processing time.
Maybe session_connect() might be a better name? :-)
-- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@xxxxxxxxxxxxx ================== .
- Follow-Ups:
- References:
- Aren't session variable preserved using "Header('Location: xxx')"?
- From: lwoods
- Re: Aren't session variable preserved using "Header('Location: xxx')"?
- From: d
- Re: Aren't session variable preserved using "Header('Location: xxx')"?
- From: lwoods
- Re: Aren't session variable preserved using "Header('Location: xxx')"?
- From: Jerry Stuckle
- Re: Aren't session variable preserved using "Header('Location: xxx')"?
- From: lwoods
- Aren't session variable preserved using "Header('Location: xxx')"?
- Prev by Date: Re: Aren't session variable preserved using "Header('Location: xxx')"?
- Next by Date: Re: file upload
- Previous by thread: Re: Aren't session variable preserved using "Header('Location: xxx')"?
- Next by thread: Re: Aren't session variable preserved using "Header('Location: xxx')"?
- Index(es):
Relevant Pages
|