从另一个文件调用函数后,Web应用程序停止运行代码

时间:2016-03-30 23:22:55

标签: php curl

我的网络应用尝试从其他文件执行功能时停止。我使用include_once来包含函数所在的文件。我也很确定路径是正确的。 (如果有任何方式检查让我知道)。我尝试使用的函数是在class.connections.php中编写的。另外你可以看到我回应2测试。只有第一个显示。

Invite.php

global $page_array ;
global $current_user ;

include_once(DITC_PATH."/class.friends.php");
include_once(DITC_PATH."/class.connections.php");

$process_status = $current_user->process_hotmail_contacts ;

global $page_array ;

if($page_array['url']['3'] == 'hotmail'){
    $process_source = 'hotmail' ;
};

if($_GET['code']){

    echo "Test 1 - ";

    $access_token_json = get_hotmail_access_token();

    echo "Test 2 - ";

    if($access_token_json){

        echo 'test';

        update_user_meta($current_user->ID, 'hotmail_access_token', $access_token_json);

        $taskurl = "/tasks";

        $data = array();
        $data['type'] = 'process_hotmail_contacts';
        $data['lang'] = get_site_language();
        $data['access_token'] = $access_token_json ;
        $data['user_id'] = $current_user->ID ;

        $options = array();

        add_task($taskurl, $data, $options);

        $process_status = 'busy' ;
        $process_source = 'hotmail' ;
    };
}

$ditc_title = _t("Invite connections") ;
get_header(); 

在class.connections中的功能

function get_hotmail_access_token(){

   global $hotmail_creds;

   $fields=array(
      'code'=>  urlencode($hotmail_creds['auth_code']),
      'client_id'=>  urlencode($hotmail_creds['client_id']),
      'client_secret'=>  urlencode($hotmail_creds['client_secret']),
      'redirect_uri'=>  urlencode($hotmail_creds['redirect_uri']),
      'grant_type'=>  urlencode('authorization_code')
   );

   $post = '';

   foreach($fields as $key=>$value) { $post .= $key.'='.$value.'&'; }
   $post = rtrim($post,'&');
   $curl = curl_init();
   curl_setopt($curl, CURLOPT_URL,'https://login.live.com/oauth20_token.srf');
   curl_setopt($curl, CURLOPT_POST,5);
   curl_setopt($curl, CURLOPT_POSTFIELDS,$post);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
   $result = curl_exec($curl);
   curl_close($curl);

   $response =  json_decode($result);
   $access_token_json = $response->access_token;

   return $access_token_json;

};

0 个答案:

没有答案