0

I am facing issue in google signup process. My site is in core php. a month before it was working, suddenly stopped.

When I click on "sign-in-with-google" button, It prompts me to select the email. When I select the select the email to proceed after this it's showing error.

Error:

Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in public_html/.../google-api-php-client-2.6.0/vendor/guzzlehttp/guzzle/src/ClientInterface.php on line 81

screenshot:

enter image description here https://prnt.sc/u24103

I searched a lot but didn't get any solution. I was using version 2.6.0, I tried to replace it with version 2.7, but no success.

Please help. Thanks

Here's my code

require_once('includes/config.php');

 require_once(DOCUMENT_ROOT . '/demo/tutor-student/google-api-php-client-2.6.0/vendor/autoload.php');

 define('GOOGLE_CLIENT_ID', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com');
 define('GOOGLE_CLIENT_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxx');
 define('GOOGLE_REDIRECT_URL', BASE_URL.'admin/my-account.php');


 $gClient = new Google_Client();

 $gClient->setApplicationName('Login to .com');
 $gClient->setClientId(GOOGLE_CLIENT_ID);
 $gClient->setClientSecret(GOOGLE_CLIENT_SECRET);
 $gClient->setRedirectUri(GOOGLE_REDIRECT_URL);
 $gClient->addScope('email');
 $gClient->addScope('profile');

 if(isset($_GET['code'])){ 

    $token = $gClient->fetchAccessTokenWithAuthCode($_GET['code']);

    if(!isset($token["error"])){

    $gClient->setAccessToken($token['access_token']);

    // getting profile information
    $google_oauth = new Google_Service_Oauth2($gClient);
    $google_account_info = $google_oauth->userinfo->get();

    // Storing data into database
    $oauth_uid = $google_account_info->id;
    $first_name = trim($google_account_info->givenName);
    $last_name = trim($google_account_info->familyName);
    $email = $google_account_info->email;
    $profile_pic = $google_account_info->picture;

    require_once(DOCUMENT_ROOT . '/demo/tutor-student/models/User.php');
    $user_obj = new User();

    
    $user_data = $user_obj->is_record_exist(['oauth_uid' => $oauth_uid, 'email' => $email,  'role_id'=> '3' ]);
    if(!empty($user_data)) {
        $_SESSION['id'] = $user_data['id'];
        $_SESSION['role'] = $user_data['role_name'];
        $_SESSION['role_id'] = $user_data['role_id'];
        $_SESSION['name'] = $user_data['first_name'];
        $_SESSION['last_name'] = $user_data['last_name'];
        $_SESSION['email'] = $user_data['email'];
        $_SESSION['is_login'] = true;
        header('Location: ' . filter_var(GOOGLE_REDIRECT_URL, FILTER_SANITIZE_URL)); 
        exit;
    } else {

        $data = [   'oauth_uid' => $oauth_uid,
                'first_name' => $first_name,
                'last_name' => $last_name,
                'email' => $email,
                'image' => $profile_pic, 
                'role_id' => 3 
            ];

        $last_id = $user_obj->save($data);
        if($last_id > 0 ){
            $getdata = ['id' => $last_id];
            $user_data = $user_obj->get_user($getdata);
            if(!empty($user_data)) {
                $_SESSION['id'] = $user_data['id'];
                $_SESSION['role'] = $user_data['role_name'];
                $_SESSION['role_id'] = $user_data['role_id'];
                $_SESSION['name'] = $user_data['first_name'];
                $_SESSION['last_name'] = $user_data['last_name'];
                $_SESSION['email'] = $user_data['email'];
                $_SESSION['is_login'] = true;
                header('Location: ' . filter_var(GOOGLE_REDIRECT_URL, FILTER_SANITIZE_URL)); 
                exit;
            }
        }

    }
}

}

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

0 Answers0