发送Facebook图片网址作为参数
问题描述:
Facebook image url for user profile looks like
https://scontent.xx.fbcdn.net/hprofile-xfa1/v/t1.0-1/c26.26.321.321/s50x50/1004031_160695494109373_202362495_n.jpg?oh=bc24275f3c0b63adcd7f2
I want to send this url in request to server
$FBImageUrl = "https://scontent.xx.fbcdn.net/hprofile-xfa1/v/t1.0-1/c26.26.321.321/s50x50/1004031_160695494109373_202362495_n.jpg?oh=bc24275f3c0b63adcd7f2";
$postString = "http://example.com/script.php?img_url=" . FBImageUrl;
But what will happen if this url have question mark inside?
用户个人资料的Facebook图片网址如下所示 p>
https: //scontent.xx.fbcdn.net/hprofile-xfa1/v/t1.0-1/c26.26.321.321/s50x50/1004031_160695494109373_202362495_n.jpg?oh=bc24275f3c0b63adcd7f2
PRE> \ n我想将此URL请求发送到服务器 p>
$ FBImageUrl =“https://scontent.xx.fbcdn.net/hprofile-xfa1/v/ t1.0-1 / c26.26.321.321 / s50x50 / 1004031_160695494109373_202362495_n.jpg?oh = bc24275f3c0b63adcd7f2“; $ postString =”http://example.com/script.php?img_url=“。 FBImageUrl; code> pre>
但是如果这个网址里面有问号会怎么样? p> div>
答
use urlencode()
$FBImageUrl = "https://scontent.xx.fbcdn.net/hprofile-xfa1/v/t1.0-1/c26.26.321.321/s50x50/1004031_160695494109373_202362495_n.jpg?oh=bc24275f3c0b63adcd7f2";
$postString = "http://example.com/script.php?img_url=".urlencode($FBImageUrl) ;
In your script.php
$img_url = urldecode($_GET['img_url']);
答
You can use base64_encode
& base64_decode
. Also for security reasons image URL wont be visible in the address bar.
$FBImageUrl = "https://scontent.xx.fbcdn.net/hprofile-xfa1/v/t1.0-1/c26.26.321.321/s50x50/1004031_160695494109373_202362495_n.jpg?oh=bc24275f3c0b63adcd7f2";
$base64Url = base64_encode($FBImageUrl);
$postString = "http://example.com/script.php?img_url=" . $base64Url;
Receiver you can decode it
$fbUrl = base64_decode($_GET['img_url']);