Reputation: 99
I am using facebook javascript SDK for logging in my website. Once the sign in button is clicked, I am sending the facebook name and profile picture URL using ajax to PHP and storing the name in DataBase and assigning the profile picture URL and name to a session variable. When I pass this session variable to the profile page of my website, I get the facebook name correct but the profile picture URL is broken. I get only half of the URL. Everything next to the '&' symbol in the URL is missing. Here is the original URL I am supposed to get. I got this by displaying the image in the same page as the login screen
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
But I get this
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/v/t1.0-1/p200x200/9444_10203017119044199_1059615267418985652_n.jpg?oh=5d5c541aa8c7c99d7c5bf5ce9ec2e718
So the link gets broken somewhere in the middle while sending through ajax. Where did I go wrong? Here is my ajax and getPhoto
function
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;
});
}`
Upvotes: 0
Views: 426
Reputation: 4025
Encode fbphoto using encodeURIComponent and then http://php.net/manual/en/function.urldecode.php in the PHP script when echo-ing the value to the browser.
var datastring = 'fbid1=' +fbid+ '&fbname1=' +fbname+ '&fbemail1=' +fbemail+ '&fbphoto1=' +encodeURIComponent(fbphoto);
and in PHP
$photourl = urldecode($photourl);
echo $photourl;
Upvotes: 1