开发者

URL Redirect, HTML, PHP

I want to link links on my website via go.php?urlhere, I have been told and I have tried using go.php?url=urlhere however the URL's to which I redirect, redirect to another URL with-in it for example go.php?http://.com/click?p=0&a=0&url=http://.com, many of the redirect I have tried to use simply copy the URL in the go.php file and use a meta refresh or a window.location reload; however they redirect to the second URL and not the first one. Sometimes when I do actually get it to redirect the first part of the redirected URL gets all the dots changed to "_" w开发者_StackOverflow社区hich stops it redirecting.

I want to have something like this website using on its "Buy It Now" buttons

http://www.searchchief.co.uk/Search/Sony-PSP-Go


So I think this is what you are asking: How do I redirect to a page using a url as a query string parameter?

eg.

http://www.myurl.com/go.php?url=http%3A%2F%2Fwww.myotherurl.com

You must do two things to achieve this on the url:

  1. have a query string parameter. eg. go.php?url=mysite.com or go.php?redirect=mysite.com not just go.php?mysite.com.

  2. you must URL ENCODE this query string parameter value. eg. go.php?url=http%3A%2F%2Fwww.myotherurl.com NOT go.php?url=http://www.myotherurl.com. In php you can use the urlencode() function or http://meyerweb.com/eric/tools/dencoder/ can do it for you if you have a small number of urls to convert.

On the PHP side of things you will use the following

<?php
     header('Location: '.urldecode($_GET['url']));
     exit();
?>

You can do other basic checks on the php side of things eg. check for a valid url format etc


I think you want to use the header command.

So, in your case you would do this:

For a url in this syntax: go.php?url=thisurl

This would be the code

<?php
header('Location: ' . $_GET['url']);
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