I am trying to make the session processing process in android. Here, I successfully logged in via android, and now I continue to process the registered user session. this is my login_suer.java (part of android)
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";
now i need an idea to start processing the session in this java file. and the server side code below: ie login_user.php
<?php session_start(); 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); } } ?>
the function used in this php file above is ie getUesrByEmailAndPassword ($ email, $ password) below:
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 > 0) { $result = mysql_fetch_array($result); $salt = $result['salt']; $encrypted_password = $result['encrypted_password']; $hash = $this->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; } }
Please help me make my code work. Any help would be appreciated. Any link containing such a solution to the problem could be useful to me. Thanks!
source share