please help me
Warning: Cannot modify header information - headers already sent in C:\xampp\htdocs\gauto-preview\gauto-preview\login(1).php on line 19

<?php
ob_start();
session_start();
require_once('connexion.php');
error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);
if(isset($_POST['login'])){
$username=$_POST['username'];
$motpasse=$_POST['motpasse'];
if($username&&$motpasse){
$query="SELECT*from user where username='$username' AND motpasse='$motpasse'";
$query_run=mysqli_query($conn,$query);
$rep = mysqli_fetch_assoc($query_run);
if($rep!=''){
$_SESSION['id_user'] = $rep['id_user'];}
$row=mysqli_num_rows($query_run);
if($row==1){
 flush();  
 header('Location: index(1).php'); 
 exit();

 //echo"<script type='text/javascript'>location.href='index(1).php';</script>";

//die('should have redirected by now');
}else{
echo "username ou password incorrect";
}                                                                         
}else{
echo "veuillez saisir tous les champs";
}
} 
?>

Recommended Answers

Try putting the header() before the flush()

Jump to Post

All 3 Replies

Try putting the header() before the flush()

commented: i tried but it's not working +0

i found the problem in securityuser.php when i removed it the header worked but i need this file to secure the other pages

<?php
ob_start();
session_start();
require_once('connexion.php');
error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);
if (!$_SESSION['username']) {
flush();    
header('Location:login(1).php');
exit();
//echo'<script >document.location.replace("login(1).php");</script>';
}
Notice: Undefined index: username in C:\xampp\htdocs\gauto-preview\gauto-preview\securityuser.php on line 7

Warning: Cannot modify header information - headers already sent in C:\xampp\htdocs\gauto-preview\gauto-preview\securityuser.php on line 9 #

So there are more php scripts than what you shared in your top post? That means we don't see the entire system and can't comment.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.