我公司通過與下面的代碼的HTML表單張貼的字符串:
<html>
<body>
<form name="form" enctype="multipart/form-data" action="test.php" method="post">
<input name="message"
type="text" value=""><br/><br/>
<input type="submit" value="Upload"/><br/>
</form>
</body>
</html>
爲test.php的代碼如下:
<html>
<head xmlns:testapp="https://apps.facebook.com/testapp/ns#">
<title>Test App</title>
</head>
<body>
<?php
echo "1".$_POST["message"];
$string1 = $_POST["message"];
echo "2".$string1;
$app_id = "191622610935428";
$app_secret = "a9cdd876cdaf17b6454639b19d91f157";
$my_url = "http://www.thepropagator.com/facebook/worldcentric";
$og_url = "http://thepropagator.com/facebook/worldcentric/issue.php?name=".$string1;
$code = $_REQUEST["code"];
if(empty($code)) {
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=email,publish_actions";
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
$token_url="https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
// remove the @expires
$params = null;
parse_str($access_token, $params);
$access_token_updated = $params['access_token'];
$post_data = "issue=" . $og_url . "&access_token=" . $access_token_updated;
echo "post_data: " . $post_data . "<br/>";
// setup the POST
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/me/testapp:raise?issue');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
// execute the POST
$result = curl_exec ($ch);
if(curl_error($ch))
{
echo 'error:' . curl_error($ch) . "<br/>";
}
curl_close ($ch);
echo "return code= " . $result . "<br/>";
?>
<br>
</br>
</body>
</html>
當我打提交表單的回聲我在第一個代碼塊做展示發佈字符串作爲預期,但在某些時候,他們消失了,變量$ og_url失去的連接字符串。$字符串1。似乎在某個時候這個變量正在被擦除任何人都可以解釋爲什麼會發生這種情況?
生成PHP錯誤的唯一行是: $ access_token = file_get_contents($ token_url); 我很確定這個錯誤的唯一原因是因爲字符串$ og_url中的「name =」後沒有任何內容。
看來我的問題是由代碼行引起的。 echo(「top.location.href ='」。$ dialog_url。「'」);
但是我不確定爲什麼,我不能擺脫這一行。
這段代碼的語法是無效的,在那裏似乎有很多無稽之談,像'$ og_url.test'。激活錯誤報告('error_reporting(E_ALL); ini_set('display_errors',true);')並且一步步調試。 – deceze 2012-01-15 23:44:29
我已經刪除了你提到的那一行,並且查閱了error_log(查看代碼更改),但是在$ access_token = file_get_contents($ token_url)之前刪除了字符串變量$ string1的根本問題。似乎仍然在那裏。 – 2012-01-16 00:00:07