header

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-01-2004
Ken
 
Posts: n/a
Default header

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.



Reply With Quote
  #2 (permalink)  
Old 10-01-2004
Ken
 
Posts: n/a
Default Re: 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.
>
>
>



Reply With Quote
  #3 (permalink)  
Old 10-01-2004
Erwin Moller
 
Posts: n/a
Default Re: 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
Reply With Quote
  #4 (permalink)  
Old 10-01-2004
Ken
 
Posts: n/a
Default Re: header

"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();


Reply With Quote
  #5 (permalink)  
Old 10-04-2004
Erwin Moller
 
Posts: n/a
Default Re: header

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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:36 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0