0

I am using this command to post parameters to my server :

response = CustomHttpClient.executeHttpPost("http://192.168.1.102/liu/login.php", postParameters);

When I get a successful log in from the server, my Android application is set to request the members.php page in webview, but when this happens I am redirected to the log in page to log in again, this means that the session has been dropped somewhere, so how do I maintain the session between the two requests ?

Here is the code on server side login.php:

 if($numrow!=0)
{
    while($row = mysql_fetch_assoc($query))
    {
        $db_username = $row['username'];
        $db_password = $row['password'];
    }

    if($username==$db_username&&$password==$db_password)
    {

        $_SESSION['username']=$db_username;
        header("Location: members.php");
        members area</a>";


    }

and members.php:

if($_SESSION['username'])
 {
echo "1";
echo "the logged in session is :". $_SESSION['username'];
echo " You are logged in as: ".$_SESSION['username'];

echo "<p><a href='logout.php'>Click here to logout</a>";
  }

Now this code works when I log in from my pc browser but when I send the info from the Android application and get successful reply then request the members.php page it takes me back to the log in.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jay
  • 343
  • 5
  • 20
  • Session parameters reside on the server. You don't have to pass them to mantain the session opened. If a session is already closed, that session id will be invalid. – felixgaal May 27 '12 at 22:33

2 Answers2

2

you can refer to this link : Maintaining session in android ( application stay authenticated on the server side)

where i have mentioned how can we manage the session in android .

Try to take help from this.

Community
  • 1
  • 1
Dinesh Sharma
  • 11,533
  • 7
  • 42
  • 60
0

You should use GET parameters. PHP's format is

myscript.php?session_name=SESSION_ID

Be aware though, that this might not be enabled on your PHP server. Docs about passing the session ID

Bart Vangeneugden
  • 3,436
  • 4
  • 33
  • 52