Bonjour,
J'essaye de faire un formulaire de connexion avec php et Mysql et lors de la redirection avec la méthode "header('Location: *******');" je rencontre un problème :
Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd5/592/15964592/public_html/index.php:1) in /storage/ssd5/592/15964592/public_html/login.php on line 13
On m'a conseillé d'utiliser output buffering mais je ne sais pas comment l'utiliser sur mon code.
Je vous mets tout le code nécessaires pour pouvoir m'aider merci d'avance :
index.php :
config.php :Code PHP:
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bijouterie RUBY</title>
<!-- Icône haut de page -->
<link rel="icon" type="image/png" href="img/bijouterieRuby.png" />
<!-- CSS -->
<link href="css/style.css" rel="stylesheet">
<link href="css/style-responsive.css" rel="stylesheet">
<!-- CSS image gallery -->
<link href="css/lightbox.min.css" type="text/css" rel="stylesheet">
<!-- Police texte -->
<link rel ="preconnect" href ="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Spartan:wght@300&display=swap" rel="stylesheet">
<!-- JS image gallery -->
<script src="script/lightbox-plus-jquery.min.js"></script>
<!-- Outil d'icônes -->
<script src="https://kit.fontawesome.com/0aa4bbfaa0.js"></script>
<!-- CDN Jquery -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<!-- Scripts -->
<script src="script/sliderAccueil.js"></script>
<script src="script/scriptRetourHautDePage.js"></script>
<script src="script/scriptPageBijouxEtAccessoires.js"></script>
</head>
<body>
<?php
include 'html/header.html';
include 'html/menu.html';
if(isset($_GET['page'])){
switch($_GET['page']){
case 'accueil' :
include 'html/accueil.html';
break;
case 'bijoux' :
include 'html/bijoux.html';
break;
case 'accessoires' :
include 'html/accessoires.html';
break;
case 'a-propos' :
include 'html/a-propos.html';
break;
case 'contact' :
include 'contact.php';
break;
case 'ml' :
include 'html/ml.html';
break;
case 'pc' :
include 'html/pc.html';
break;
case 'traitement' :
include 'traitement.php';
break;
case 'dashboard' :
include 'dashboard.php';
break;
case 'login' :
include 'login.php';
break;
default :
echo "erreur";
break;
}
}else{
include 'html/accueil.html';
}
include 'html/footer.html';
?>
</body>
</html>
formLogin.php :Code PHP:
<?php
$databaseHost = 'localhost';
$databaseName = 'id15964592_bij*********';
$databaseUsername = 'id15964592_*******';
$databasePassword = 'Jessi******';
$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName);
?>
login.php :Code HTML:<style> input[type=text], input[type=password] { width: 25%; padding: 10px 20px; margin: 5px 0; border: 1px solid black; } input[type=submit] { width: 10%; padding: 12px 20px; border: 1px solid #555; background-color: pink; color:white; } </style> <form action="" method="POST"> <label for="uname">Identifiant</label> <input type="text" name="uname" required=""><br><br> <label for="upassword">Mot de passe</label> <input type="password" name="upassword" required=""><br><br> <input type="submit" name="sub" value="Connexion"> <form>
dashboard.php (début du code) :Code PHP:
<?php
include "config.php";
include "formLogin.php";
if(isset($_POST['sub'])){
$uname = $_POST['uname'];
$upassword = $_POST['upassword'];
$res = mysqli_query($mysqli,"SELECT * FROM user WHERE uname='$uname'and upassword='$upassword'");
$result=mysqli_fetch_array($res);
if($result){
header('Location:index.php?page=login');
}else{
echo "Erreur";
}
}
?>
Code PHP:
<?php
header('Location:index.php?page=login');
exit();
//Compteur visites sur le site...
-----