如何阻止人们访问此页面?

nam*_*ami 1 php facebook facebook-graph-api

我有以下代码,允许我向当前登录的用户Facebook墙发布消息:

<?php
    error_reporting( E_ALL | E_STRICT );
    ini_set('display_errors', 1);

    session_start();

    require("facebook.php");

    $facebook = new Facebook(array(
        'appId'  => 'app_id_here',
        'secret' => 'secret_here',
        'cookie' => true
    ));

    $session = $facebook->getSession();

    if( !empty( $session ) ) {

        try {

            $uid = $facebook->getUser();
            $user = $facebook->api('/me');

            $api_call = array( 
                'method' => 'users.hasAppPermission', 
                'uid' => $uid, 
                'ext_perm' => 'publish_stream' 
            ); 

            $can_post = $facebook->api($api_call); 

            if( $can_post ) { 

                $facebook->api('/'.$uid.'/feed', 'post', array('message' => 'post some message here')); 
                echo 'Posted! Then redirect to an appropriate page.'; 

            } else { 

                $url = $facebook->getLoginUrl(array(  
                    'req_perms' => 'publish_stream'  
                ));  

                header("Location: {$url}");  
                exit;

            } 

        } catch ( Exception $e ) {

            echo $e;
            exit;

        }

    } else {

        $url = $facebook->getLoginUrl(array(  
            'req_perms' => 'publish_stream'  
        ));

        header("Location: {$url}");

    }
?>
Run Code Online (Sandbox Code Playgroud)

我需要在我的网站上的多个位置使用此代码,并且需要不断更改正在发布的消息.所以我认为我应该使用url查询字符串将消息发送到上面的代码.即

header("Location:post_message.php?message =".$ some_message_here);

但这意味着任何弄清楚网址的人都可以开始发布随机消息吗?即

这里有http://mysite.com/post_message.php?message=some留言

如何在我需要的所有页面中使用上面的代码,传递一个字符串以便发布消息,但是阻止用户导航到页面发布随机消息?

Que*_*tin 7

  1. 将文件放在webroot之外
  2. 将代码包装在函数中
  3. 如果要使用它,请包含它并调用该函数.