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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。