By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,574 Members | 2,966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,574 IT Pros & Developers. It's quick & easy.

Aren't session variable preserved using "Header('Location: xxx')"?

P: n/a
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?

TIA,

Larry Woods
Jan 18 '06 #1
Share this Question
Share on Google+
23 Replies


P: n/a
d
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
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

Jan 18 '06 #2

P: n/a
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@example.com> wrote in message
news:T2****************@text.news.blueyonder.co.uk ...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
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


Jan 18 '06 #3

P: n/a
d
"lwoods" <la***@lwoods.com> wrote in message
news:NIrzf.8954$JT.3009@fed1read06...
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:
It looks like you're not starting your session in this script:
<!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@example.com> wrote in message
news:T2****************@text.news.blueyonder.co.uk ...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
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



Jan 18 '06 #4

P: n/a
lwoods top-posted (corrected):
"d" <d@example.com> wrote in message
news:T2****************@text.news.blueyonder.co.uk ...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
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().

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();
}
?> <snip>
Target Page - testsess2.php:
You need a session_start() right here!

<?php session_start() ?> <!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....


With the session_start they do ... but I didn't test it :-)

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Jan 18 '06 #5

P: n/a
You have to do a "start_session()" in EVERY script where you use SESSION
variables? I thought that you only had to start the session once.

Larry
"d" <d@example.com> wrote in message
news:ry***************@text.news.blueyonder.co.uk. ..
"lwoods" <la***@lwoods.com> wrote in message
news:NIrzf.8954$JT.3009@fed1read06...
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:


It looks like you're not starting your session in this script:
<!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@example.com> wrote in message
news:T2****************@text.news.blueyonder.co.uk ...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
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



Jan 18 '06 #6

P: n/a
You have to do a "start_session()" in EVERY script where you use SESSION
variables? I thought that you only had to start the session once.

Larry
"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.individual.net...
lwoods top-posted (corrected):
"d" <d@example.com> wrote in message
news:T2****************@text.news.blueyonder.co.uk ...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
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().

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();
}
?>

<snip>
Target Page - testsess2.php:


You need a session_start() right here!

<?php session_start() ?>
<!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....


With the session_start they do ... but I didn't test it :-)

--
If you're posting through Google read <http://cfaj.freeshell.org/google>

Jan 18 '06 #7

P: n/a
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@example.com> wrote in message
news:T2****************@text.news.blueyonder.co.uk ...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
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.
js*******@attglobal.net
==================
Jan 18 '06 #8

P: n/a
Wow,

Thanks, Jerry. Kinda' crude, no?

Larry
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Z4********************@comcast.com...
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@example.com> wrote in message
news:T2****************@text.news.blueyonder.co.uk ...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...

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.
js*******@attglobal.net
==================

Jan 18 '06 #9

P: n/a
lwoods wrote:
You have to do a "start_session()" in EVERY script where you use SESSION
variables? I thought that you only had to start the session once.

Larry
"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.individual.net...
lwoods top-posted (corrected):
"d" <d@example.com> wrote in message
news:T2****************@text.news.blueyonder.co .uk...

"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...

>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().

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();
}
?>


<snip>
Target Page - testsess2.php:


You need a session_start() right here!

<?php session_start() ?>
<!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....


With the session_start they do ... but I didn't test it :-)

--
If you're posting through Google read <http://cfaj.freeshell.org/google>



Nope, you need it in every page.

Also, I mistyped - it's session_start().

And please don't top post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 18 '06 #10

P: n/a
lwoods wrote:
Wow,

Thanks, Jerry. Kinda' crude, no?

Larry
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Z4********************@comcast.com...
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@example.com> wrote in message
news:T2****************@text.news.blueyonder.co .uk...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
>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.
js*******@attglobal.net
==================



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.
js*******@attglobal.net
==================
Jan 18 '06 #11

