4:02 PM
0

Web service for login method. Code is continue with user class which i mentioned in my previous post object oriented programming in php

Login Method Code

 function login($username,$password){
      $query = "select * from users where username='".$username."' AND password='".$password."'";
      $result = mysql_query($query);
      $num_rows = mysql_num_rows($result);
      return $num_rows;
 }

In the web service page.

  <?php
// Includes the class which have the all functions
ini_set('display_errors', '1');
include_once("user.class.php");

/* Created object for User class*/
$web = new users();
/* This file return the sucess or failure with provided details ( username, password ) */

// USER NAME - user_name
// PASSWORD - password


if(isset($_REQUEST) && ($_REQUEST['user_name'] != "") && ($_REQUEST['password']!="") ){

    $result = $web->login($_REQUEST['user_name'],$_REQUEST['password']);
    echo json_encode(array('results'=>$result));
}

/* Provided output in the json encoded format */
// Call the database disconnection method
$web->connection_close();

?>

Call this method as

http://localhost/login.php?username=anil&password=123456

Output:

if correct {“result”:1} else {“result”:0}
complete documentation for this post is at in anther file download it for better understanding.
References: http://www.anil2u.info

0 comments:

Post a Comment