在PHP会话中存储Facebook个人资料图片URL
我正在使用Facebook的JavaScript SDK登录我的网站。点击登录按钮后,我将使用ajax的Facebook名称和个人资料图片URL发送给PHP,并将名称存储在DataBase中,并将个人资料图片URL和名称分配给会话变量。当我将此会话变量传递给我的网站的个人资料页面时,我获得了正确的Facebook名称,但个人资料图片网址已损坏。我只获得了一半的网址。网址中'&'符号旁边的所有内容均缺失。这是我应该得到的原始URL。我得到这个由作为登录屏幕在PHP会话中存储Facebook个人资料图片URL
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/v/t1.0-1/p200x200/9444_10203017119044199_1059615267418985652_n.jpg?oh=5d5c541aa8c7c99d7c5bf5ce9ec2e718&oe=54E265CB&__gda__=1420508157_9882b31d641e2b27ef486c2ee7c61ad0
在同一页面显示图像,但我得到这个
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/v/t1.0-1/p200x200/9444_10203017119044199_1059615267418985652_n.jpg?oh=5d5c541aa8c7c99d7c5bf5ce9ec2e718
所以链接获取中间的某个地方打破,而通过Ajax发送。我哪里做错了?这是我在PHP脚本Ajax和getPhoto
功能
function getUserInfo() {
FB.api('/me', function(response) {
var fbid = response.id;
var fbname = response.name;
var fbemail = response.email;
var datastring = 'fbid1=' +fbid+ '&fbname1=' +fbname+ '&fbemail1=' +fbemail+ '&fbphoto1=' +fbphoto;
$.ajax({
type: "POST",
url: "http://www.uniwink.com/landing/php_includes/fb_cred_store.php",
data:datastring,
cache:false,
success: function(data){
if(data == "success"){
window.open("profile.php","_self");
} else {
window.open("index.php","_self");
}
}
});
});
}
function getPhoto()
{
FB.api('/me/picture?type=large', function(response) {
window.fbphoto = response.data.url;
});
}`
编码fbphoto使用encodeURIComponent方法,然后http://php.net/manual/en/function.urldecode.php当回声-ING值到浏览器。
var datastring = 'fbid1=' +fbid+ '&fbname1=' +fbname+ '&fbemail1=' +fbemail+ '&fbphoto1=' +encodeURIComponent(fbphoto);
和PHP
$photourl = urldecode($photourl);
echo $photourl;
这工作就像一个魅力。谢谢 :) – Anbu369 2014-10-29 14:56:10