1

ユーザーのサインインにGoogle auth2を使用しています。ユーザー情報を取得して、ユーザーがデータベースに存在しない場合はデータベースに保存しています...以下はコードで、ここでエラーを確認できます。dooperation() 関数を削除すると、エラーは発生しません....functions.php には「User」という名前のクラスが含まれています。ここで、ユーザーが存在するかどうかを確認し、存在しない場合は行を追加します..各行でエラーが発生しますdooperation() 関数...ここで何が問題なのか、また私が何か間違ったことをしているかどうか教えてください....ありがとう

<?php

require_once 'src/apiClient.php';
require_once 'src/contrib/apiOauth2Service.php';
require_once 'config/functions.php';
session_start();

$client = new apiClient();
$client->setApplicationName("Google Account Login");
$oauth2 = new apiOauth2Service($client);

if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

if (isset($_REQUEST['logout'])) {
 unset($_SESSION['token']);
 unset($_SESSION['google_data']); //Google session data unset
 $client->revokeToken();
 header('Location: home.php');
 exit();
}
   function dooperation($user){
      $ret=false;
      $email = $user['email'];
      $fname = $user['given_name'];
      $lname = $user['family_name'];

      $gender=$user['gender'];
      $dob = $user['birthday'];
      $location = null;
      $picture = $user['picture'];
      $uid = $user['id'];
      $ousername = null;
      $link = $user['link'];
           $provider = 'google';
           $verified = $user['verified_email'];

          $gen=0;
          if($gender == 'male'){$gen=1;} else{$gen=0;}
          $new_dob = date( "Y-m-d H:i:s", strtotime($dob) );

          $userObj = new User();
          $userdata = $userObj->checkUser($email,$fname,$lname,$gen,$new_dob,$location,$picture,$uid,$ousername,$link,$provider,$new_verified); 
          if(!empty($userdata)){         
            $_SESSION['id'] = $userdata['user_id'];
            $_SESSION['oauth_id'] = $userdata['user_oauth_id'];
            $_SESSION['username'] = $userdata['user_oauth_username'];
            $_SESSION['picture'] = $userdata['picture'];            
            $_SESSION['link'] = $userdata['link'];
            $_SESSION['fname'] = $userdata['user_fname'];
            $_SESSION['lname'] = $userdata['user_lname'];
            $_SESSION['gender'] = $userdata['user_gender'];
            $_SESSION['email'] = $userdata['user_email'];
            $_SESSION['oauth_provider'] = $userdata['user_oauth_provider'];             
            $_SESSION['oauth_id'] = $uid;
            $ret= true;
         }
         } else {
            # For testing purposes, if there was an error, let's kill the script
            die("There was an error.");
            $ret=false;
        }
       return $ret;
 }

 if ($client->getAccessToken()) {

 $user = $oauth2->userinfo->get();
 //print_r($user);

 $val=dooperation($user);

 header("location: home.php");

// The access token may have been updated lazily.
$_SESSION['token'] = $client->getAccessToken();
} else {
  $authUrl = $client->createAuthUrl();
}
?>
<?php if(isset($personMarkup)): ?>
<?php print $personMarkup ?>
<?php endif ?>
<?php
   if(isset($authUrl)) {
    header("Location: $authUrl");
 }

 ?>
4

0 に答える 0