如何使用php在href中创建自定义链接,如下所示
link from : http://www.top10bestwebsitehosting.com/visit.php?site=iPage
goes to : http://www.ipage.com
答案 0 :(得分:1)
也许是这样的:
$sites = array(
'iPage' => 'http://www.ipage.com/',
'Google' => 'http://www.google.com/',
);
$key = $_GET['site'];
if(isset($sites[$key])) {
header('Location: ' . $sites[$key]);
exit;
}
echo 'Sorry, no such site.';
答案 1 :(得分:0)
有重定向,如果你在firefox开发者工具中打开并打开一个链接,然后按下转义键(否则你将被重定向)你可以看到下一个网址:
http://naturaltracking.com/redirect.php?url=http%3A%2F%2Fwww.ipage.com%2Fjoin%2Findex.bml%3FAffID%3D638751%26amp%3BLinkName%3D&uid=6344b6a239bb&sid=374eaa4bb6d2&hukc=1&nicid=00004ZQNza&nivkey=FiiRIhiDHa
答案 2 :(得分:0)
最有可能以这种方式完成:
$_GET['site']
可以$_GET['site']
这是一个例子:
<?php
// visit.php
$pages = array('iPage'=>'www.ipage.com','google','www.google.com');
if (in_array($pages,$_GET['site']))
{
// do some internal logging or whatever
header("Location: ".$pages[$_GET['site']]);
}
?>
答案 3 :(得分:0)
top10bestwebsitehosting的方式是,它将URL保存在数据库中。那么它会做类似于下面的事情:
$name = mysql_real_escape_string($_GET['site']); //check for escapes etc.
$query = mysql_query('select * from `websites` where `name` = {$name} limit 1');
$row = mysql_fetch_row($query);
header('Location: '.$row['url']);