doukekui0914 2013-05-12 13:31
浏览 48
已采纳

在Ampersand的urlencode和GET请求中断

I am working on a wordpress website which has thousands of pages and the owner has entered an affiliate link for each page via a custom field named: afflink

The affiliate link is outputted on the page using:

<?php echo get_post_meta(get_the_ID(), 'afflink', true) ?>

The user clicks the link which sends them to a page called go.php

The link looks like this:

www.mysite.com/go/go.php?url=http://www.somesite.com/redirector.aspx?aid=334&cid=2502&tid=3

Within the go.php page is the following meta refresh tag:

<meta http-equiv="refresh" content="5;<?php echo $_GET['url']?>

" />

However, when the page refreshes it sends us to just:

http://www.somesite.com/redirector.aspx?aid=334

How can i fix this?

  • 写回答

3条回答 默认 最新

  • dou47732 2013-05-12 13:39
    关注

    You should use urlencode before printing link to the user, not after he clicks the link:

    $link = "http://www.somesite.com/redirector.aspx?aid=334&cid=2502&tid=3";
    echo '<a href="http://www.mysite.com/go/go.php?url='.urlencode($link).'">' . $link . '</a>';
    

    [+]

    I strongly recommend writing some script that will change existing entries with proper ones. If all of them starts with www.mysite.com/go/go.php?url= then you can replace it with nothing in database, add this part to your meta tag and echo urlencoded link from db.

    Any other solution will be just a kludge. One of it is to recreate original url from the rest of GET parameters in go.php:

    $url = $_GET['url'];
    unset($_GET['url']);
    if ($_GET) {
        $url .= '&' . http_build_query($_GET);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b