hybridAuthLib库中的问题,在生产中提供错误500

时间:2016-04-04 11:07:12

标签: php curl hybridauth

hybridAuthLib库完全适用于localhost,但不适用于live error 500

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class HAuth extends CI_Controller {

public function __construct()
{       
    // Constructor to auto-load HybridAuthLib
    parent::__construct(); //echo 'doinng insdie'; 
    $this->load->library('hybridAuthLib');
    //echo 'After loading lib';
    //echo "hybridauthlib";
}

public function index()
{           
    // Send to the view all permitted services as a user profile if authenticated
    $login_data['providers'] = $this->hybridauthlib->getProviders();
    foreach($login_data['providers'] as $provider=>$d) {
        if ($d['connected'] == 1) {
            $login_data['providers'][$provider]['user_profile'] = $this->hybridauthlib->authenticate($provider)->getUserProfile();
        }
    }

    $this->load->view('hauth/home', $login_data);
}

/*public function login($provider)
{
    log_message('debug', "controllers.HAuth.login($provider) called");

    try
    {
        log_message('debug', 'controllers.HAuth.login: loading HybridAuthLib');
        $this->load->library('HybridAuthLib');

        if ($this->hybridauthlib->providerEnabled($provider))
        {   
            log_message('debug', "controllers.HAuth.login: service $provider enabled, trying to authenticate.");
            $service = $this->hybridauthlib->authenticate($provider);

            if ($service->isUserConnected())
            {
                log_message('debug', 'controller.HAuth.login: user authenticated.');

                $user_profile = $service->getUserProfile();

                log_message('info', 'controllers.HAuth.login: user profile:'.PHP_EOL.print_r($user_profile, TRUE));

                $data['user_profile'] = $user_profile;
                header("Location:../");
                // $this->load->view('hauth/done',$data);
            }
            else // Cannot authenticate user
            {
                show_error('Cannot authenticate user');
            }
        }
        else // This service is not enabled.
        {
            log_message('error', 'controllers.HAuth.login: This provider is not enabled ('.$provider.')');
            show_404($_SERVER['REQUEST_URI']);
        }
    }
    catch(Exception $e)
    {
        $error = 'Unexpected error';
        switch($e->getCode())
        {
            case 0 : $error = 'Unspecified error.'; break;
            case 1 : $error = 'Hybriauth configuration error.'; break;
            case 2 : $error = 'Provider not properly configured.'; break;
            case 3 : $error = 'Unknown or disabled provider.'; break;
            case 4 : $error = 'Missing provider application credentials.'; break;
            case 5 : log_message('debug', 'controllers.HAuth.login: Authentification failed. The user has canceled the authentication or the provider refused the connection.');
                     //redirect();
                     if (isset($service))
                     {
                        log_message('debug', 'controllers.HAuth.login: logging out from service.');
                        $service->logout();
                     }
                     show_error('User has cancelled the authentication or the provider refused the connection.');
                     break;
            case 6 : $error = 'User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.';
                     break;
            case 7 : $error = 'User not connected to the provider.';
                     break;
        }

        if (isset($service))
        {
            $service->logout();
        }

        log_message('error', 'controllers.HAuth.login: '.$error);
        show_error('Error authenticating user.');
    }
}*/
public function login($provider) 
{   
    log_message('debug', "controllers.HAuth.login($provider) called");

    try
    {
        log_message('debug', 'controllers.HAuth.login: loading HybridAuthLib');
        $this->load->library('HybridAuthLib');

        if ($this->hybridauthlib->providerEnabled($provider))
        {   
            log_message('debug', "controllers.HAuth.login: service $provider enabled, trying to authenticate.");
            $service = $this->hybridauthlib->authenticate($provider);

            if ($service->isUserConnected())
            {
                log_message('debug', 'controller.HAuth.login: user authenticated.');

                $user_profile = $service->getUserProfile();

                log_message('info', 'controllers.HAuth.login: user profile:'.PHP_EOL.print_r($user_profile, TRUE));

                $data['user_profile'] = $user_profile;
                if($provider=='Facebook')
                {
                    $query = $this->db->query("SELECT * FROM  `user`  WHERE  fbid='".$data['user_profile']->identifier."'");
                    if ($query->num_rows() <=0)
                    {   
                        $data_array = array(
                       'fbid' => $data['user_profile']->identifier ,
                       'username' => $data['user_profile']->displayName
                        );
                        $this->db->insert('user', $data_array); 
                    }
                    $_SESSION['login']="Facebook";
                     $_SESSION['username']=$data['user_profile']->displayName; 
                //   var_dump($_SESSION['username']);
                     $this->load->view('home/home_view',$data);

                }
                if($provider=='Google')
                {
                     $query = $this->db->query("SELECT * FROM  `user`  WHERE  gid='".$data['user_profile']->identifier."'");
                    if ($query->num_rows() <=0)
                    {   
                        $data_array = array(
                       'gid' => $data['user_profile']->identifier ,
                       'username' => $data['user_profile']->displayName
                        );

                        $this->db->insert('user', $data_array); 
                    }
                    $_SESSION['login']="Google";
                    $_SESSION['username']=$data['user_profile']->displayName; 
                  //  var_dump($data); exit;
                    $this->load->view('home/home_view',$data);

                }
                if($provider=='Twitter')
                {
                    $query = $this->db->query("SELECT * FROM  `user`  WHERE  twid='".$data['user_profile']->identifier."'");
                    if ($query->num_rows() <=0)
                    {   
                        $data_array = array(
                       'twid' => $data['user_profile']->identifier ,
                       'username' => $data['user_profile']->displayName
                        );
                        $this->db->insert('user', $data_array); 
                    } 
                    $_SESSION['login']="Twitter";
                    $_SESSION['username']=$data['user_profile']->displayName; 
                   // var_dump($_SESSION['username']); 
                    $this->load->view('home/home_view',$data);


                }
                //header("Location:../../");
                $this->load->view('home/home_view',$data);
            }
            else // Cannot authenticate user
            {
                show_error('Cannot authenticate user');
            }
        }
        else // This service is not enabled.
        {
            log_message('error', 'controllers.HAuth.login: This provider is not enabled ('.$provider.')');
            show_404($_SERVER['REQUEST_URI']);
        }
    }
    catch(Exception $e)
    {
        $error = 'Unexpected error';
        switch($e->getCode())
        {
            case 0 : $error = 'Unspecified error.'; break;
            case 1 : $error = 'Hybriauth configuration error.'; break;
            case 2 : $error = 'Provider not properly configured.'; break;
            case 3 : $error = 'Unknown or disabled provider.'; break;
            case 4 : $error = 'Missing provider application credentials.'; break;
            case 5 : log_message('debug', 'controllers.HAuth.login: Authentification failed. The user has canceled the authentication or the provider refused the connection.');
                     //redirect();
                     if (isset($service))
                     {
                        log_message('debug', 'controllers.HAuth.login: logging out from service.');
                        $service->logout();
                     }
                     show_error('User has cancelled the authentication or the provider refused the connection.');
                     break;
            case 6 : $error = 'User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.';
                     break;
            case 7 : $error = 'User not connected to the provider.';
                     break;
        }

        if (isset($service))
        {
            $service->logout();
        }

        log_message('error', 'controllers.HAuth.login: '.$error);
        show_error('Error authenticating user.');
    }
}

public function endpoint()
{

    log_message('debug', 'controllers.HAuth.endpoint called.');
    log_message('info', 'controllers.HAuth.endpoint: $_REQUEST: '.print_r($_REQUEST, TRUE));

    if ($_SERVER['REQUEST_METHOD'] === 'GET')
    {
        log_message('debug', 'controllers.HAuth.endpoint: the request method is GET, copying REQUEST array into GET array.');
        $_GET = $_REQUEST;
    }

    log_message('debug', 'controllers.HAuth.endpoint: loading the original HybridAuth endpoint script.');
    require_once APPPATH.'/third_party/hybridauth/index.php';

}
}

/* End of file hauth.php */
/* Location: ./application/controllers/hauth.php */

此代码在localhost上工作正常,但不知道为什么它不能在live服务器上运行。

我做了一些调试,代码代码运行到这一步:

//echo 'doing inside'; 

但是只要我包含文件库输出就不会出现。

我的服务器上的

启用了Curl。

  

Curl的配置:

     

AsynchDNS:是的

     

IDN:是的

     

SPENGO:是的

     

TLS-SRP:否。

这是实时服务器上的Curl配置。 此服务器卷曲设置是否有问题?任何帮助表示赞赏。

0 个答案:

没有答案