Bonsoir,
Je tente d'utiliser la fonction session_start();. Malheureusement, j'ai un problème quand je change de page et que j'essaie de récupérer les informations dans mon $_SESSION il est vide. Je test depuis 1&1 la base de donnée aussi.
recup_infos.php :
Profile.php :
index.php :
résultat de profile.php : TEST2Array ( ) le tableau est vide ...
Merci
Je tente d'utiliser la fonction session_start();. Malheureusement, j'ai un problème quand je change de page et que j'essaie de récupérer les informations dans mon $_SESSION il est vide. Je test depuis 1&1 la base de donnée aussi.
recup_infos.php :
<?php
include 'entete.php';
/*------------------------------------connexion bdd----------------------------------------------------*/
$host_name = "xxx";
$database = "xxx";
$user_name = "xxx";
$password_base = "xxx";
$bdd = mysqli_connect($host_name, $user_name, $password_base, $database, 3306);
$db_selected = mysqli_select_db($bdd, $database);
if (mysqli_connect_errno())
ecrire_log( "Failed to connect to MySQL: " . mysqli_connect_error());
/*------------------------------------fin connexion bdd------------------------------------------------*/
/*----------------------------------------init variable super - global---------------------------------*/
/**************mode connexion**********************/
$email_connect = $_POST["email_connect"];
$password_connect = $_POST["password_connect"];
/**************fin mode connexion******************/
/*if (isset($_POST["log_out_submit"]))
{
ecrire_log('User submit log out');
session_destroy();
echo "<script type='text/javascript'>document.location.replace('index.php');</script>";
}*/
if (isset($_POST["email_connect"], $_POST["password_connect"]))
{
ecrire_log('the user tries to connect to it');
if ($result = mysqli_query($bdd, "SELECT password FROM t_user WHERE email = '$email_connect'"))
{
$rep = mysqli_fetch_assoc($result);
$_password = $rep['password'];
if (password_verify($password_connect, $_password))
{
session_start();
$_SESSION['email'] = $email_connect;
$_SESSION['password'] = $_password;
print_r("SESSION:");
print_r($_SESSION);
print("POST:");
print_r($_POST);
ecrire_log($_SESSION['email']);
ecrire_log('Email and Password match. User is connected');
echo "<script type='text/javascript'>document.location.replace('profile.php');</script>";
}
else
{
echo "<script type='text/javascript'>document.location.replace('index.php');</script>";
ecrire_log('Email and Password no match. User is no connected');
}
}
else
{
echo "<script type='text/javascript'>document.location.replace('index.php');</script>";
}
}
elseif ($result = mysqli_query($bdd, "INSERT INTO t_user(nom, prenom, age, password, email) VALUE ('$nom', '$prenom', '$age', '$mdphasher', '$email')"))
{
/**************mode inscription********************/
$nom = $_POST["nom"];
$prenom = $_POST["prenom"];
$age = $_POST["age"];
$password = $_POST["password"];
$email = $_POST["email"];
$mdphasher = password_hash($password, PASSWORD_DEFAULT);
/**********fin mode inscription********************/
mysqli_free_result($result);
/*-----------------------Envoi du mail de confirmation d'incription----------------------------------*/
$mail = $email; // Déclaration de l'adresse de destination.
if (!preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#", $mail)) // On filtre les serveurs qui rencontrent des bogues.
$passage_ligne = "\r\n";
else
$passage_ligne = "\n";
//=====Déclaration des messages au format texte et au format HTML.
$message_txt = "Bonjour, $nom $prenom \n voici l'e-mail de confirmation d'inscription.";
$message_html = "<html><head></head><body>Bonjour, $nom $prenom \n voici l'e-mail de confirmation.</body></html>";
//==========
//=====Création de la boundary
$boundary = "-----=".md5(rand());
//==========
//=====Définition du sujet.
$sujet = "Email de confirmation d'inscription";
//=========
//=====Création du header de l'e-mail.
$header = "From: \"xx\"<xxx>".$passage_ligne;
$header.= "Reply-to: \"xx\" <xxx>".$passage_ligne;
$header.= "MIME-Version: 1.0".$passage_ligne;
$header.= "Content-Type: multipart/alternative;".$passage_ligne." boundary=\"$boundary\"".$passage_ligne;
//==========
//=====Création du message.
$message = $passage_ligne."--".$boundary.$passage_ligne;
//=====Ajout du message au format texte.
$message.= "Content-Type: text/plain; charset=\"ISO-8859-1\"".$passage_ligne;
$message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
$message.= $passage_ligne.$message_txt.$passage_ligne;
//==========
$message.= $passage_ligne."--".$boundary.$passage_ligne;
//=====Ajout du message au format HTML
$message.= "Content-Type: text/html; charset=\"ISO-8859-1\"".$passage_ligne;
$message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
$message.= $passage_ligne.$message_html.$passage_ligne;
//==========
$message.= $passage_ligne."--".$boundary."--".$passage_ligne;
$message.= $passage_ligne."--".$boundary."--".$passage_ligne;
//==========
//=====Envoi de l'e-mail.
mail($mail,$sujet,$message,$header);
//==========
/*-------------------FIN Envoi du mail de confirmation d'incription----------------------------------*/
echo "<script type='text/javascript'>document.location.replace('index.php');</script>";
}
else
{
ecrire_log('impossible to insert in the existing email database');
echo "<script type='text/javascript'>document.location.replace('index.php');</script>";
}
mysqli_close($result);
?>
Profile.php :
<?php
session_start();
print_r("TEST2");
print_r($_SESSION);
include 'entete.php';
ecrire_log(email.$_SESSION['email']);
ecrire_log(pwd.$_SESSION['password']);
?>
index.php :
<!DOCTYPE html>
<html>
<?php include("entete.php"); ?>
<body>
<div class="container">
<?php include("menus.php"); ?>
</div>
<div class="row">
<div class="banniere"></div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-xs-12" >
<p style="margin-top: 2%;">
Bienvenue sur un site.
</p>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-6 col-md-6 col-xs-12">
<h1>Inscription</h1>
<p>Veuillez vous inscrire :</p>
<form method="post"name="inscription dans la base de donnée" action="recup_infos.php">
Nom: <input type="text" required="*" name="nom" /><br />
Prenom: <input type="text" required="*" name="prenom" /><br />
Email: <input type="email" required="*" name="email" /><br />
Age: <input type="number" required="*" min="1" max="105" name="age" /><br />
Password: <input type="password" required="*" name="password" />
<input type="submit" value="OK" />
</form>
</div>
<div class="col-lg-6 col-md-6 col-xs-12">
<h1>Connexion</h1>
<p>Veuillez vous connecter :</p>
<form method="post"name="inscription dans la base de donnée" action="recup_infos.php">
Email: <input type="text" required="*" name="email_connect" /><br />
Password: <input type="password" required="*" name="password_connect" />
<input type="submit" value="OK" />
</form>
</div>
</div></div>
<?php include("pieddepage.php"); ?>
</body>
</html>
résultat de profile.php : TEST2Array ( ) le tableau est vide ...
Merci