This is a discussion on header within the PHP Language forums, part of the PHP Programming Forums category; Can I carry the session_id() over to the next page on a header? header("LOCATION: http://domainname.com/view_error....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Can I carry the session_id() over to the next page on a header?
header("LOCATION: http://domainname.com/view_error.php?sessionid=".$sessionid); exit(); OR Inside an if statement, how can I branch to the page view_error.php?session_id() without using a header. |
|
|||
|
Addition $sessionid = session_id();
"Ken" <kkrolski@wi.rr.com> wrote in message news:Vg77d.51642$B51.49405@twister.rdc-kc.rr.com... > Can I carry the session_id() over to the next page on a header? $sessionid = session_id(); > header("LOCATION: http://domainname.com/view_error.php?sessionid=".$sessionid); > exit(); > > OR > > Inside an if statement, how can I branch to the page view_error.php?session_id() without using a header. > > > |
|
|||
|
Ken wrote:
Hi Ken, > Can I carry the session_id() over to the next page on a header? > > header("LOCATION: > http://domainname.com/view_error.php?sessionid=".$sessionid); > exit(); Yes, that should work just fine. > > OR > > Inside an if statement, how can I branch to the page > view_error.php?session_id() without using a header. How excactly do you go to that errorpage if not redirecting the browser to it? Maybe show some code with that if-statement. Anyway: If you go send the user to that errorpage, it is up to you if you want to keep the session alive. If you send the client to the errorpage without maintaining the session, the session will be lost (doh). Unless of course cookies are used. Regards, Erwin Moller |
|
|||
|
"Erwin Moller"
<since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in message news:415d44c2$0$78772$e4fe514c@news.xs4all.nl... > Ken wrote: > > Hi Ken, > > > Can I carry the session_id() over to the next page on a header? > > > > header("LOCATION: > > http://domainname.com/view_error.php?sessionid=".$sessionid); > > exit(); > > Yes, that should work just fine. > > > > > OR > > > > Inside an if statement, how can I branch to the page > > view_error.php?session_id() without using a header. > > How exactly do you go to that errorpage if not redirecting the browser to > it? > Maybe show some code with that if-statement. > > Anyway: If you go send the user to that errorpage, it is up to you if you > want to keep the session alive. If you send the client to the errorpage > without maintaining the session, the session will be lost (doh). Unless of > course cookies are used. > > Regards, > Erwin Moller > Yes, that should work just fine. I thought it should work. But it does not. Maybe this is my problem. The user Submits on add_pic.php which takes him to the view_pictures.php page. The PHP at the top of the page checks for errors then jumps to view_pictures_error.php without displaying the view_pictures.php page. Note exit() after the header. When are the variables and session variables set. After the script is read or after the page is displayed? Here is more of the code. I do want to keep the session going. The user corrects the problem and continues with other pages. add-pic.php <form enctype="multipart/form-data" name="picture" method="post" action="view_pictures.php"> <input type="hidden" name="sessionid" value="<?PHP echo session_id(); ?>"> <table align="center" cellspacing="5" cellpadding="0" border="0"> <tr><td><input type="button" value="Continue" onClick="validate_pictures)"></td></tr></table></form> view_pictures.php session_id($sessionid); session_start(); if (($validity[1] == "true") && ($validity[2] == "true") && ($validity[3] == "true") && ($validity[4] == "true") && ($validity[5] == "true") && ($validity[6] == "true") && ($validity[7] == "true") && ($validity[8] == "true") && ($validity[9] == "true") && ($validity[10] == "true") ) { } else { $_SESSION['add_pic_skip'] = 1; header("LOCATION: http://domainname.com/view_pictures_error.php?sessionid=".$sessionid); exit(); view_pictures_error.php session_id($sessionid); session_start(); |
|
|||
|
Ken wrote:
> "Erwin Moller" > <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in > message news:415d44c2$0$78772$e4fe514c@news.xs4all.nl... >> Ken wrote: >> >> Hi Ken, >> >> > Can I carry the session_id() over to the next page on a header? >> > >> > header("LOCATION: >> > http://domainname.com/view_error.php?sessionid=".$sessionid); >> > exit(); >> >> Yes, that should work just fine. >> >> > >> > OR >> > >> > Inside an if statement, how can I branch to the page >> > view_error.php?session_id() without using a header. >> >> How exactly do you go to that errorpage if not redirecting the browser to >> it? >> Maybe show some code with that if-statement. >> >> Anyway: If you go send the user to that errorpage, it is up to you if you >> want to keep the session alive. If you send the client to the errorpage >> without maintaining the session, the session will be lost (doh). Unless >> of course cookies are used. >> >> Regards, >> Erwin Moller > >> Yes, that should work just fine. > I thought it should work. But it does not. > > Maybe this is my problem. > The user Submits on add_pic.php > which takes him to the view_pictures.php page. > The PHP at the top of the page checks for errors > then jumps to view_pictures_error.php without displaying the > view_pictures.php page. Note exit() after the header. > > When are the variables and session variables set. After the script is > read or after the page is displayed? I never use session_start() and the like anymore. It is very confusing in certain situations (like yours maybe) I recommend to auto_start session (via php.ini). If you need to check certain credentials (like if somebody is logged in), just use a session-var for that. eg: $_SESSION["isLoggedIn"] = "Y"; And check for that where needed. I also recommend to let PHP take care of the session. PHP is able to rewrite URL's (adding ?PHPSESSIONID=982398425) and forms too (By adding a hidden var with the sessionid) and when cookies are enabled, PHP will use cookies to propagate the session between pages. It works just fine and will safe you a lot of headache, believe me, been there. :-) But I cannot tell you what goes wrong in your situation without knowing a lot more about the code/php.ini/etc. Hope this helps nonetheless. :-) Regards, Erwin Moller > > Here is more of the code. I do want to keep the session going. The user > corrects the problem and continues with other pages. > > add-pic.php > <form enctype="multipart/form-data" name="picture" method="post" > action="view_pictures.php"> > <input type="hidden" name="sessionid" value="<?PHP echo session_id(); ?>"> > <table align="center" cellspacing="5" cellpadding="0" border="0"> > <tr><td><input type="button" value="Continue" > onClick="validate_pictures)"></td></tr></table></form> > > view_pictures.php > session_id($sessionid); > session_start(); > > if (($validity[1] == "true") && ($validity[2] == "true") && ($validity[3] > == "true") && ($validity[4] == "true") && ($validity[5] == "true") && > ($validity[6] == "true") && ($validity[7] == "true") && ($validity[8] == > "true") && ($validity[9] == "true") && ($validity[10] == "true") ) { } > else { > $_SESSION['add_pic_skip'] = 1; > header("LOCATION: > http://domainname.com/view_pictures_error.php?sessionid=".$sessionid); > exit(); > > view_pictures_error.php > session_id($sessionid); > session_start(); |