You are here: Re: Aren't session variable preserved using "Header('Location: xxx')"? « PHP Programming Language « IT news, forums, messages
Re: Aren't session variable preserved using "Header('Location: xxx')"?

Posted by lwoods on 10/02/46 11:38

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" <hexkid@dodgeit.com> wrote in message
news:slrndssk63.h04.hexkid@ID-203069.user.individual.net...
> lwoods top-posted (corrected):
>> "d" <d@example.com> wrote in message
>> news:T2rzf.3315$wl.1860@text.news.blueyonder.co.uk...
>>> "lwoods" <larry@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>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация