Jump to content


Photo

redirecting to different page after having sent data


  • Please log in to reply
5 replies to this topic

#1 boonamera

boonamera
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 16 July 2006 - 06:13 AM

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?



#2 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 16 July 2006 - 06:23 AM

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
if($category == 0)
{
    header(location: http://www.yoursite.com/error.php);
}

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


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

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


#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 July 2006 - 06:26 AM

you can echo a <meta> refresh anywhere on the page, and it will still be picked up.

#4 quimbo

quimbo
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 16 July 2006 - 06:34 AM

if you've already sent headers you could try using the javascript location object:
window.location.href = "http://yoursite.com/error.php"

#5 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 16 July 2006 - 12:17 PM

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



#6 boonamera

boonamera
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 16 July 2006 - 04:55 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users