此代码在行Parse error: syntax error, unexpected T_STRING
处提供解析错误$gender=$user['gender'];
.....这段代码中有错误...需要帮助.....谢谢
<?php
require_once 'config/functions.php';
session_start();
$user=$_SESSION['google_data'];
if(!empty($user)){
$email = $user['email'];
$fname = $user['given_name'];
$lname = $user['family_name'];
$gender=$user['gender'];
$dob = $user['birthday'];
$location = '';
$picture = $user['picture'];
$uid = $user['id'];
$ousername = '';
$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;
} else {
# For testing purposes, if there was an error, let's kill the script
die("There was an error.");
}
}
?>
答案 0 :(得分:1)
这一行可能是问题所在:
} } else {
答案 1 :(得分:1)
你需要删除最后一个额外的}
。
所以最后一行将是。
} else {
# For testing purposes, if there was an error, let's kill the script
die("There was an error.");
}
<强> CompleteCode 强>
<?php
require_once 'config/functions.php';
session_start();
$user=$_SESSION['google_data'];
if(!empty($user))
{
$email = $user['email'];
$fname = $user['given_name'];
$lname = $user['family_name'];
$gender=$user['gender'];
$dob = $user['birthday'];
$location = '';
$picture = $user['picture'];
$uid = $user['id'];
$ousername = '';
$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;
}
}
else
{
die("There was an error.");
}
?>
答案 2 :(得分:0)
请像这样使用
$gender = isset( $user['gender'] ) ? $user['gender'] : '' ;