【问题标题】:Getting Errors when doing a $_post in php在 php 中执行 $_post 时出错
【发布时间】:2017-01-15 23:37:10
【问题描述】:

好的,我正在使用我在这里找到的一些代码:Read feed on a Facebook page without login in

代码如下

proxy.php

<?php
// always add this header to ensure the JSON is output in the correct format
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header('Content-Type: application/json; charset=utf-8'); 

$graphUrl = $_POST[graphUrl];
if ($graphUrl == "") {
    $graphUrl = "https://graph.facebook.com/684985445000793/posts";
}

//App Info, needed for Auth
$app_id = "MY-APP-ID";
$app_secret = "MY-APP-SECRET";

//retrieve auth token
$authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={$app_id}&client_secret={$app_secret}");

//Echo back json to read client side.
echo fetchUrl("{$graphUrl}?fields=ratings%2Cposts.limit(10)&access_token={$authToken}");

function fetchUrl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $retData = curl_exec($ch);
    curl_close($ch); 
    return $retData;
}
?>

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>FB reader</title>
</head>
<body>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            var timeout = 5000,
                load_error;

            load_error = function (jqXHR, textStatus, errorThrown) {
                if (errorThrown === "timeout") {
                    alert('Server bussy');
                } else {
                    alert('error: 404', textStatus + ": " + errorThrown);
                }
            };      

            $(document).ready(function() {
                console.log('Loading from Facebook...\n');

                $.ajax({
                    type: 'POST',
                    url: 'proxy.php',
                    data: {graphUrl: 'https://graph.facebook.com/684985445000793/'}, 
                    timeout:  timeout,
                    error: load_error,
                    success: function (rv) {
                        var data = rv.data,
                            len = data.length,
                            i,
                            out = '';
                        for (i = 0; i < len; i += 1) {
                            if (data[i].description) {
                                out += data[i].description + '\n\n';
                            }
                        }
                        console.log(out);
                    }
                });

            });
        });
    </script>
</body>
</html>

我的问题是

 type: 'POST',
                    url: 'proxy.php',
                    data: {graphUrl: 'https://graph.facebook.com/684985445000793/'}

在我的 proxy.php 的错误日志中似乎没有工作,我被告知:

PHP 注意:使用未定义的常量 graphUrl - 假定为 'graphUrl' 在第 8 行的 proxy.php 中

所以我假设数据:来自我的 index.html 没有被发送过来。

任何帮助或建议为什么我会收到此错误?

重要的是我在共享主机上....

【问题讨论】:

  • 对此要非常小心...您实际上拥有一个开放的代理,黑客可以利用该代理进行恶意目的。他们甚至不一定要以你为目标......到处都是爬取服务器的机器人,只是寻找这样的脚本。
  • 我意识到这个后记并删除了这个代码

标签: php post request error-log


【解决方案1】:

$graphUrl = $_POST[graphUrl]; 应该是$graphUrl = $_POST['graphUrl'];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多