会话变量被破坏连接到Android应用程序

I m building an android app in which users have a personal profile.I use php (through wamp) to connect to server. So I want to keep the username of each user for further actions that the user will do. I use in php SESSION variables but after a user is logged in and wants e.g to upload a file the session is destroyed. My php code:

login.php

//Retrieve the login details via POST
session_start();
$username = $_POST['username'];
$password = $_POST['pass']; 

$con = mysql_connect("localhost","root","");
mysql_select_db("mobiledb1", $con);


$query = mysql_query("SELECT * FROM user1 WHERE username='$username' 
AND pass='$password'");
$num = mysql_num_rows($query);

if($num == 1){

while ($list=mysql_fetch_array($query)){

    $output=$list;
    $_SESSION['name'] = $output['username'];

    echo json_encode($output);

}

mysql_close();


}

?>

base.php

<?php
session_start();
$uname=$_SESSION['name'];
$base=$_POST['file'];

$con = mysql_connect("localhost","root","");
mysql_select_db("mobiledb1", $con);

$query=mysql_query("insert into pic (file,username) VALUES ('".$base."' 
, '".$uname."')");
$query1=mysql_query($query);

if ($query1="")
     {echo "unsuccessfull";
          }
          else
        {
     echo"successfull";
       }
?>

When the base.php file is called the session is destroyed (I guess because there is no header in index.php). But I can t set a header in index.php bacause it' s called from the java code. Can you provide me a solution for maintainig username variable??I' m new in android coding so any help would be appreciated!