i'm trying to create a login/register system with PDO and sessions and a user can create his account and he ca access the Welcome page , but when logging out and trying to log back with working username and password , it sends me to a blank php page , i looked on the internet and a blank php page means syntax error which i can't find any. Btw i tried typing any username with any password and it stills sending me to a blank php page here's my code : Config.php
class config {
public static function connect()
{
$host = "localhost";
$username = "root";
$password = "";
$dbname = "logintest";
try{
$bdd = new PDO("mysql:host=$host;dbname=$dbname",$username,$password);
$bdd->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
}catch(PDOException $e)
{
echo "Connection échoué" . $e->getMessage();
}
return $bdd;
}
}
?>
My process.php (that's where i think the probleme is comming from :
session_start();
include_once("config.php");
if(isset($_POST['register']))
{
$bdd = config::connect();
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
if(insertDetails($bdd,$username,$email,$password))
{
$_SESSION['username'] = $username;
header("Location: profile.php");
}
}
if(isset($_POST['login']))
{
$bdd = config::connect();
$username = $_POST['username'];
$password = $_POST['password'];
if(checkLogin($bdd,$username,$password))
{
$_SESSION['username'] = $username;
header("Location: profile.php");
}
else{
echo "Le mot de passe ou le nom d'utilisateur sont incorrect";
}
}
function insertDetails($bdd,$username,$email,$password)
{
$query = $bdd->prepare("
INSERT INTO users (username,email,password)
VALUES(:username,:email,:password)
");
$query->bindParam(":username",$username);
$query->bindParam(":email",$email);
$query->bindParam(":password",$password);
return $query->execute();
}
function checkLogin($bdd,$username,$password)
{
$query = $bdd->prepare("
SELECT * From users WHERE username=:username AND password=:password
");
$query->bindParam(":username", $username);
$query->bindParam(":password", $password);
$query->execute();
// Check how many rows are returned
if ($query->rowCount() == 1)
{
return true;
}
else {
return false;
}
}
my profile.php :
session_start();
include_once("config.php");
echo "Bienvenue " . $_SESSION['username'] . " ";
echo "<a href='logout.php'>Se deconnecter</a>". " ";
echo "<a href='update.php'>Mettre a jour le profile</a>" . " ";
echo "<a href='delete.php'>Supprimer mon compte</a>". " ";
?>```
and my logout.php :
```<?php
session_destroy();
header("Location: index.html");
?>
Or here's the project i'm working on : https://github.com/AmrouHab/LoginRegister/tree/master/neptunetest
I'll take any help Thanks (Btw sorry for my bad english im french)