0
Good evening, I’m implementing a very basic Facebook login system on my site, the system should capture the basic data (id, name and email) of the user and save in a table and that’s where I’m having difficulties, I already ran many forums on the internet and tested various codes, but nothing is working.
UPDATING
"I solved" the problem by inserting Function.php data into fbconfig.php, probably the code should be very heavy, but for now it worked:
fbcongig.php
<?php
session_start();
// added in v4.0.0
require_once 'autoload.php';
require 'dbconfig.php'; // Conexão com o Banco
...
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
/* ---- header location after session ----*/
if ($fbid>"1"){
$consulta = "SELECT Fuid FROM Users WHERE Fuid='".$fbid."'";
$check = mysqli_query($con,$consulta);
$numeros = mysqli_num_rows ($check);
if ($numeros <= 0){
$query = "INSERT INTO Users (Fuid,Ffname,Femail) VALUES";
$query .= "('".$fbid."','".$fbfullname."','".$femail."')";
$inserir = mysqli_query($con,$query) or die(mysql_error($con));
}
}
//checkuser($fbid,$fbfullname,$femail);
header("Location: index.php");
} else {
$loginUrl = $helper->getLoginUrl(array('scope' => 'email, public_profile,user_friends'));
header("Location: ".$loginUrl);
}
?>
Are you sure you should use
exit
in functioncheckuser
when you find a record in the table? And why the functionmysqli_query
, in instructioninsert
does not have the reference to the connection with the bank$con
? Moreover, the function parametersmysqli_query
not in orderconnection, query
, guymysqli_query($con, $query)
?– Woss
No, I’m still studying about... Exit() was the best I had thought and I already understood that it was not such a good idea, I’m modifying the code, but still with a lot of difficulty
– Michel Fernandes
You can do
if ($numeros <= 0) { ...}
and eliminate theelse
, since if the condition by positive, no code is executed.– Woss
This solved the duplicate problem, but the data is not being entered in the table, it is returning error in this stretch
$sql = "INSERT INTO Users ('Fuid','Ffname','Femail') VALUES ('".$fbid."','".$fbfullname."','".$femail."')";
mysqli_query($con,$sql) or die('Erro ao Cadastrar');
– Michel Fernandes
And what’s the mistake?
– Woss
Fixing, the error is not in the code I listed, the error is this one:
[03-Feb-2017 01:47:42 UTC] PHP Notice: Undefined index: FBID in /home/profissa/public_html/teste/index.php on line 12
– Michel Fernandes
To be more Xto, line 12 is now if ($numbers <= 0){`
– Michel Fernandes
Undefined index references some array...
– Rodrigo Jarouche
Note that the error is happening on line 12 of
index.php
, not offunction.php
. See what’s on that line.– Woss
In the index.php file line 12 has this code
<?php if ($_SESSION['FBID']): ?>
That just receives the variable and displays on the screen, I’m updating the question with all the code. When I try to login with an account already inserted in the bd, the information usually appears on the screen, but if I use an account that is not in the bd, it returns the "Error when Registering" message in the browser. Since fbconfig.php redirects to index,php, the registration error might not be sending the data to the index, generating the Undefined error?– Michel Fernandes
Try to do on this line
if (isset($_SESSION["FBID"]))
– Woss
I tried the isset here, the error remains the Undefined above. As I said, when I log in using an account that is already in the comic book, everything works correctly: The data is displayed on the screen and is not being duplicated on the server, the error is only appearing when I try to log in with an account that is not in the comic book... "Error while Registering" (and the url is in "fbconfig.php?code=Aqalflyywz..."), in the system log appears the same error as Undefined
– Michel Fernandes
I updated the above question, found a "solution", but still don’t know what could be causing the error. Now I’ll try to find a way to better fix that code
– Michel Fernandes
Edit your question and post only the current codes, it is already very messy.
– Woss
I edited the question, I believe that, for now, the problem is solved , I’m studying on how to optimize this code.
– Michel Fernandes