I got an interesting error which says that headers were already sent through ob_end_flush(); when I run the below code. This is the exact error I am getting
Warning: Cannot modify header information - headers already sent by (output started at /export/home/ua/games/gamescripts/login_backend2.php:47) in /export/home/ua/games/gamescripts/login_backend2.php on line 57 should have redirected by now
line 47 is ob_end_flush();
Edit: Sorry I was a bit careless while pasting my code. I have now arranged it in a right format.
<?php
include_once('Services_JSON.php');
include 'connect.php';
include_once('functions.php');
error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);
$json = new Services_JSON();  
$username=  $_POST["username"];  
$password = $_POST["password"];  
$check=0;  
$query="SELECT * FROM `game_users` WHERE `username` LIKE  '$username'";  
$result = mysql_query($query)  
or  
 die("<br>Query Error: ".mysql_error());  
while($row = mysql_fetch_row($result))  
{  
    $user = $row[2];  
    $pass = $row[3];  
    $name = $row[1];  
        if($username == $user )  
        {  
            if($password == $pass)  
            {    
                              $Day = 86400 + time(); // 1 Day    
                              $name= "name";  
                              $user= "user";  
                              $pass= "password";  
                              ob_start();  
                              //creating cookie for one day  
                              setcookie("username", $user, $Day);  
                              $cookiename = $name.$user;                    
                              setcookie("games", $cookiename, $Day);    
                              createSession($user,$cookiename);  
                              ob_end_flush();  
                              $data = array($user, $pass, $name);           
                              $check=1;  
                              flush();  
                              header("Location:                  http://www.uark.edu/ua/games/gamescripts/Game/Game.html");  
                              die('should have redirected by now');  
            }
        }
}
if($check==0)
{
    $data = array("failed", "failed", "failed","failed");
    echo $json->encode($data);
}
 ?>
 
    