Header

They have: 51 posts

Joined: Dec 2002

Just started learning php and am in the process of doing a tutorial. If I wanted to redirect a user to page B as soon as they arrived at page A would I use the following code:

<?php
header
( "Location:<a href="http://www.someurl.com" class="bb-url">http://www.someurl.com</a>");
exit;
?>

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

yes you would.

They have: 51 posts

Joined: Dec 2002

cheers

They have: 461 posts

Joined: Jul 2003

fyi: if you want to have a delay you need to use the html meta tag, and if you want to be able to vary on some things (like e i have) you will need a page creation function of your own that takes a url and time. (like i did) and if you wanna add other things you can put them thre too. mine for redirection takes three arguments: title, url, delay

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

They have: 51 posts

Joined: Dec 2002

I read somewhere that with the code I mentioned above you can only use it at the very beginning of the script, it won't work if it's further down, that true?

Is there any other way to do a redirect other than that which I mentioned?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

yes and no -- you can use that anywhere in the script if you're exiting right afterwards. Thing is, if the headers are already sent (page is loading), you can't send MORE headers, so if you want it in the same page, no can do, it must be first.

Why do you want to redirect? That may help people give you specific and helpful advice instead of just guessing at it.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

&lt;script language="javascript" type="text/javascript"&gt;
<!--
self.location='index.html';
//-->
&lt;/script&gt;
'

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 51 posts

Joined: Dec 2002

no particlar reason, I just wanted to know if there were other ways of redirecting

cheers

They have: 461 posts

Joined: Jul 2003

change the numbe (0) to however many seconds you want. 0 is immediate (same as headers function)

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.