+ 2

Warning: Cannot modify header information - headers already sent by (output started at)

please fix this code wml chat.. help me if($admin=="6"){  header ('Location: ../tools/yourbooted.php?nimi=$nimi');}  $status=file('../text/bannames.txt');  for ($ri=0; $ri<count($status); $ri++)  {

8th Jan 2018, 7:27 AM
Weet Bokarachai
Weet Bokarachai - avatar
8 Answers
+ 2
You can't use header after a function that produces an output (ex. print, echo or raw html). Check the behavior of the code in the previous lines.
9th Jan 2018, 4:34 AM
AtoMX
AtoMX - avatar
+ 1
can u make a simple code for me sir?
9th Jan 2018, 8:59 PM
Weet Bokarachai
Weet Bokarachai - avatar
+ 1
To solve this problem it's necessary to check if the flow of the script produces some kind of output before header call. ex. print "test"; // <-- this print it's a problem if $admin = 6 if($admin=="6"){ header ('Location: ../tools/yourbooted.php?nimi=$nimi');} you should remove all print function before header. I also suggest you to put "exit" after "header" because this function sends the http header (redirect in this case) but doesn't stop the execution of the script. ex. if($admin=="6"){ header ('Location: ../tools/yourbooted.php?nimi=$nimi'); exit; } without exit you may have problems with print functions even after calling header.
9th Jan 2018, 10:27 PM
AtoMX
AtoMX - avatar
+ 1
bro. this my full code. can u fix it? <?php $status=file('../text/bannames.txt');  for ($ri=0; $ri<count($status); $ri++)  {  $resultban=rtrim($status[$ri]);  if($nimi=="$resultban"){$admin="5";}  }  if($admin=="5"){  echo '<meta http-equiv="Refresh" Content="0; URL=../tools/yourbanned.php">';}  $status=file('../text/bootnames.txt');  for ($ri=0; $ri<count($status); $ri++)  {  $resultboot=rtrim($status[$ri]);  if($nimi=="$resultboot"){$admin="6";}  }  if($admin=="6"){  echo '<meta http-equiv="Refresh" Content="0; URL=../tools/yourbooted.php">';}  $status=file('../text/bannames.txt');  for ($ri=0; $ri<count($status); $ri++)  {  $resultipban=rtrim($status[$ri]);  if($nimi=="$resultipban"){$admin="8";}  }  if($admin=="8"){  echo '<meta http-equiv="Refresh" Content="0; URL=../tools/yourbooted.php">';}  ?>
10th Jan 2018, 12:35 PM
Weet Bokarachai
Weet Bokarachai - avatar
+ 1
Try add "exit;" after each occurrence of header
10th Jan 2018, 10:03 PM
AtoMX
AtoMX - avatar
0
bro this my full code. can u fix it? <?php $status=file('../text/bannames.txt');  for ($ri=0; $ri<count($status); $ri++)  {  $resultban=rtrim($status[$ri]);  if($nimi=="$resultban"){$admin="5";}  }  if($admin=="5"){  header ('Location: ../tools/yourbanned.php');}  $status=file('../text/bootnames.txt');  for ($ri=0; $ri<count($status); $ri++)  {  $resultboot=rtrim($status[$ri]);  if($nimi=="$resultboot"){$admin="6";}  }  if($admin=="6"){  header ('Location: ../tools/yourbooted.php?nimi=$nimi');}  $status=file('../text/bannames.txt');  for ($ri=0; $ri<count($status); $ri++)  {  $resultipban=rtrim($status[$ri]);  if($nimi=="$resultipban"){$admin="8";}  }  if($admin=="8"){  header ('Location: ../tools/yourbanned.php');}  ?>
10th Jan 2018, 12:40 PM
Weet Bokarachai
Weet Bokarachai - avatar
0
make a example code bro. please.. i know u pro.. masta
10th Jan 2018, 11:13 PM
Weet Bokarachai
Weet Bokarachai - avatar
0
This is my version of your code without repetitions and superfluous variables. <?php $files = array( "bannames", "bootnames" ); for($i = 0; $i < count($files); $i++) { $status=file("../text/".$files[$i].'.txt');  for ($ri=0; $ri<count($status); $ri++) {  $result=rtrim($status[$ri]);  if($nimi==$result) { header("Location: ../tools/".($i == 0 ? "yourbanned.php" : "yourbooted.php?nimi=$nimi")); exit; } } } ?> I think you can fix your code simply by adding exit for each header, ex. if($admin==8) { header('Location: ../tools/yourbanned.php'); exit; }
14th Jan 2018, 1:37 PM
AtoMX
AtoMX - avatar