RE: Validation and session variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm



> -----Original Message-----
> From: Stuart Felenstein [mailto:stuart4m@xxxxxxxxx] 
> Sent: 27 October 2004 00:01
> 
> Having some odd behaviour. 
> First , let me mention this is a multi page form using
> session variables. (This might be important)
> 
> So I am doing a page by page validation, and have
> tried putting the code before session_start or after. 
> Either way my session variables are getting lost.
> 
> Now in order to do my validation on the same page, I
> have set form action to nothing action=""
> And upon sucess of happy validation added this code:
> 
> if ($_SERVER["REQUEST_METHOD"] == "POST") {
>  $url = "success.php";
>  Header("Location: $url");
> }
> ?>
> 
> The page progresses correctly but it seems the
> variables are gone.  
> Sound like it makes sense ? Any suggestions or ideas.

The only circumstance under which I can think this might happen is if the
session id is not being propagated by cookie -- either because they're
blocked in the browser, or because you have them switched off in php.ini.
Even if you have session.use_trans_sid enabled, PHP cannot rewrite URLs in
the header() call, so you have to include the session ID manually.  You
should do this regardless of whether you expect cookies to be enabled, so
that it will work ok even in the unexpected situation of having cookies
turned off.

Fortunately, the standard PHP constant SID is provided for exactly this
purpose, so your header call above should be:

   header("Location: $url?".SID);

Finally, you should note that HTTP requires the Location: URL to be a full
absolute one (i.e. starting http://) -- whilst it's true that all current
mainstream browsers do the expected with a relative URL, it's better
defensive programming to use only absolute URLs (just in case someone
produces a browser that adheres to the standard!).

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services, JG125, James
Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS,
LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux