By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,722 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,722 IT Pros & Developers. It's quick & easy.

Sending user to another page ?

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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' );
}

?>
Jul 17 '05 #2

P: n/a
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.

Take care,
Cyrus
Jul 17 '05 #3

P: n/a
"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
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #4

P: n/a
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
Jul 17 '05 #5

P: n/a
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.)
Jul 17 '05 #6

P: n/a
"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
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.