在PHP会话中存储facebook个人资料图片URL


Storing facebook profile picture URL in PHP session

我正在使用facebookjavascript SDK登录我的网站。点击登录按钮后,我将使用ajax将facebook名称和个人资料图片URL发送到PHP,并将名称存储在数据库中,并将个人资料图片的URL和名称分配给会话变量。当我将这个会话变量传递到我网站的个人资料页面时,我得到了正确的facebook名称,但个人资料图片URL已损坏。我只得到URL的一半。"&"旁边的所有内容URL中缺少符号。这是我应该得到的原始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进行发送时,链接在中间的某个位置断开。我哪里错了?这是我的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;
  });
}`

使用encodeURIComponent对fbphoto进行编码,然后http://php.net/manual/en/function.urldecode.php在PHP脚本中,当将值回显到浏览器时。

var datastring = 'fbid1=' +fbid+ '&fbname1=' +fbname+ '&fbemail1=' +fbemail+ '&fbphoto1=' +encodeURIComponent(fbphoto);

和在PHP 中

$photourl = urldecode($photourl);
echo $photourl;