I'm trying to get users email addresses when they log in so I can they can be entered into my database and given a unique ID. I've managed to retrieve user display names and store them in the database using this code however its not working with the email address.
session_start();
if(property_exists($profile->profile,'displayName')){
$_SESSION['username'] = $profile->profile->displayName;
$_SESSION['email'] = $profile->profile->email;
$_SESSION['logged']="logged";
$username = $_SESSION['username'];
$email = $_SESSION['email'];
require_once("db_connect.php");
$query="SELECT email FROM users WHERE email = '$email'";
mysqli_select_db($db_server, $db_database);
$result=mysqli_query($db_server, $query);
if($result != $email){
$query = "INSERT INTO users (username, email) VALUES ('$username', '$email')";
mysqli_query($db_server, $query) or
die("Insert failed. ". mysqli_error($db_server));
}else{
echo "Login error.";
}
mysqli_free_result($result);
require_once("db_close.php");
header('location:home.php');
}else{
$_SESSION['username'] = '(Anonymous)';
$_SESSION['logged']="logged";
header('location:home.php');
}
Thanks for your help.
It sounds like it has to do with what information the providers share by default. I believe these steps should fix it:
Let me know if that works out for you!