View Full Version : redirect url
nikomou
04-05-2006, 07:43 PM
Hi,
I've set up a simple script to redirect to a page depending on what the &url= parameter is...
<?php
$goto = $_GET['goto'];
?>
<html>
<head>
<title>Mobile Phone Deals</title>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="refresh" content="40;url=<?php echo ("$goto")?>">
</head>
<body>
</body>
<html>
the problem being, if the URL i am redirecting to, has a " & " in it, it doesnt work... (i'm using affiliate links, so sum URL could have more than one " & " in the URL...
<?php echo(htmlentities($goto)); ?>
nikomou
04-05-2006, 09:25 PM
tha doesnt work Twey..
it just ignores anything after a question mark ? or a and sign &
the other problem is that there are more parametres that will be called..
e.g. /goto.php?1=this&2=that&goto=http://www.google.co.uk/search?hl=en&q=php&meta=
Hm. The question mark should be fine, but the ampersand would usually cause trouble: they're meant to be escaped as &. Can you show me the output of your script?
nikomou
04-05-2006, 09:36 PM
yeah, was just gunna edit to say that theres no problem with the question mark...
if goto is this url:
http://www.google.co.uk/search?hl=en&q=php&meta=
i get this...
<html>
<head>
<title>Redirect</title>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="refresh" content="4;url=http://www.google.co.uk/search?hl=en">
</head>
<body>
</body>
<html>
Aaaaaah. Of course you do. You need to escape the ampersands as %26 when you first feed them into the script.
redir.php?goto=http%3A%2F%2Fwww%2Egoogle%2Eco%2Euk%2Fsearch%3Fhl%3Den%26q%3Dphp%26meta%3D
If you call the urlencode() function on the string in PHP, it'll perform this replacement for you.
I suggest you use an HTTP redirect rather than a meta refresh, though.
nikomou
04-05-2006, 10:06 PM
thought i would of had to do that...
could you give me an example of a HTTP redirect script/code?!?
Cheers.
<?php header("Location: http://www.google.co.uk/search?hl=en&q=php&meta="); ?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.