urlencode和GET请求在“与"号中断 [英] urlencode and GET request breaks at Ampersand
问题描述
我正在一个有数千个页面的wordpress网站上工作,所有者已经通过一个名为afflink的自定义字段为每个页面输入了会员链接
会员链接使用以下方法在页面上输出:
<?php echo get_post_meta(get_the_ID(), 'afflink', true) ?>
用户单击链接将其发送到名为go.php的页面
链接看起来像这样:
www.mysite.com/go/go.php?url=http://www.somesite.com/redirector.aspx?aid=334&cid=2502&tid=3
go.php页面中的以下元刷新标记:
<meta http-equiv="refresh" content="5;<?php echo $_GET['url']?>
"/>
但是,当页面刷新时,它会将我们发送至:
http://www.somesite.com/redirector.aspx?aid=334
我该如何解决?
在打印指向用户的链接之前,而不是在他单击链接之后,您应该使用urlencode
:
$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>';
[+]
我强烈建议编写一些脚本,以将现有条目更改为适当的脚本.如果所有这些都以www.mysite.com/go/go.php?url=
开头,那么您可以在数据库中将其替换为任何内容,将此部分添加到您的meta标签中,并从db中回显urlencoded链接.
任何其他解决方案都将成为难题.其中之一是从go.php中的其余GET参数重新创建原始网址:
$url = $_GET['url'];
unset($_GET['url']);
if ($_GET) {
$url .= '&' . http_build_query($_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?
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);
}
这篇关于urlencode和GET请求在“与"号中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!