title: session handling in android while logging into the server side in php
body: <p>I  am trying to do the session handling process in android. 
  Here I have successfully logged into through android and now i waant to handle the session of the logged in user.
  this is my login_suer.java(android part)</p>
  
  <pre><code>package com.iwantnew.www;
  
  
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.http.NameValuePair;
  import org.apache.http.message.BasicNameValuePair;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.app.Activity;
  import android.app.ProgressDialog;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class login_user extends Activity{
      private ProgressDialog pDialog;
      JSONParser jsonParser = new JSONParser();
      EditText login_email;
      EditText login_password;
      Button signin;
      TextView error_msg;
  
      private static String url_create_signin= "http://10.0.2.2/android_iwant/login_user.php";
      // JSON Node names
              private static final String TAG_SUCCESS = "success";
              public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.user_form);
  
                  // Edit Text
                  login_email = (EditText) findViewById(R.id.login_email);
                  login_password = (EditText) findViewById(R.id.login_password);              
                  signin = (Button) findViewById(R.id.signin);
                  error_msg = (TextView) findViewById(R.id.error_msg);
  
                  signin.setOnClickListener(new View.OnClickListener() {
  
                      @Override
                      public void onClick(View view) {
                          // creating new product in background thread
                          new CheckLogin().execute();
                      }
                  });
              }
  
              class CheckLogin extends AsyncTask&lt;String, String, String&gt; {
                  /**
                   * Before starting background thread Show Progress Dialog
                   * */
                  @Override
                  protected void onPreExecute() {
                      super.onPreExecute();
                      pDialog = new ProgressDialog(login_user.this);
                      pDialog.setMessage("Signing in..");
                      pDialog.setIndeterminate(false);
                      pDialog.setCancelable(true);
                      pDialog.show();
                  }
                  /**
                   * Creating product
                   * */
                  protected String doInBackground(String... args) {
  
                      //Building Parameters
                      List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
                      params.add(new BasicNameValuePair("email",login_email.getText().toString()));
                      params.add(new BasicNameValuePair("password", login_password.getText().toString()));
  
                      // getting JSON Object
                      // Note that create product url accepts POST method
                      JSONObject json = jsonParser.makeHttpRequest(url_create_signin,
                              "POST", params);
  
                      // check log cat fro response
                      Log.d("Create Response", json.toString());
  
                      // check for success tag
                      try {
                          int success = json.getInt(TAG_SUCCESS);
  
                          if (success == 1) {
                              // successfully created users
                              Intent i = new Intent(getApplicationContext(), post_item.class);
                              startActivity(i);
  
                              // closing this screen
                              finish();
                          } else {
                              // failed to sign in
                              error_msg.setText("Incorrect username/password");
  
                          }
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
                      return null;
                  }
  
                  /**
                   * After completing background task Dismiss the progress dialog
                   * **/
                  protected void onPostExecute(String file_url) {
                      // dismiss the dialog once done
                      pDialog.dismiss();
                  }
  
              }
  
  
  }
  </code></pre>
  
  <p>now i need the idea to start session handling in this java file.
  and the code of the server side is below: ie login_user.php</p>
  
  <pre><code>&lt;?php
  session_start();
  // array for JSON response
  $response = array();
  if(isset($_POST['email']) &amp;&amp; isset($_POST['password'])){
      $email = $_POST['email'];
      $password = $_POST['password'];
  
  // include db handler
      require_once 'DB_Functions.php';
      $db = new DB_Functions();
  
       $user = $db-&gt;getUesrByEmailAndPassword($email, $password);
        if ($user != false) {
              // user found
              // echo json with success = 1
              $response["success"] = 1;
              $response["uid"] = $user["unique_id"];
              $response["user"]["name"] = $user["name"];
              $response["user"]["email"] = $user["email"];
              $response["user"]["created_at"] = $user["created_at"];
              $response["user"]["updated_at"] = $user["updated_at"];
              echo json_encode($response);
          } else {
              // user not found
              // echo json with error = 1
              $response["error"] = 1;
              $response["error_msg"] = "Incorrect email or password!";
              echo json_encode($response);
          }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>the function used in this above php file is i.e getUesrByEmailAndPassword($email, $password)
  is below :</p>
  
  <pre><code>public function getUserByEmailAndPassword($email, $password) {
          $result = mysql_query("SELECT * FROM users WHERE email = '$email'") or die(mysql_error());
          // check for result 
          $no_of_rows = mysql_num_rows($result);
          if ($no_of_rows &gt; 0) {
              $result = mysql_fetch_array($result);
              $salt = $result['salt'];
              $encrypted_password = $result['encrypted_password'];
              $hash = $this-&gt;checkhashSSHA($salt, $password);
              // check for password equality
              if ($encrypted_password == $hash) {
                  // user authentication details are correct
                  //return $result;
                  session_start();
                  $_SESSION['clientId'] = $result[0];
                  $_SESSION['logged_in'] = TRUE;
              }
          } else {
              // user not found
              return false;
          }
      }
  </code></pre>
  
  <p>Please help me to make my code working.
  Any help will be appreciated. 
  Any link containing such problem solution can be helpful for me. thank you! </p>