[英]PHP Variables not passing to url correctly from API
我正在尝试使用来自codecanyon的Premium URL Shortener脚本,我已经寻求支持,但它们似乎有点忙,因此响应时间不是很快。
我遇到的问题是当API使用以下缩短的查询将请求发送到url缩短器脚本的请求时,例如:
$short = "http://myurl/api?api=MYAPI&format=text&url=http://myfullwebsite.com/email/quote.php?fullname=$fullname&address=$address&emailaddress=$emailaddress";
尽管在发送api请求后使用脚本末尾的echo函数将变量正确地放置在脚本中,但表明它们已正确插入,如下所示:
http://myurl/api?api=MYAPI&format=text&url=http://myfullwebsite.com/email/quote.php?fullname=Dan Smith&address=12 Main Street, London&emailaddress=dan@smith.com
但是,如果我从脚本中单击提供给我的缩短的URL,我只会在浏览器中看到以下URL字符串:
http://myfullwebsite.com/email/quote.php?fullname=Dan
似乎一旦有空格,或者甚至没有第二个名称(例如Dan Smith),并且只有Dan是可用名称,它甚至都不会应用第二个&符号。
我尝试使用urlecode()
但仍然没有任何乐趣,并且最近三天我一直在拔头发!
作为一个初学者,尝试达到最终结果有些困难,而且似乎无法实现,因此,如果可以的话,我将不胜感激,也许我会缺少一些简单的东西?
我曾经考虑过要从一组变量数组构建url查询,但是作为一个新手,我尝试了一种方法并失败了,所以不确定我是否做错了。
这是我完整的api代码,我在SESSION
和GET
都尝试过,但这不是问题,因为最终结果会在其中带有变量的情况下回显到浏览器中。仅当您遵循缩短的url链接时,您才会看到它们是失踪。
<?php
session_start();
$fullname = htmlspecialchars($_GET["fullname"]);
$address = htmlspecialchars($_GET["address"]);
$postcode = htmlspecialchars($_GET["postcode"]);
$emailaddress = htmlspecialchars($_GET["emailaddress"]);
$short = "http://myurl/api?api=MYAPI&format=text&url=http://ukhomesurveys.co.uk/email/quote.php?fullname=$fullname&address=$address&emailaddress=$emailaddress";
echo $short;
// Using Plain Text Response
$api_url = $short;
$res= @file_get_contents($api_url);
if($res){
echo $res;
}
?>
希望我能涵盖所有内容,并希望我不要混淆任何人。 谢谢。
我认为这里的不错选择是使用base64对查询进行编码,然后将其传递给缩短器。 在您的http://myfullwebsite.com/email/quote.php中,您只需解码查询并使用它即可。 标准的PHP函数是base64_encode和base64_decode。
您是否尝试使用rawurlencode编码URI?
$url = rawurlencode('http://myfullwebsite.com/email/quote.php?fullname=Dan Smith&address=12 Main Street, London&emailaddress=dan@smith.com');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.