This is a discussion on Sending user to another page ? within the PHP Language forums, part of the PHP Programming Forums category; Hi guys, I want to do something simple, here is the code: <?php if($ageCheck) // goto mainpage.html else // ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi guys,
I want to do something simple, here is the code: <?php if($ageCheck) // goto mainpage.html else // goto under21.html ?> What is the best way to do that ? I looked at header() but I'm not sure if that's the best way. Thanks. Take care, Cyrus |
|
|||
|
Cyrus D. wrote:
> Hi guys, > > I want to do something simple, here is the code: > > <?php > > if($ageCheck) > // goto mainpage.html > else > // goto under21.html > >> > > What is the best way to do that ? I looked at header() but I'm not > sure if that's the best way. Thanks. > > Take care, > Cyrus Any reason that you can't do: <?php if( $ageCheck ) { include( 'mainpage.html' ); } else { include( 'under21.html' ); } ?> |
|
|||
|
"Cyrus D." wrote:
> > Hi, > > No, I don't want to do it that way for several reasons. > > Is it so difficult to just send the user to another URL ? It should be an > easy thing to do. Header("Location: http://whatever.com/under21.php") should work fine, as long as you haven't outputted any text at all before the header. And you should put an exit() afer it. Shawn -- Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com |
|
|||
|
Thanks man,
The thing that was confusing me with Header() is the part about not outputing anything before the call. That just means outputing something that would show up on the page, like the output from 'echo' right ? I can still have functions with calculations before the Header() call can't I ? Take care, Cyrus |
|
|||
|
Cyrus D. wrote:
> No, I don't want to do it that way for several reasons. > > Is it so difficult to just send the user to another URL ? It should be an > easy thing to do No, its not difficult. The last solution given to you proves that. You could do yourself a big favour by explaining your needs more accurately (and being less dismissive of someone that's taken the time to gve you an extremely elegant solution.) |
|
|||
|
"Cyrus D." wrote:
> > The thing that was confusing me with Header() is the part about not > outputing anything before the call. > > That just means outputing something that would show up on the page, like the > output from 'echo' right ? I can still have functions with calculations > before the Header() call can't I ? Yup, that could be something from echo, any HTML you have in the page before the header, any error messages that the server produces, or even just a single blank line before your first <?PHP tag. Or it could be any of the above produced from any included or required files. You can do calculations as long as they produce no output or you buffer the output. Shawn -- Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com |