After researching for hours, no proper fix has been found by myself so far, thus here I am!
I'm currently working on a school project that uses a login.php validator file to check if the user filled in all inputs, etc. etc., and also to create sessions.
require "config.inc.php";
$query = ("SELECT username, password, active FROM *DATABASE* WHERE username='".$username."' AND password='".$password."' AND active='1'") or die(mysql_error());
$result = mysqli_query($mysqli, $query);
$match = mysqli_num_rows($result);
if($match > 0){
//Directing to account page
header("Location:account.php");
//User info search
$queryID = ("SELECT id FROM *DATABASE* WHERE username='".$username."' AND password='".$password."' AND active='1'") or die(mysql_error());
$resultID = mysqli_query($mysqli, $queryID);
$id = mysqli_fetch_assoc($resultID);
$queryNAME = ("SELECT name FROM *DATABASE* WHERE username='".$username."' AND password='".$password."' AND active='1'") or die(mysql_error());
$resultNAME = mysqli_query($mysqli, $queryNAME);
$naam = mysqli_fetch_assoc($resultNAME);
//Session user info
$_SESSION['id'] = $id;
$_SESSION['naam'] = $naam;
This is just a minor piece of the validator, but as you can see it redirects to the account page (This works fine), and should create sessions for the name and ID found in the database.
The account page then again receives and translates the sessions to variables with the following code;
//SESSIONS
require 'session.php'; //CHECKS IF SESSION IS VALID, IF NOT: RETURN TO HOME
//VARIABLES
if (isset($_SESSION['naam']) && isset($_SESSION['id']) && isset($_SESSION['username'])) {
print_r($_SESSION['naam']); //Debug purposes
print_r($_SESSION['id']);
print_r($_SESSION['username']);
$id = implode($_SESSION['id']); //Convert to String
$naam = implode($_SESSION['naam']);
$username = ($_SESSION['username']); //Already a string, this was a variable used in the POST form
var_dump($naam);
} else {
echo "No sessions"; //Debug purposes
}
When I echo the username on my account page, it displays the username perfectly fine, and I assume that's because username has always been a string to begin with.
Yet when I echo the naam variable, it displays "AdministratorAdministrator" even though the naam in the database is just Administrator.
This is my print_r result:
Array ( [0] => Administrator [name] => Administrator )
Array ( [0] => 23 [id] => 23 )
admin
string(26) "AdministratorAdministrator"
Any clues on how I can ensure that whenever I echo the naam variable, it shows just Administrator ONCE, and not twice? thanks!