P: n/a
d
"lwoods" <la***@lwoods.com> wrote in message
news:Tftzf.8958$JT.5294@fed1read06...
You have to do a "start_session()" in EVERY script where you use SESSION
variables? I thought that you only had to start the session once.
You have to do that every time you want to use the session.
Larry
"d" <d@example.com> wrote in message
news:ry***************@text.news.blueyonder.co.uk. ..
"lwoods" <la***@lwoods.com> wrote in message
news:NIrzf.8954$JT.3009@fed1read06...
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:


It looks like you're not starting your session in this script:
<!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@example.com> wrote in message
news:T2****************@text.news.blueyonder.co.uk ...
"lwoods" <la***@lwoods.com> wrote in message
news:RPqzf.8953$JT.6285@fed1read06...
>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
>



Jan 18 '06 #12

P: n/a
d
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:FN********************@comcast.com...
lwoods wrote:
Wow,

Thanks, Jerry. Kinda' crude, no?

Larry
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Z4********************@comcast.com...
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@example.com> wrote in message
news:T2****************@text.news.blueyonder.c o.uk...
>"lwoods" <la***@lwoods.com> wrote in message
>news:RPqzf.8953$JT.6285@fed1read06...
>
>
>>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.
js*******@attglobal.net
==================


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.


Not to mention the default session handler will only allow two scripts to
use the same session at the same time - if sessions were "always on", then
you'd get timeouts all over the place.
Maybe session_connect() might be a better name? :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jan 18 '06 #13

P: n/a
Jerry,

What does "top post" mean?

TIA,

Larry
Nope, you need it in every page.

Also, I mistyped - it's session_start().

And please don't top post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jan 18 '06 #14

P: n/a
First, I really enjoy working with PHP so I don't want to get something
started, but I also work with ASP and there is no such thing as "turning on
and off" session support. It's just there! The only problem that you run
into is if someone has cookies turned off...but I live with that.

Anyway, I'll remember to put "session_start()" at the top of each page...and
before any headers...which I also discovered the hard way.

Thanks to all...

Larry
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.


Not to mention the default session handler will only allow two scripts to
use the same session at the same time - if sessions were "always on", then
you'd get timeouts all over the place.
Maybe session_connect() might be a better name? :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


Jan 18 '06 #15

P: n/a
lwoods wrote:
Jerry,

What does "top post" mean?

TIA,

Larry

Nope, you need it in every page.

Also, I mistyped - it's session_start().

And please don't top post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


It means posting your response at the top of the page.

Becasue it doesn't follow the normal reading flow.
Why is top posting bad?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 18 '06 #16

P: n/a
lwoods wrote:
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.


If your session uses cookie, it should work. But, if you use trans
sid, it won't rewrite the URL in header()--it will *only* rewrite
"url_rewriter.tags"

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jan 19 '06 #17

P: n/a
d
"lwoods" <la***@lwoods.com> wrote in message
news:Ncvzf.8967$JT.2242@fed1read06...
Jerry,

What does "top post" mean?

TIA,

Larry
Nope, you need it in every page.

Also, I mistyped - it's session_start().

And please don't top post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


Some people get a real bug up their ass about it, as if it makes a
difference ;) Individual replies are still clearly seperated in the post,
so it's not as if you're hunting for hours for the real text. If you can't
follow a thread that has top-posts in it, you probably shouldn't be using a
computer ;)

(my apologies to all top-posting haters :))
Jan 19 '06 #18

P: n/a
d
"lwoods" <la***@lwoods.com> wrote in message
news:7gvzf.8968$JT.5454@fed1read06...
First, I really enjoy working with PHP so I don't want to get something
started, but I also work with ASP and there is no such thing as "turning
on and off" session support. It's just there! The only problem that you
run into is if someone has cookies turned off...but I live with that.
Session support IS always there in PHP, but you don't always want to use it.
Having your sessions enabled for every script regardless of whether you want
them or not is uneccesary overhead.
Anyway, I'll remember to put "session_start()" at the top of each
page...and before any headers...which I also discovered the hard way.
Or you can use output buffering, and put it wherever you want ;)
Thanks to all...

Larry
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.


