以下是我在Facebook TimeLine上传图片的下方代码,但我发现$ _SESSION变量在重定向表单facebook后没有保留商店值。
<?php
session_start();
require 'facebook.php';
echo $_SESSION['uploadimage'] = $_POST['img_url'];
echo $_SESSION['return_url'] = $_POST['return_url'];
//die(); if I remove comment from die() function then session variable echo
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
// Get User ID
$user = $facebook->getUser();
$_SESSION['id'] = $user;
$loginUrl = $facebook->getLoginUrl();
//$_SESSION['id'];
?>
<?php
// Login or logout url will be needed depending on current user state.
if (isset($_GET['upload'])) {
echo "yes";
if ($_SESSION['id']) {
$facebook->setFileUploadSupport(true);
$args = array(
'message' => 'by http://thecodedeveloper.com'
);
copy($_SESSION['uploadimage'], 'tmp/file.jpeg');
$args['image'] = '@' . realpath('tmp/file.jpeg');
$data = $facebook->api('/me/photos', 'post', $args);
unlink('tmp/file.jpeg');
//assigning users to tag and cordinates
$argstag = array(
'to' => $user
);
$argstag['x'] = 40;
$argstag['y'] = 40;
$datatag = $facebook->api('/' . $data['id'] . '/tags', 'post', $argstag);
// echo 'Success! Check your facebook wall now';
header("Location:" . $_SESSION['return_url']);
} else {
header('Location:' . $loginUrl . '&scope=user_photos,publish_stream');
}
}
?>
答案 0 :(得分:1)
在PHP代码之上添加 session_start();
。
<?php
session_start(); //<-- Here
require 'facebook.php';
答案 1 :(得分:0)
ob_start();
在session_start();
要求'facebook.php';
$ img_url = isset($ _ POST ['img_url'])?$ _ POST ['img_url']:'';
$ return_url = isset($ _ POST ['return_url'])?$ _ POST ['return_url']:'';
如果(!空($ img_url){
echo $ _SESSION ['uploadimage'] = $ img_url;
}
如果(!空($ return_url)){
echo $ _SESSION ['return_url'] = $ return_url;
}