-1

this is warning. even it is NOT allowing me to open the page admin.php and error is ":

Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\rail\index.php:446) in

    <?php

    ob_start();

    error_reporting(E_ALL); 

here is warning in this line . where i have started the session

     session_start();
    include("db.php");
    if(isset($_POST['log']))
      {

   $user= $_POST['username'];
    $pass= md5($_POST['password']);

   $sql=mysql_query( "select * from reg where username= '$user' AND password='$pass' ") or die( mysql_error());
   $data=mysql_num_rows($sql);
      if ($data == 1) {
   while($row = mysql_fetch_array($sql)){ 

     $_SESSION['username']=$s1;
   echo '<script>window.location="admin.php"</script>';
         }
        }


      else {
        echo '<script type="text/javascript">';
          echo 'alert("Password Invalid!")';
         echo '</script>';

        }
       }
       ob_end_flush();
       ?>

enter image description here

2 Answers2

1

Try to use this may help you ,

 <?php
 session_start();
ob_start();
error_reporting(E_ALL); 
include("db.php");
include("redirect.php"); // the file which is stored redirect()   
 if(isset($_POST['log']))
  {

 $user= $_POST['username'];
 $pass= md5($_POST['password']);

  $sql=mysql_query( "select * from reg where username= '$user' AND password='$pass' ") or die( mysql_error());
  $data=mysql_num_rows($sql);
  if ($data == 1) {
    while($row = mysql_fetch_array($sql)){ 

 $_SESSION['username']=$s1;
 redirect('admin.php');            // HERE YOU NEED TO REPLACE THE FUNCTION
     }
    }
    else {
    echo '<script type="text/javascript">';
      echo 'alert("Password Invalid!")';
     echo '</script>';

    }
   }
   ob_end_flush();
   ?>

Avoid the ?> if there is not any html tags in your code

EDIT :

If the above did not helped you then try use the below function instead of header()

  function redirect($url) {
     if (!headers_sent()) {    
      header('Location: '.$url);
      exit;
  } else {  
    echo '<script type="text/javascript">';
    echo 'window.location.href="'.$url.'";';
    echo '</script>';
    echo '<noscript>';
    echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
    echo '</noscript>'; exit;
  }
}

Thanks to Rajat Singhal for the redirect()

Vishnu R Nair
  • 335
  • 2
  • 17
1

In a nut shell. There are many things which could cause this error/warning. Most of which are narrowed down to a piece of output being sent to the browser before starting a session. So with that in mind, check for output in your script.. this can be anything from a simple white space or text before initialising the session.

another common scenario for this warning to be presented is triggered by your files encoding. There can be something called UTF8-BOM which is a hidden character (s) which some editors might not pick up, providing you have set the wrong encoding for yor file. So in that case, the solution would be to double check the files encoding.

The error message is clear, it states index.PHP and around line 446 is roughly the cause for this warning. So check for things I've mentioned above on or before that line

Daryl Gill
  • 5,464
  • 9
  • 36
  • 69