Not to mention the default session handler will only allow two scripts to
use the same session at the same time - if sessions were "always on",
then you'd get timeouts all over the place.
Maybe session_connect() might be a better name? :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================



Jan 19 '06 #19

P: n/a
d
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
lwoods wrote:
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.
If your session uses cookie, it should work. But, if you use trans
sid, it won't rewrite the URL in header()--it will *only* rewrite
"url_rewriter.tags"


trans sid makes the site's URLs look like crap, and everyone supports
cookies these days, so it's not really an issue ;)
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jan 19 '06 #20

P: n/a
d wrote:

Some of us do not have easy access to the previous post in the thread.
Having the quoted text before the new text, helps us understand what the
post is responding to.
Some people get a real bug up their ass about it, as if it makes a
difference ;)
Yes, they are.
It would be even better if the comments were posted right below what
they comment on, like I'm doing here.
Individual replies are still clearly seperated in the post,
so it's not as if you're hunting for hours for the real text.
If you liked this post of mine, you probably shouldn't be using a
computer eiter :)
If you can't
follow a thread that has top-posts in it, you probably shouldn't be using a
computer ;)



Richard Heathfield did a much better job than my attempt at copying
this style;
see MSG_ID: <dp**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>
on comp.lang.c

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Jan 19 '06 #21

P: n/a
d
"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.individual.net...
d wrote:

Some of us do not have easy access to the previous post in the thread.
Having the quoted text before the new text, helps us understand what the
post is responding to.
Some people get a real bug up their ass about it, as if it makes a
difference ;)
Yes, they are.
It would be even better if the comments were posted right below what
they comment on, like I'm doing here.
Individual replies are still clearly seperated in the post,
so it's not as if you're hunting for hours for the real text.


If you liked this post of mine, you probably shouldn't be using a
computer eiter :)
If you can't
follow a thread that has top-posts in it, you probably shouldn't be using
a
computer ;)


The thing is, I'm just here to help people. I don't give a rat's ass if
people top post, bottom post, sideways post or inside-out post. It's
helping people that matters. Being a usenet nazi isn't helping (not that
I'm accusing you or anyone of that, you understand ;))


Richard Heathfield did a much better job than my attempt at copying
this style;
see MSG_ID: <dp**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>
on comp.lang.c

--
If you're posting through Google read <http://cfaj.freeshell.org/google>

Jan 19 '06 #22

P: n/a
d wrote:
The thing is, I'm just here to help people.
I don't give a rat's ass if people top post, bottom post, sideways
post or inside-out post. It's helping people that matters.
The worst of it all is when people post without enough of previous posts
for context (like in google). I will move the link in my signature to
the top and hope people read *and follow* its guidelines.

Imagine you see a post "out of the blue" like this:
--------
And now the page is completely blank. Why?
--------
Being a usenet nazi isn't helping (not that I'm accusing you or anyone
of that, you understand ;))


It's the people that need help who should try to help the helpers.
If, as a helper, I need to spend 30 seconds to interpret the question
instead of 2, I may (and did a few times before) ignore further
questions from the person.

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Jan 19 '06 #23

P: n/a
d
"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.individual.net...
d wrote:
The thing is, I'm just here to help people.
I don't give a rat's ass if people top post, bottom post, sideways
post or inside-out post. It's helping people that matters.
The worst of it all is when people post without enough of previous posts
for context (like in google). I will move the link in my signature to
the top and hope people read *and follow* its guidelines.

Imagine you see a post "out of the blue" like this:
--------
And now the page is completely blank. Why?
--------
Being a usenet nazi isn't helping (not that I'm accusing you or anyone
of that, you understand ;))


It's the people that need help who should try to help the helpers.
If, as a helper, I need to spend 30 seconds to interpret the question
instead of 2, I may (and did a few times before) ignore further
questions from the person.


It's not a big deal to most people, that's all I'm saying.
--
If you're posting through Google read <http://cfaj.freeshell.org/google>

Jan 22 '06 #24

This discussion thread is closed

Replies have been disabled for this discussion.