Connecting Tech Pros Worldwide Forums | Help | Site Map

can't get header() to redirect

Bob Garbados
Guest
 
Posts: n/a
#1: Jul 17 '05
forgive my ignorance, as I'm new to php coming from a ms background...

If I create a page named redirect.php and it's only content is:
<?php
header("Location: http://www.google.com");
?>
Should it not redirect to www.google.com? I can't get the header()
function to redirect.

I'm trying to take an online reservation... the customer fills out
contact and billing info at SignUp.php. The form on SignUp.php
submits to Confirm.php, where I perform validation.

If the input fails validation, I want to redirect back to SignUp.php.
Otherwise I will display the input for confirmation before processing
the order. Maybe I'm implementing this wrong... using asp thinking
for a php implementation, but I think this should be simple and I must
be missing something.

thanks.

Sebastian Lauwers
Guest
 
Posts: n/a
#2: Jul 17 '05

re: can't get header() to redirect


Bob Garbados wrote:

[...]
[color=blue]
> If the input fails validation, I want to redirect back to SignUp.php.
> Otherwise I will display the input for confirmation before processing
> the order. Maybe I'm implementing this wrong... using asp thinking
> for a php implementation, but I think this should be simple and I must
> be missing something.[/color]

Instead of redirecting (do you get any error messages by the way?) why
don't you re-show the form if it's not filled in correctly? And now
you're at it, show the user what's wrong (e.g.: what he didn't fill in)
[color=blue]
> thanks.[/color]

HTH,
Sebastian


--
The most likely way for the world to be destroyed,
most experts agree, is by accident.
That's where we come in; we're computer professionals.
We cause accidents.
--Nathaniel Borenstein
steve
Guest
 
Posts: n/a
#3: Jul 17 '05

re: can't get header() to redirect


"Bob Garbados" wrote:[color=blue]
> forgive my ignorance, as I’m new to php coming from a ms
> background...
>
> If I create a page named redirect.php and it’s only content is:
> <?php
> header("Location: http://www.google.com");
> ?>
> Should it not redirect to www.google.com? I can’t get the
> header()
> function to redirect.
>
> I’m trying to take an online reservation... the customer fills
> out
> contact and billing info at SignUp.php. The form on SignUp.php
> submits to Confirm.php, where I perform validation.
>
> If the input fails validation, I want to redirect back to[/color]
SignUp.php.[color=blue]
> Otherwise I will display the input for confirmation before[/color]
processing[color=blue]
> the order. Maybe I’m implementing this wrong... using asp
> thinking
> for a php implementation, but I think this should be simple and I[/color]
must[color=blue]
> be missing something.
>
> thanks.[/color]

The normal way is to process the form on the same script, and redirect
only if everything is ok. The reason has to do with post variables,
and people going back to prev. page (complex but take my word for it).
If you redirect, make sure nothing has been written out (e.g. header
stuff, spaces, etc.). It should work. Please report the error you
get.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-header-r...ict141549.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=473240
Bob Garbados
Guest
 
Posts: n/a
#4: Jul 17 '05

re: can't get header() to redirect


steve <UseLinkToEmail@dbForumz.com> wrote in message news:<41252ed4_2@news.athenanews.com>...[color=blue]
> "Bob Garbados" wrote:[color=green]
> > forgive my ignorance, as I?m new to php coming from a ms
> > background...
> >
> > If I create a page named redirect.php and it?s only content is:
> > <?php
> > header("Location: http://www.google.com");
> > ?>
> > Should it not redirect to www.google.com? I can?t get the
> > header()
> > function to redirect.
> >
> > I?m trying to take an online reservation... the customer fills
> > out
> > contact and billing info at SignUp.php. The form on SignUp.php
> > submits to Confirm.php, where I perform validation.
> >
> > If the input fails validation, I want to redirect back to[/color]
> SignUp.php.[color=green]
> > Otherwise I will display the input for confirmation before[/color]
> processing[color=green]
> > the order. Maybe I?m implementing this wrong... using asp
> > thinking
> > for a php implementation, but I think this should be simple and I[/color]
> must[color=green]
> > be missing something.
> >
> > thanks.[/color]
>
> The normal way is to process the form on the same script, and redirect
> only if everything is ok. The reason has to do with post variables,
> and people going back to prev. page (complex but take my word for it).
> If you redirect, make sure nothing has been written out (e.g. header
> stuff, spaces, etc.). It should work. Please report the error you
> get.[/color]

Thanks...
I'm not seeing an error message, just a blank page. I'm testing it on
my hoster's server because I haven't configured IIS to suppport php
yet and I don't have a linux box set up yet. Is there something to
configure in php.ini to display error messages?

Let me see if I have this right... I have to post the form on
SignUp.php back to SignUp.php, perform the validation, and redirect to
the confirmation page if everything passes validation prior to the
<html> tag?

thanks again.
steve
Guest
 
Posts: n/a
#5: Jul 17 '05

re: can't get header() to redirect


"Bob Garbados" wrote:[color=blue]
> steve <UseLinkToEmail@dbForumz.com> wrote in message
> news:<41252ed4_2@news.athenanews.com>...[color=green]
> > "Bob Garbados" wrote:[color=darkred]
> > > forgive my ignorance, as I?m new to php coming from a ms
> > > background...
> > >
> > > If I create a page named redirect.php and it?s only content[/color][/color]
> is:[color=green][color=darkred]
> > > <?php
> > > header("Location: http://www.google.com");
> > > ?>
> > > Should it not redirect to www.google.com? I can?t get the
> > > header()
> > > function to redirect.
> > >
> > > I?m trying to take an online reservation... the customer[/color][/color]
> fills[color=green][color=darkred]
> > > out
> > > contact and billing info at SignUp.php. The form on[/color][/color]
> SignUp.php[color=green][color=darkred]
> > > submits to Confirm.php, where I perform validation.
> > >
> > > If the input fails validation, I want to redirect back to[/color]
> > SignUp.php.[color=darkred]
> > > Otherwise I will display the input for confirmation before[/color]
> > processing[color=darkred]
> > > the order. Maybe I?m implementing this wrong... using asp
> > > thinking
> > > for a php implementation, but I think this should be simple[/color][/color]
> and I[color=green]
> > must[color=darkred]
> > > be missing something.
> > >
> > > thanks.[/color]
> >
> > The normal way is to process the form on the same script, and[/color]
> redirect[color=green]
> > only if everything is ok. The reason has to do with post[/color]
> variables,[color=green]
> > and people going back to prev. page (complex but take my word for[/color]
> it).[color=green]
> > If you redirect, make sure nothing has been written out (e.g.[/color]
> header[color=green]
> > stuff, spaces, etc.). It should work. Please report the error[/color]
> you[color=green]
> > get.[/color]
>
> Thanks...
> I’m not seeing an error message, just a blank page. I’m
> testing it on
> my hoster’s server because I haven’t configured IIS to
> suppport php
> yet and I don’t have a linux box set up yet. Is there something
> to
> configure in php.ini to display error messages?
>
> Let me see if I have this right... I have to post the form on
> SignUp.php back to SignUp.php, perform the validation, and redirect[/color]
to[color=blue]
> the confirmation page if everything passes validation prior to the
> <html> tag?
>
> thanks again.[/color]

Hi Bob, surprised you get a blank page. Is there a URL or nothing at
all? Why don’t you create a test script with just the header
statement and see how it works.

Yes, you redirect to the same page. So your form would say
<form action=’’ method=post>
and you also would have a hidden field <input type=hidden....
which would be used in the validation to detect that the form has been
submitted. Then if everything is ok, you can redirect.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-header-r...ict141549.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=473984
Bob Garbados
Guest
 
Posts: n/a
#6: Jul 17 '05

re: can't get header() to redirect


Thanks for your help.

I see the URL of the page containing the header() statement, but there's no
content... just whitespace. I created a script with just the header
statement earlier today and it worked without a hitch.

Any php script that I put on the server that has an error like a missing
semicolon, I just see a blank page and no error message.

Originally, my reasoning for having the form post to a different script is
because I will be creating 5 reservation forms for different events. All of
the forms have the same fields for contact info and billing info, they'll
just have different fields for information pertaining to each specific
event. So I wanted to keep all of the validation logic for the contact and
billing info in one spot and not have to maintain the code in five different
places. Am I correct in assuming I could accomplish this through some kind
of include file then?

"steve" <UseLinkToEmail@dbForumz.com> wrote in message
news:41261df0$1_2@news.athenanews.com...[color=blue]
> "Bob Garbados" wrote:[color=green]
> > steve <UseLinkToEmail@dbForumz.com> wrote in message
> > news:<41252ed4_2@news.athenanews.com>...[color=darkred]
> > > "Bob Garbados" wrote:
> > > > forgive my ignorance, as I?m new to php coming from a ms
> > > > background...
> > > >
> > > > If I create a page named redirect.php and it?s only content[/color]
> > is:[color=darkred]
> > > > <?php
> > > > header("Location: http://www.google.com");
> > > > ?>
> > > > Should it not redirect to www.google.com? I can?t get the
> > > > header()
> > > > function to redirect.
> > > >
> > > > I?m trying to take an online reservation... the customer[/color]
> > fills[color=darkred]
> > > > out
> > > > contact and billing info at SignUp.php. The form on[/color]
> > SignUp.php[color=darkred]
> > > > submits to Confirm.php, where I perform validation.
> > > >
> > > > If the input fails validation, I want to redirect back to
> > > SignUp.php.
> > > > Otherwise I will display the input for confirmation before
> > > processing
> > > > the order. Maybe I?m implementing this wrong... using asp
> > > > thinking
> > > > for a php implementation, but I think this should be simple[/color]
> > and I[color=darkred]
> > > must
> > > > be missing something.
> > > >
> > > > thanks.
> > >
> > > The normal way is to process the form on the same script, and[/color]
> > redirect[color=darkred]
> > > only if everything is ok. The reason has to do with post[/color]
> > variables,[color=darkred]
> > > and people going back to prev. page (complex but take my word for[/color]
> > it).[color=darkred]
> > > If you redirect, make sure nothing has been written out (e.g.[/color]
> > header[color=darkred]
> > > stuff, spaces, etc.). It should work. Please report the error[/color]
> > you[color=darkred]
> > > get.[/color]
> >
> > Thanks...
> > I'm not seeing an error message, just a blank page. I'm
> > testing it on
> > my hoster's server because I haven't configured IIS to
> > suppport php
> > yet and I don't have a linux box set up yet. Is there something
> > to
> > configure in php.ini to display error messages?
> >
> > Let me see if I have this right... I have to post the form on
> > SignUp.php back to SignUp.php, perform the validation, and redirect[/color]
> to[color=green]
> > the confirmation page if everything passes validation prior to the
> > <html> tag?
> >
> > thanks again.[/color]
>
> Hi Bob, surprised you get a blank page. Is there a URL or nothing at
> all? Why don't you create a test script with just the header
> statement and see how it works.
>
> Yes, you redirect to the same page. So your form would say
> <form action='' method=post>
> and you also would have a hidden field <input type=hidden....
> which would be used in the validation to detect that the form has been
> submitted. Then if everything is ok, you can redirect.
>
> --
> http://www.dbForumz.com/ This article was posted by author's request
> Articles individually checked for conformance to usenet standards
> Topic URL: http://www.dbForumz.com/PHP-header-r...ict141549.html
> Visit Topic URL to contact author (reg. req'd). Report abuse:[/color]
http://www.dbForumz.com/eform.php?p=473984


steve
Guest
 
Posts: n/a
#7: Jul 17 '05

re: can't get header() to redirect


"Bob Garbados1" wrote:[color=blue]
> Thanks for your help.
>
> I see the URL of the page containing the header() statement, but
> there’s no
> content... just whitespace. I created a script with just the[/color]
header[color=blue]
> statement earlier today and it worked without a hitch.
>
> Any php script that I put on the server that has an error like a
> missing
> semicolon, I just see a blank page and no error message.
>
> Originally, my reasoning for having the form post to a different
> script is
> because I will be creating 5 reservation forms for different[/color]
events.[color=blue]
> All of
> the forms have the same fields for contact info and billing info,
> they’ll
> just have different fields for information pertaining to each[/color]
specific[color=blue]
> event. So I wanted to keep all of the validation logic for the
> contact and
> billing info in one spot and not have to maintain the code in five
> different
> places. Am I correct in assuming I could accomplish this through[/color]
some[color=blue]
> kind
> of include file then?
>
> "steve" <UseLinkToEmail@dbForumz.com> wrote in message
> news:41261df0[/color]
_2@news.athenanews.com...[color=blue][color=green]
> > "Bob Garbados" wrote:[color=darkred]
> > > steve <UseLinkToEmail@dbForumz.com> wrote in message
> > > news:<41252ed4_2@news.athenanews.com>...
> > > > "Bob Garbados" wrote:
> > > > > forgive my ignorance, as I?m new to php coming[/color][/color]
> from a ms[color=green][color=darkred]
> > > > > background...
> > > > >
> > > > > If I create a page named redirect.php and it?s[/color][/color]
> only content[color=green][color=darkred]
> > > is:
> > > > > <?php
> > > > > header("Location: http://www.google.com");
> > > > > ?>
> > > > > Should it not redirect to www.google.com? I[/color][/color]
> can?t get the[color=green][color=darkred]
> > > > > header()
> > > > > function to redirect.
> > > > >
> > > > > I?m trying to take an online reservation... the[/color][/color]
> customer[color=green][color=darkred]
> > > fills
> > > > > out
> > > > > contact and billing info at SignUp.php. The[/color][/color]
> form on[color=green][color=darkred]
> > > SignUp.php
> > > > > submits to Confirm.php, where I perform[/color][/color]
> validation.[color=green][color=darkred]
> > > > >
> > > > > If the input fails validation, I want to[/color][/color]
> redirect back to[color=green][color=darkred]
> > > > SignUp.php.
> > > > > Otherwise I will display the input for[/color][/color]
> confirmation before[color=green][color=darkred]
> > > > processing
> > > > > the order. Maybe I?m implementing this wrong...[/color][/color]
> using asp[color=green][color=darkred]
> > > > > thinking
> > > > > for a php implementation, but I think this[/color][/color]
> should be simple[color=green][color=darkred]
> > > and I
> > > > must
> > > > > be missing something.
> > > > >
> > > > > thanks.
> > > >
> > > > The normal way is to process the form on the same[/color][/color]
> script, and[color=green][color=darkred]
> > > redirect
> > > > only if everything is ok. The reason has to do with[/color][/color]
> post[color=green][color=darkred]
> > > variables,
> > > > and people going back to prev. page (complex but take[/color][/color]
> my word for[color=green][color=darkred]
> > > it).
> > > > If you redirect, make sure nothing has been written[/color][/color]
> out (e.g.[color=green][color=darkred]
> > > header
> > > > stuff, spaces, etc.). It should work. Please report[/color][/color]
> the error[color=green][color=darkred]
> > > you
> > > > get.
> > >
> > > Thanks...
> > > I’m not seeing an error message, just a blank page.[/color][/color]
> I’m[color=green][color=darkred]
> > > testing it on
> > > my hoster’s server because I haven’t configured[/color][/color]
> IIS to[color=green][color=darkred]
> > > suppport php
> > > yet and I don’t have a linux box set up yet. Is[/color][/color]
> there something[color=green][color=darkred]
> > > to
> > > configure in php.ini to display error messages?
> > >
> > > Let me see if I have this right... I have to post the form[/color][/color]
> on[color=green][color=darkred]
> > > SignUp.php back to SignUp.php, perform the validation, and[/color][/color]
> redirect[color=green]
> > to[color=darkred]
> > > the confirmation page if everything passes validation prior[/color][/color]
> to the[color=green][color=darkred]
> > > <html> tag?
> > >
> > > thanks again.[/color]
> >
> > Hi Bob, surprised you get a blank page. Is there a URL or[/color]
> nothing at[color=green]
> > all? Why don’t you create a test script with just the[/color]
> header[color=green]
> > statement and see how it works.
> >
> > Yes, you redirect to the same page. So your form would say
> > <form action=’’ method=post>
> > and you also would have a hidden field <input type=hidden....
> > which would be used in the validation to detect that the form has[/color]
> been[color=green]
> > submitted. Then if everything is ok, you can redirect.
> >
> > --
> > http://www.dbForumz.com/ This article was posted by[/color]
> author’s request[color=green]
> > Articles individually checked for conformance to usenet standards
> > Topic URL:[/color]
> http://www.dbForumz.com/PHP-header-r...ict141549.html[color=green]
> > Visit Topic URL to contact author (reg. req’d). Report[/color]
> abuse:
> http://www.dbForumz.com/eform.php?p=473984[/color]

Bob, as far as header, try to do the header logic at the very top of
the code before anything else is sent. Also do try the buffering with
ob_start, if nothing else works.

PHP has a nice "include" so you can keep the logic in one place.
That is not a problem. Just be cautious of the ways paths in include
work. A bit counter-intuitive, but you should be ok.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-header-r...ict141549.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=474163
Geoff Berrow
Guest
 
Posts: n/a
#8: Jul 17 '05

re: can't get header() to redirect


I noticed that Message-ID: <10ic9s5rbi1af8e@corp.supernews.com> from Bob
Garbados contained the following:
[color=blue]
>Any php script that I put on the server that has an error like a missing
>semicolon, I just see a blank page and no error message.[/color]

Not good. You need a lot more than that for development work.

Create a page containing
<?php
phpinfo();
?>

and see what level of error reporting is set. You may well have to
include a line to turn error reporting back on. See the manual for
details.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Bob Garbados
Guest
 
Posts: n/a
#9: Jul 17 '05

re: can't get header() to redirect


Thanks Geoff. I created the phpinfo() page earlier today as well and
display_errors is 'On', error_reporting is '1'. It's my understanding that
errors should be displayed... am I correct?

I also tried adding the commands ini_set("error_reporting", E_ALL); and
ini_set("display_errors", TRUE); at the top of my php script to no avail.

"Geoff Berrow" <blthecat@ckdog.co.uk> wrote in message
news:1afci0psv0rgnvab346fqa62pbo086lkmv@4ax.com...[color=blue]
> I noticed that Message-ID: <10ic9s5rbi1af8e@corp.supernews.com> from Bob
> Garbados contained the following:
>[color=green]
> >Any php script that I put on the server that has an error like a missing
> >semicolon, I just see a blank page and no error message.[/color]
>
> Not good. You need a lot more than that for development work.
>
> Create a page containing
> <?php
> phpinfo();
> ?>
>
> and see what level of error reporting is set. You may well have to
> include a line to turn error reporting back on. See the manual for
> details.
> --
> Geoff Berrow (put thecat out to email)
> It's only Usenet, no one dies.
> My opinions, not the committee's, mine.
> Simple RFDs http://www.ckdog.co.uk/rfdmaker/[/color]


Bob Garbados
Guest
 
Posts: n/a
#10: Jul 17 '05

re: can't get header() to redirect


My hosting company said that they enabled error logs for php and now the
errors show up. Forgive my ignorance, but how does one enable error logs?


"Bob Garbados" <bobgarbados@hotmail.com> wrote in message
news:10icht97nmmfaca@corp.supernews.com...[color=blue]
> Thanks Geoff. I created the phpinfo() page earlier today as well and
> display_errors is 'On', error_reporting is '1'. It's my understanding[/color]
that[color=blue]
> errors should be displayed... am I correct?
>
> I also tried adding the commands ini_set("error_reporting", E_ALL); and
> ini_set("display_errors", TRUE); at the top of my php script to no avail.
>
> "Geoff Berrow" <blthecat@ckdog.co.uk> wrote in message
> news:1afci0psv0rgnvab346fqa62pbo086lkmv@4ax.com...[color=green]
> > I noticed that Message-ID: <10ic9s5rbi1af8e@corp.supernews.com> from Bob
> > Garbados contained the following:
> >[color=darkred]
> > >Any php script that I put on the server that has an error like a[/color][/color][/color]
missing[color=blue][color=green][color=darkred]
> > >semicolon, I just see a blank page and no error message.[/color]
> >
> > Not good. You need a lot more than that for development work.
> >
> > Create a page containing
> > <?php
> > phpinfo();
> > ?>
> >
> > and see what level of error reporting is set. You may well have to
> > include a line to turn error reporting back on. See the manual for
> > details.
> > --
> > Geoff Berrow (put thecat out to email)
> > It's only Usenet, no one dies.
> > My opinions, not the committee's, mine.
> > Simple RFDs http://www.ckdog.co.uk/rfdmaker/[/color]
>
>[/color]


Geoff Berrow
Guest
 
Posts: n/a
#11: Jul 17 '05

re: can't get header() to redirect


I noticed that Message-ID: <10icht97nmmfaca@corp.supernews.com> from Bob
Garbados contained the following:
[color=blue]
>Thanks Geoff. I created the phpinfo() page earlier today as well and
>display_errors is 'On', error_reporting is '1'. It's my understanding that
>errors should be displayed... am I correct?
>
>I also tried adding the commands ini_set("error_reporting", E_ALL); and
>ini_set("display_errors", TRUE); at the top of my php script to no avail.[/color]

Others know more than me but I use
error_reporting(E_ALL);
ini_set('display_errors', 1);

If that doesn't work, I'm stumped.

If you are using Windows you could simply try downloading PHPDEV from
www.firepages.com.au and doing your development on your local machine.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Closed Thread