Jump to content

Archived

This topic is now archived and is closed to further replies.

boonamera

redirecting to different page after having sent data

Recommended Posts

basically i'm trying to do something like this:

index.php has:

if($category == 0)
{
          // GO to error.php
}

how would i go about making the page refresh to error.php?
So if i understood correctly i can't used  header because I have data above it.
Then i can't use meta because that needs to be in the header.

What's left?

Share this post


Link to post
Share on other sites
you can use header(location: $url)
or something like that i dont remember the exact syntax... regardless of the fact that there is code above
however you cant have output any data
meaning
this will work
[code]
if($category == 0)
{
    header(location: http://www.yoursite.com/error.php);
}
[/code]

[code]
echo "blah";
if($category == 0)
{
    header(location: http://www.yoursite.com/error.php);
}

[/code]

the second will fail becasue something has been output to the browser.
make sense?

correct syntax:
[code]
header("Location: http://www.yoursite.com/error.php");
[/code]

Share this post


Link to post
Share on other sites
you can echo a <meta> refresh anywhere on the page, and it will still be picked up.

Share this post


Link to post
Share on other sites
if you've already sent headers you could try using the javascript location object:
window.location.href = "http://yoursite.com/error.php"

Share this post


Link to post
Share on other sites
you could also try to include the error.php, if the border styles and formating is the same.  you could use something like if(condition){include("error.php";)}

i would also rename the file .inc, so that it easy to tell wht it is used for.

this is sometimes good for form validation, where you want to redisplay the form, the form would simply be in the inc file

Share this post


Link to post
Share on other sites
thanks guys

I got 2 versions working: with the meta and with the include

I couldn't use header as i had outputted preivously.

I think the include method should do the trick but the only problem with it is that I would like the address to show http://domain.com/error
anyways of doing that?

Otherwise ill stick with the meta,

thx

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.