Page 1 sur 1
Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 00:51
par flexi2202
bonjour a tous
j ai un soucis avec fichier de connexion
après que l utilisateur a rentre ces instructions de connexion
j ai cette erreur
Notice: Undefined index: id in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 17
Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd3/226/15539226/public_html/nosignal/connexion.php:17) in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 19
j ai beau vérifier le fichier de connexion tout me semble bon pourtant
Code : Tout sélectionner
<?php
session_start();
// require_once 'config.php';
require_once 'config.php';
if(!empty($_POST['pseudo']) && !empty($_POST['password']))
{
$pseudo = htmlspecialchars($_POST['pseudo']);
$password = htmlspecialchars($_POST['password']);
$check = $bdd->prepare('SELECT pseudo, password FROM utilisateurs WHERE pseudo = ?');
$check->execute(array($pseudo));
$data = $check->fetch();
$row = $check->rowCount();
if($row == 1)
{
if(password_verify($password, $data['password']))
{
$_SESSION['user'] = array('id'=>$data['id'],'pseudo'=>$data['pseudo']) ;
$_SESSION['pseudo'] = $data['pseudo'];
header('Location:accueil-peche-perle.php?pseudo='.$_SESSION['pseudo']);
die();
}else{ header('Location:index.php?login_err=password'); die(); }
}else{ header('Location: index.php?login_err=already'); die(); }
}
?>
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 08:13
par Figuedi
je viens d'adapter ton code et il fonctionne parfaitement chez moi
ton erreur si il y a, est peut etre dans ton config.php ?
mais en tout cas ton code fonctionne chez moi
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();
// require_once 'config.php';
require('_connexion_pdo.php');
if(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
$check = $pdo->prepare('SELECT username, password FROM users WHERE username = ?');
$check->execute(array($username));
$data = $check->fetch();
$row = $check->rowCount();
if($row == 1)
{
if(password_verify($password, $data['password']))
{
$_SESSION['username'] = array('id'=>$data['id'],'username'=>$data['username']) ;
$_SESSION['username'] = $data['username'];
header('Location:accueil-peche-perle.php?username='.$_SESSION['username']);
die();
}else{ header('Location:index.php?login_err=password'); die(); }
}else{ header('Location: index.php?login_err=already'); die(); }
}
?>
<form method="POST" action="">
<table>
<tr>
<td align="right">
<label for="mail">Mail :</label>
</td>
<td>
<input type="text" placeholder="Votre pseudo" id="username" name="username" value="" required />
</td>
</tr>
<tr>
<td align="right">
<label for="mdp">Mot de passe :</label>
</td>
<td>
<input type="password" placeholder="Votre mot de passe" id="password" name="password" required/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<br />
<input type="submit" name="forminscription" value="Je me connecte" />
</td>
</tr>
</table>
</form>
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 09:24
par flexi2202
bonjour
un tres grand merci pour ce code
mais j ai ces erreurs
Warning: require(_connexion_pdo.php): failed to open stream: No such file or directory in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 8
Warning: require(_connexion_pdo.php): failed to open stream: No such file or directory in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 8
Fatal error: require(): Failed opening required '_connexion_pdo.php' (include_path='.:/usr/share/pear:/usr/share/php') in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 8
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 11:04
par @rthur
Bonjour,
Le message d'erreur est assez explicite normalement :
require(_connexion_pdo.php): failed to open stream: No such file or directory
Tu n'as pas de fichier appelé _connexion_pdo.php dans le répertoire public_html/nosignal/ (ou alors tu as un problème de droit en lecture dessus)
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 12:34
par flexi2202
merci pour la réponse et surtout l aide
j ai du apporter quelques modifications afin qu il puisse correspondre a ma table
par exemple modifier usename en pseudo
et users en utilisateurs pour la requête
et changer
l erreur a disparu mais je me retrouve avec une erreur sur cette ligne
Code : Tout sélectionner
$check = $pdo->prepare('SELECT pseudo, password FROM utilisateurs WHERE pseudo = ?');
qui est celle ci
Notice: Undefined variable: pdo in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 14
Fatal error: Uncaught Error: Call to a member function prepare() on null in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php:14 Stack trace: #0 {main} thrown in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 14
j ai donc modifier $pdo en $bdd et cela passe
mais de nouveau je me retrouve avec une erreur
Notice: Undefined index: id in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 23
Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd3/226/15539226/public_html/nosignal/connexion.php:23) in /storage/ssd3/226/15539226/public_html/nosignal/connexion.php on line 25
voici le nouveau fichier
Code : Tout sélectionner
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();
// require_once 'config.php';
require('config.php');
if(!empty($_POST['pseudo']) && !empty($_POST['password']))
{
$pseudo = htmlspecialchars($_POST['pseudo']);
$password = htmlspecialchars($_POST['password']);
$check = $bdd->prepare('SELECT pseudo, password FROM utilisateurs WHERE pseudo = ?');
$check->execute(array($pseudo));
$data = $check->fetch();
$row = $check->rowCount();
if($row == 1)
{
if(password_verify($password, $data['password']))
{
$_SESSION['pseudo'] = array('id'=>$data['id'],'pseudo'=>$data['pseudo']) ;
$_SESSION['pseudo'] = $data['pseudo'];
header('Location:accueil-peche-perle.php?pseudo='.$_SESSION['pseudo']);
die();
}else{ header('Location:index.php?login_err=password'); die(); }
}else{ header('Location: index.php?login_err=already'); die(); }
}
?>
<form method="POST" action="">
<table>
<tr>
<td align="right">
<label for="mail">Mail :</label>
</td>
<td>
<input type="text" placeholder="Votre pseudo" id="pseudo" name="pseudo" value="" required />
</td>
</tr>
<tr>
<td align="right">
<label for="mdp">Mot de passe :</label>
</td>
<td>
<input type="password" placeholder="Votre mot de passe" id="password" name="password" required/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<br />
<input type="submit" name="forminscription" value="Je me connecte" />
</td>
</tr>
</table>
</form>
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 17:06
par Figuedi
mais ce que je dis c'est que ton code est fonctionnel,ton problème n'est pas dans ce fichier d'après moi car il fonctionne sur mon environnement
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 17:12
par Figuedi
La ligne 23 étant celle là rajoutes y // pour la passer en commentaire, et vois ce qu'il se passe
}else{ header('Location:index.php?login_err=password'); die(); }
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 20:29
par or 1
$check = $bdd->prepare('SELECT pseudo, password FROM utilisateurs WHERE pseudo = ?');
$data = $check->fetch();
$_SESSION['pseudo'] = array('id'=>$data['id'],'pseudo'=>$data['pseudo']) ;
$data['pseudo'] fonctionne mais pas $data['id'] ce qui est logique.
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 20:39
par flexi2202
merci pour vos réponses
et surtout de l aide
peux tu me préciser ce que je devrais mettre a la place de $data['id']
stp or1
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 21:34
par Figuedi
tu rajoutes id dans ta requete
$check = $bdd->prepare('SELECT pseudo, id, password FROM utilisateurs WHERE pseudo = ?');
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 22:09
par flexi2202
super vraiment un tout tres grand merci Figuedi
c etait bien cela le soucis
mais comment expliquer que sur un autre hébergeur cela a fonctionner sans le id??
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 22:39
par or 1
tout dépend si les warnings sont affichés ou non dans la page.
$_SESSION['pseudo'] = array('id'=>$data['id'],'pseudo'=>$data['pseudo']) ;
$_SESSION['pseudo'] = $data['pseudo'];
la première ligne ne sert à rien, donc ce n'est pas grave si elle ne fonctionne pas.
Re: Warning: Cannot modify header information - headers already sent by
Posté : 13 avr. 2021, 22:49
par flexi2202
ah ok or 1
un grand merci pour l explication