在PHP中创建自定义ahref链接

时间:2014-01-16 18:18:54

标签: php

如何使用php在href中创建自定义链接,如下所示

link from : http://www.top10bestwebsitehosting.com/visit.php?site=iPage
goes to : http://www.ipage.com

4 个答案:

答案 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)

最有可能以这种方式完成:

  1. $_GET['site']可以
  2. 的内部列表
  3. 阅读$_GET['site']
  4. 重定向到相应的网站
  5. 这是一个例子:

    <?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']);