Jump to content

redirecting to different page after having sent data


boonamera

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?

Link to comment
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]
Link to comment
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

Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.