I am using this code to login on Instagram API, but in some servers this code runs correctly, in other servers I can't get the instagram data. Who knows why?
<?php
require 'instagram.class.php';
require 'instagram.config.php';
// Receive OAuth code parameter
$code = $_GET['code'];
// Check whether the user has granted access
if (true === isset($code)) {
// Receive OAuth token object
$data = $instagram->getOAuthToken($code );
if(empty($data->user->username))
{
echo "1";
}
else
{
session_start();
$_SESSION['userdetails']=$data;
echo $user=$data->user->username;
echo $fullname=$data->user->full_name;
echo $bio=$data->user->bio;
echo $website=$data->user->website;
echo $id=$data->user->id;
echo $token=$data->access_token;
}
}
else
{
// Check whether an error occurred
if (true === isset($_GET['error']))
{
echo 'An error occurred: '.$_GET['error_description'];
}
}
?>
If you create session on a server, you cannot get it on other servers. You need to use sticky sessions. My suggesiton is installing memcache on one of your servers. You can see howto install here . After installation, let say your memcache server path is localhost:11211
. You can configure your php to say that save your session in this memcache server instead of per server memory. You need following simple conf in your php.ini
,
session.save_handler = memcache
session.save_path = "tcp://localhost:11211"
When you set any session, it will be created on this memcache server, and you can get it from any server. This settings mus be applied to all your servers. You need to give server name for session.save_path
in all servers. Since, there is only one memcache server
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.