I have tried all methods but still am not seeing a redirect to index.php as expected. I also added ob_start() but it doesn't work. Then I tried header('location:...'). It also didn't work. Then I tried to redirect using JavaScript but that also didn't work. Any suggestions ??
<html>
<head>    
<link rel ="stylesheet" href=css/style.css>
</head>
<body>
<?php
ob_start();
require('dbconnect.php');
require('loginservice.php');
session_start();
//if my form is submitted
if(isset($_POST['submit']))
 {
 $username=$_POST['username'];
 $password=$_POST['password'];
$query1= userIdentity($username,$password);
echo 'returning value deisplay';
  echo '\n' .$query1 . '\n'; 
  echo 'i am here';
  if($query1==1){
  //echo 'welcome dude';
  $_SESSION['username'] = $username;
   //    Redirect user to index.php
   //echo "<script type='text/javascript'>  window.location='index.php';      </script>";
 // header("Location: index.php");
   //e//cho 'heeeelo';
   echo "<script type='text/javascript'>window.location.href = 'index.php';  </script>";
        ob_flush();
        exit(0);       
      }
   // header("Location: index.php");
   else 
   {
   echo  " <div class='form'>
   <h3>Username/password is incorrent.</h3>
   <br/>click here to <a href='login.php'>Login</a></div>";
   } 
   //header("Location: index.php");
  }
  else {
 ?>
 <div class="form">
 <h1>Log In</h1>
 <form action="" method='post' name="login">
 <input type ="text" name="username" placeholder="username" required />
 <input type="password" name="password" placeholder="password" required />
 <input name="submit" type="submit" value="login" />
 </form>
 <p> Not registered yet ? <a href='register.php'>Register Here </a> </p>
 </div>
  <?php
  }
 ?>
 </body>
</html>
 
     
     
    