众博彩票的网址99zbcCreate a RESTful Services API in PHP.

云南快乐十分走势图基本走势图

Wall Script
MailxEngine
Monday, May 14, 2012

Create a RESTful Services API in PHP.

Are you working with multiple devices like iPhone, Android and Web then take a look at this post that explains you how to develop a RESTful API in PHP.  Representational state transfer (REST) is a software system for distributing the data to different kind of applications. The web service system produce status code response in JSON or XML format.

Create a RESTful Services API in PHP.



New Tutorial: Create a RESTful services using Slim PHP Framework

Developer
Arun Kumar Shekar
Arun Kumar Sekar
Engineer
Chennai, INDIA

Database
Sample database users table columns user_id, user_fullname, user_email, user_password and user_status.
CREATE TABLE IF NOT EXISTS `users`
(
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_fullname` varchar(25) NOT NULL,
`user_email` varchar(50) NOT NULL,
`user_password` varchar(50) NOT NULL,
`user_status` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Rest API Class: api.php
Contains simple PHP code, here you have to modify database configuration details like database name, username and password.
<?php
require_once("Rest.inc.php");

class API extends REST
{
public $data = "";
const DB_SERVER = "localhost";
const DB_USER = "Database_Username";
const DB_PASSWORD = "Database_Password";
const DB = "Database_Name";

private $db = NULL;

public function __construct()
{
parent::__construct();// Init parent contructor
$this->dbConnect();// Initiate Database connection
}

//Database connection
private function dbConnect()
{
$this->db = mysql_connect(self::DB_SERVER,self::DB_USER,self::DB_PASSWORD);
if($this->db)
mysql_select_db(self::DB,$this->db);
}

//Public method for access api.
//This method dynmically call the method based on the query string
public function processApi()
{
$func = strtolower(trim(str_replace("/","",$_REQUEST['rquest'])));
if((int)method_exists($this,$func) > 0)
$this->$func();
else
$this->response('',404);
// If the method not exist with in this class, response would be "Page not found".
}

private function login()
{
..............
}

private function users()
{
..............
}

private function deleteUser()
{
.............
}

//Encode array into JSON
private function json($data)
{
if(is_array($data)){
return json_encode($data);
}
}
}

// Initiiate Library
$api = new API;
$api->processApi();
?>

Login POST
Displaying users records from the users table Rest API URL http://localhost/rest/login/. This Restful API login status works with status codes if status code 200 login success else status code 204 shows fail message. For more status code information check Rest.inc.php in download script.
private function login()
{
// Cross validation if the request method is POST else it will return "Not Acceptable" status
if($this->get_request_method() != "POST")
{
$this->response('',406);
}

$email = $this->_request['email'];
$password = $this->_request['pwd'];

// Input validations
if(!empty($email) and !empty($password))
{
if(filter_var($email, FILTER_VALIDATE_EMAIL)){
$sql = mysql_query("SELECT user_id, user_fullname, user_email FROM users WHERE user_email = '$email' AND user_password = '".md5($password)."' LIMIT 1", $this->db);
if(mysql_num_rows($sql) > 0){
$result = mysql_fetch_array($sql,MYSQL_ASSOC);

// If success everythig is good send header as "OK" and user details
$this->response($this->json($result), 200);
}
$this->response('', 204); // If no records "No Content" status
}
}

// If invalid inputs "Bad Request" status message and reason
$error = array('status' => "Failed", "msg" => "Invalid Email address or Password");
$this->response($this->json($error), 400);
}

Users GET
Displaying users records from the users table Rest API URL http://localhost/rest/users/
private function users()
{
// Cross validation if the request method is GET else it will return "Not Acceptable" status
if($this->get_request_method() != "GET")
{
$this->response('',406);
}
$sql = mysql_query("SELECT user_id, user_fullname, user_email FROM users WHERE user_status = 1", $this->db);
if(mysql_num_rows($sql) > 0)
{
$result = array();
while($rlt = mysql_fetch_array($sql,MYSQL_ASSOC))
{
$result[] = $rlt;
}
// If success everythig is good send header as "OK" and return list of users in JSON format
$this->response($this->json($result), 200);
}
$this->response('',204); // If no records "No Content" status
}

DeleteUser
Delete user function based on the user_id value deleting the particular record from the users table Rest API URL http://localhost/rest/deleteUser/
private function deleteUser()
{

if($this->get_request_method() != "DELETE"){
$this->response('',406);
}
$id = (int)$this->_request['id'];
if($id > 0)
{
mysql_query("DELETE FROM users WHERE user_id = $id");
$success = array('status' => "Success", "msg" => "Successfully one record deleted.");
$this->response($this->json($success),200);
}
else
{
$this->response('',204); // If no records "No Content" status
}
}

Chrome Extention
A Extention for testing PHP restful API response download here

.htaccess code
Rewriting code for friendly URLs. In the download code you just modify htaccess.txt to .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
</IfModule>

226 comments:

  1. pls post more about api i want to learn that

    云南快乐十分走势图基本走势图it's very nice , what about xml rpc

    really usefull to me.. thanks a lot :)

    nice. 'll give it a try

    thanks for the article :)

    云南快乐十分走势图基本走势图that a very well but i want some more example & declaration pls provide this.thank u

  2. kool man nice work .. i have used this one

    云南快乐十分走势图基本走势图good job ! but it would be much better if you indent the code with tabs, as the code above is little difficult to understand

    I will definitely try it out to develop demo API by myself and will try the same API for the android app development.

    云南快乐十分走势图基本走势图Thank for sharing detailed article.

    awesome article....!

  3. amazing!!

    云南快乐十分走势图基本走势图very good tutorial! thanks a lot!

    云南快乐十分走势图基本走势图muito bom cara! parabéns.

    very good post as usual! good work, arun! :)

    云南快乐十分走势图基本走势图could you explain how to get data? as i see in this script, in url you send a name, that name is the name on the function. further more _request is set to array. so you wrap everything in an array?? but then, how to extract, so you get correct function?? im confused! and where to extend this so i can claim and api key ?

    @kfllash32 : this is little bit tricky but more user friendly, api(api.php) demo class wrote like this way query string as a function. but you can write your own class insteed of api.php. validating api key or headers and all up to you.

    I have some experiences in this, so I figures out a way, but the Login function in the api.php will not work for most users because you also need email and username input. And something strange.
    云南快乐十分走势图基本走势图You write this: $this->response('',204). And this will return nothing at all, because first param is '' (empty) and in the function you return data (data is the first param left empty). So what is the point with this one?

    云南快乐十分走势图基本走势图every nice ... big thanks if i can have more tutorial

  4. how to highlight your codes?

    yeah looks nice dude

    your diagrams are impressive, what tool you use for that?

    I heard PHP is not good for applying RESTfull because it does not integrate natively query functionality DELETE and PUT

    It's really?

    云南快乐十分走势图基本走势图well, that upto you what you think. but php is the best option for http request in sss.

  • 云南快乐十分走势图基本走势图thank this blog always saves me.i love your jobs and i stay tune.i ll try this api because i have a simillar projet and this will help i think so

    云南快乐十分走势图基本走势图well nice post keep it up for us to learn more...

    Can any one explain this line in Sample database "users"

    ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

  • What did you use in making the illustration:
    http://lh6.googleusercontent.com/-u9hFxEK0OS8/T6a9yHaniHI/AAAAAAAAF_Y/prEsvdWrNtI/s550/rest.png

    adobe illustration

    What about security :))?
    Write is you can how to use also with REST OAuth.
    Also do you know why some API uses such url
    site.com/api/create.json
    云南快乐十分走势图基本走势图why the use dot?

    云南快乐十分走势图基本走势图nice sir ji

    post more information regarding the rest modules and i want to integrate it with my application

    nice sir.. thank you for sharing always your ideas to us ..

    very nice. thanks..

    i am having a problem getting Params such as email and Password for the sample Post function login()
    could it be htaccess?
    email and password keep coming in as null

    云南快乐十分走势图基本走势图any suggestions? I have Sample Code

    Well, this example ios really nice and working so far. I just wanna know if it's possible to request for a special user this way:

    http://localhost/rest/users/14

    GET: List info for user with ID of 14

    How do I manage it with your code? Is that possible?

    how to pass request for deleteuser and login in url..

    pls explain someone

  • 云南快乐十分走势图基本走势图this is really nice and easy plugin. can u plz tell me how to call 'login' function with post menthod. plz it's urgent. it wil be really great if you reply asap

    this tutorial is not in detail for the person who is new to api. i was trying to create an api that inserts records to my db. i know i could use this, but i'm struggling

  • Hi,

    Can anyone tell how to use this api? Do I need to call it from other application? If yes, then how?

  • 云南快乐十分走势图基本走势图i always see get request. how to change it to post ?

    云南快乐十分走势图基本走势图could you please post an example for inserting data using post.

    could you please post insert & fetch data using xml with rest

  • Can you explain the post methods. Means how can i post email and password

    thanks

  • thanks.... its enough to start with rest api for begginers

  • Hello,

    I am new to php, how to execute this program ?

    Can any one help.

  • 云南快乐十分走势图基本走势图what are de .ds_store and .htacces files for? regards!

  • To execute the program you must have php installed, and a web server.

    I'd suggest you look for tutorials for beginning php first. Then when you are comfortable, and know what REST is, then come back

    not working how to see result of http://localhost/rest/users/??

  • How to call it for testing...

    hi!
    云南快乐十分走势图基本走势图can u explain me how use credential for calling REST resources after login?

    Nice job Arun :D
    but are you sure that the returns in json?

    for example, i use your Rest.inc.php file for construct an api, and this file return that's

    string(508) " object(Api)#1 (8) { ["data"]=> string(0) "" ["db":"Api":private]=> resource(4) of type (mysql link) ["_allow"]=> array(0) { } ["_content_type"]=> string(16) "application/json" ["_request"]=> array(3) { ["rquest"]=> string(5) "login" ["Email"]=> string(15) "[email protected]" ["Password"]=> string(5) "12345" } ["_resp"]=> array(1) { ["Id"]=> string(1) "1" } ["_method":"REST":private]=> string(0) "" ["_code":"REST":private]=> int(200) } "

    is json?

  • Very helpful... I can test it in php and working perfectly. But unable to call it in windows phone.
    云南快乐十分走势图基本走势图So, Can you tell me how can I call it in Windows Phone apps.

    云南快乐十分走势图基本走势图helpful for beginners. great!!!

    make sure to enable mod_rewrite in httpd.conf

  • I am getting this error:
    Notice: Undefined index: rquest in C:\server\www\jrserver.dev\public_html\rest\api.php on line 69

  • 云南快乐十分走势图基本走势图thanks for the info !

  • @eureckou: you should pass the parameter rquest and value to that.
    云南快乐十分走势图基本走势图for example. "http://localhost/rest/api.php?rquest=users" so that your rquest parameter will be passed and the value will be accessed in processApi(). Then the action will be taken according to your request.

  • 云南快乐十分走势图基本走势图thanks for sharing

  • Hi, thanks for that good.. it took me a while to find any good and easy to use examples..

    One question.. When I use to Chrome extension to test the web service, the login and deleteUser function is not working.. During the debbuging I found out that $_GET and $_POST is just empty.. any idea why that happens?

  • 云南快乐十分走势图基本走势图plz tell me form where we can post the value and how can get post value within function....

  • good tutorial but you know that the post implementation is not working, right? there are a lot of people asking for help in the comments but i guess the author forgot about this post... it's a shame.

    can anyone help me on how to access the service methods from the client code.

    There is no impementation of any methods to add a user so to use the API you need to first add data into your database's 'users' table. Use an online md5 generator to create the password and make sure to have the field 'user-status' set to 1 if you want to get the data. To login (/login) use POST and variables 'pwd' and 'email' in Payload, to see users (/users use GET. To delete, no idea. Seems like dELETE is not accepted on my system (Chrome/Windows). I hope this will help some of you.

    云南快乐十分走势图基本走势图to delete users, there is an error: in rest.inc.php, within the inputs() method, delete must be treated as put, not as get as it is currently set.

    云南快乐十分走势图基本走势图really helpful dude..thanks a lot.. :)

    curl testing

    $ch = curl_init('http://api.local/deleteUser?id=2');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    云南快乐十分走势图基本走势图echo $result = curl_exec($ch);

    curl testing

    $ch = curl_init('http://api.local/deleteUser?id=2');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    echo $result = curl_exec($ch);

    curl testing

    $ch = curl_init('http://api.local/deleteUser?id=2');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    云南快乐十分走势图基本走势图echo $result = curl_exec($ch);

    云南快乐十分走势图基本走势图good i'd like to know how to call the api from jquery mobile application

    Hi,
    Can you tell me please where from download Rest.inc.php?

  • To use it without problems make sure you have:
    apt-get install php5-curl

    require_once("Rest.inc.php");

    云南快乐十分走势图基本走势图from where i get it?

    云南快乐十分走势图基本走势图not served in wampserver gives me a problem in the require_once ("rest.inc.php");

    云南快乐十分走势图基本走势图very helpful tutorial, thanks very much!

    云南快乐十分走势图基本走势图i am new to soap and rest which do you recommend me to learn and is easy to learn.

  • how do i use the private function login() section. if i have 2 inputs for username and password and i post the email and password to api.php how can i log that user in through private function login()?

    Getting a 404 Not Found?
    云南快乐十分走势图基本走势图Make sure to enable mod_rewrite in httpd.conf

  • 云南快乐十分走势图基本走势图we want to create api for prepaid mobile recharges & other kindly provide suggession to get it

    Hi,

    I am trying to use this code and actually i am getting an notice like..


    Notice: Undefined index: rquest in C:\xampp\htdocs\rest\api.php on line 69

    Can you please explain what the problem..

  • 云南快乐十分走势图基本走势图nice post... very helpful

    hi guys. i am new to PHP. here i am using this api.php for webservice consuming to mobiles.can any one please tell me how can i use POST method for login function.

    my table name: user

    column names : email , password
    please urgent please.
    thanks in advance.

  • u can also use this to call with the style /users instead of api.php?rquest=users
    $func = trim(str_replace("/","",$_SERVER['REQUEST_URI']));
    $func = trim(str_replace("restcomicapp","",$func));
    $func = trim(explode("?",$func)[0]);

  • cool guy !
    have a nice year !
    ben

  • You dont kwown with means API REST.

    Example, with same URL:
    /resource/333

    diferent HTTP VERB (DELETE, POST, PUT, GET), Delete, create, update or GET de resource


    hi am getting an error like

    Notice: Undefined index: rquest in C:\xampp\htdocs\rest\api.php on line 69

    What should I do

    nice tutorial.thanks.keep up the good work

    云南快乐十分走势图基本走势图hi, thanks alot but i am new beginer with restful, can you help me how test demo?

  • thank you for this! simple, but it works for my little project.

    can you explain me why do you get function by $func = strtolower(trim(str_replace("/","",$_REQUEST['rquest'])));

    I don't find any rquest variable.

    how to upload byte array of image in php?

    thaks,
    srinivas

  • i'm new to php.here is api.php is a client code & rest.cin.php is a server code? wt is the use of htaccess.txt and how to run?

    hi its ok how to i run this script in my localhost

    云南快乐十分走势图基本走势图thanks for simple lessons

  • nice...very useful

    this is awesome tutorial for learning api web application.it is very useful for developing android application.

    云南快乐十分走势图基本走势图we can make this without using rest keyword, so how we can ensure that its used rest api. is there have any specific keyword for rest ? please someone explain this.

    hello i am not able to get response , plz help me

    plz help me i am not geting response

    my web project name = rest

    request = http://localhost/rest/users

    htaccess = file same in example

    Thanks a lot Arun, it really helped a lot.
    Cleraed my basic confusion about rest api and solved my purpose too.
    Keep it up.

    云南快乐十分走势图基本走势图not working..

    Hello... Thanks for the tutorial...
    please how do i get to test what you have explained in this tutorial?

    please i have tried implementing this but i i have not been able to consume the api in a client file.

    Login is not worked for me. But i changed something like following...Now its working fine..

    Please use $_REQUEST to get params,

    if(isset($_REQUEST['email']) && isset($_REQUEST['pwd'])){
    $email = $_REQUEST['email'];
    $password = $_REQUEST['pwd'];

    // Input validations
    if(!empty($email) and !empty($password)){
    //keep all queries
    }
    }

    ultimate tuts dude..keep it up.thnx alot

    gud tut..
    can u help how to send response in json/xml
    if user send url as format/json or format/xml

  • nice post to learn

    so this is what rest does. thank you!

    hi i just use you rest api and also using rest client but every time i getting response does not contain any data. please help

  • client side code for login:

    $user_data = array();

    $user_data['email'] = '[email protected]';
    $user_data['pwd'] = md5('test123');

    // cURL code
    $ch = curl_init('http://localhost/rest/api.php?request=login');

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $user_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $response = curl_exec($ch);

    echo $response;

    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    echo $http_code;

  • HI , This is a very nice tutorial. GET request is working fine. But POST request is not working properly. Here is the solution,I tested this in mozilla rest client addon. Please enter json format data in request body [{"email":"[email protected]","pwd":"123456"}].

    For reading that json code we need to add few lines in api.php.
    $request_body = file_get_contents('php://input');
    $json = json_decode($request_body);
    $email = $json[0]->email;
    $password = $json[0]->pwd;
    Thats all. In mozilla rest client addon at the time of executing pls select method type POST.
    Thanks..


    Thanks for the lesson!
    In advance rest client->chrom i tried,
    http://localhost/rest/login/, to post the inputs, i face 400 Bad Request error when inputing the following json information:

    {
    "email":"[email protected]",
    "password":"test123"
    }

    i wonder to know the way json should be inputed for posting the login information.

  • Hi, is really http://localhost/rest/deleteUser/ even rest?
    Shouldn't be somthing like DELETE http://localhost/rest/users/21 to be able to call it Rest?
    Where is the Uniform Interface in all this?

    You really should read this carefully: http://en.wikipedia.org/wiki/Representational_state_transfer

  • problem with your userID???
    try this:
    http://localhost/rest/users?id=2

    don't use:
    云南快乐十分走势图基本走势图http://localhost/rest/users/2

    try with:
    http://localhost/rest/users?id=2

    don't use:
    http://localhost/rest/users/2

    云南快乐十分走势图基本走势图it's work

    hi, it was nice work for me thanks

    i am happy to see your new design

    hello! just start with this the rest api, i saw your code and if i understand but as implemented on a small website.

    This error code is too generic. Can you give more info, a complete description of the error message, a picture, something more?
    Without more info, I won't be able to help you
    Thanks mate

  • 云南快乐十分走势图基本走势图how to run dis application?

    thankyou very much for your sharing ! ^_^
    can you explain to me how htaccess file works?

    Hi,
    I am getting


    Notice: Undefined index: email in D:\XMAPP\xampp\htdocs\rest\api.php on line 92



    Notice: Undefined index: pwd in D:\XMAPP\xampp\htdocs\rest\api.php on line 93

    {"status":"Failed","msg":"Invalid Email address or Password"}

    云南快乐十分走势图基本走势图When i using http://localhost/rest/login API with post method

  • 云南快乐十分走势图基本走势图good article.

    anything to insert data in to database???

    nice post, so how to access this rest on andorid with java code?? would you mind to give an example?? i had a code with web service server side on php then client side on java. but i didnt apply api rest to my code. im just a newbie,

    can u please explain for beginners

    云南快乐十分走势图基本走势图how to use html form to post data to the function

    thanks for the great tutorial!

    I like this tutorial. How to use this on web app?
    thanks in advance

    云南快乐十分走势图基本走势图how to use html form to post data to the function.thanks for the great tutorial!

  • Nice tutorial AKS, easy and simple to understand.
    But as most of the people in this thread mentioned, I am also little stuck with the POST implementation. I am not sure, over here how to make POST request with login.
    When I use http://localhost/rest/login, I always get 406 (Not acceptable) in the headers (Request method being served as GET). But as you mentioned in the tut that it is Login POST, so can you/someone please share how to make a POST request for login. How can I test it on localhost?

    It's very nice , what about XML RPC
    Thanks

  • Hi,
    I'm new to PHP im struggling with the htaccess configuration. I'm using port 8080 for my server localhost:8080



    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^(.*)$ http://localhost:8080/api.php?rquest=$1 [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ http://localhost:8080/api.php [QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} -s
    RewriteRule ^(.*)$ http://localhost:8080/api.php [QSA,NC,L]


    can anyone help me? Thanks in advance :D

  • nice tutorial really helpfull

    云南快乐十分走势图基本走势图why are we using htaccess configuration ? im a newbie

    i created one record in the users table and then tried to run the api "localhost/rest/api.php?rquest=1 but i got a blank page. if i want to retrieve the data from the users database, how do i do it?

    云南快乐十分走势图基本走势图me too, i received the blank page please need someone to help.

    me too i receieved a blank page for this tutorial please someone to help
    thank you

    user httprequester or postman to post,get,delete,put data, rquest is ment to find the request method and it need not be in the url.

  • hi i run the above script but i am getting an error, 'fatal error: class 'rest' not found in c:\xampp\htdocs\rest\api.php on line 4 '. please help me to fix this, thanks in advance :)

  • Mr Srinvas Tamada. Are you aware the deleteUser function doest function? Whenever a request is made (using the above recommended API client for chrome, nothing happens. It just returns a 204 no content error. I found out that the $id assignment doesn't work because $this->_request['Id] is blank. A searched the web and found out that this has to do with a complication with most web servers not allowing Delete requests, or a complication with PHP and delete requests, either way the delete request is the problem. I confirmed this by simply switch the request method for the deleteuser function to POST instead of delete and it worked. I'm not sure what you did to you Dev environment for it to work, or what environment you're using (I'm using the lateset XAMPP, BTW). Would you please correct me or your tutorial?
    云南快乐十分走势图基本走势图Thanks for the great tutorial nonetheless.

  • thanks!!! very very good!

  • it really helps a lot. thanks!

    云南快乐十分走势图基本走势图nice tutorial for rest beginners, thanks!

  • How to pass parmater for insert data

    Nice tutorial for beginners, Thanks.

    I am using same method for my api but stuck now.
    i have two urls
    1. api/users - to get all users which is done already
    2. api/users/search/id - to search user with id ( any keyword )

    云南快乐十分走势图基本走势图can someone guide me on how to get it done ?

    How to create a a function for url like api/users/edit/1 ?
    云南快乐十分走势图基本走势图it simply update the user with id 1, values will be passed by POST

    云南快乐十分走势图基本走势图its realy usefull api

  • Suppose : i want to access data from a server through REST api System and the server link is www.test.com

    I do have the username and password .

    Now how to fetch the data...

    I tried using the firefox Add-On RESTclient 2.0.3 and it works...but i can't write the code of my own...

    i am trying since last week but unfortunately still unsuccessful :(

    Can you please help me....i haven't had much knowledge about REST..beginner you ca say.

    Thank you

    云南快乐十分走势图基本走势图I ll try this

    How to Delete user from this
    http://localhost/CeederOn/rest/api.php?rquest=delete
    云南快乐十分走势图基本走势图how to pass id actual i wanna ask

    Nice Tutorial
    How can I call it with curl can you please help me?

    $func = strtolower(trim(str_replace("/","",$_REQUEST['rquest'])));

    Can Some one help me in understanding, what this code line above does, cz am getting an error when ever I hit the api method

    the error is undefined index : rquest

    thanks

  • can you please explain how this api or urls will call in mobiles.what will be the connection?

  • please explain how the connection was built between api and android or ios or anything

  • how the urls are called from mobiles and connect to mysql and get the results?

  • great post , well explained and super understandable ... thank you very much !!!
    云南快乐十分走势图基本走势图from Paraguay

  • It does not work for GET http://localhost/services/customer/1 (This is actual REST calls)
    But it works with http://localhost/services/customer?id=1

    What shall we do to make it work with such URL?

    can you explain using CURL..

    云南快乐十分走势图基本走势图how can we do that without using Chrome exetention

  • 云南快乐十分走势图基本走势图simply, fantastic! thanks

    Hi,
    Please tell me anyone,
    get is working.
    云南快乐十分走势图基本走势图how to test delete using chrome extension?

    how to test login in chrome

  • good job

    云南快乐十分走势图基本走势图something that worth reading... thanx for the lesson

  • 云南快乐十分走势图基本走势图thanks for the tut it worked properly... but i have a prblm with .htaccess files i just want to add a new file like api.php to .htaccess. can you please help me with these...

  • how to get youtube api and show in our web ?

    how can i use this service with post key value parameter using poster

  • Here is the add user(insert):

    private function adduser(){
    // Cross validation if the request method is GET else it will return "Not Acceptable" status
    if($this->get_request_method() != "POST"){
    $this->response('',406);
    }
    $name = isset($_POST['name']) ? mysql_real_escape_string($_POST['name']) : "";
    $email = isset($_POST['email']) ? mysql_real_escape_string($_POST['email']) : "";
    $password = isset($_POST['pwd']) ? mysql_real_escape_string($_POST['pwd']) : "";
    $status = isset($_POST['status']) ? mysql_real_escape_string($_POST['status']) : "";
    $sql = mysql_query("INSERT INTO `users` (`user_id`, `user_fullname`, `user_email`, `user_password`, `user_status`) VALUES (NULL, '$name', '$email', '$password', '$status');", $this->db);
    if($sql){
    $success = array('status' => "Success", "msg" => "Successfully inserted");
    $this->response($this->json($success),200);
    }else{
    $this->response('',204); // If no records "No Content" status
    }

    301 error when i calling api.php?request=users

    how can i create a page except api.php? i create a page mails.php but it is not working due to some htaccess issue. how can i solve it. i want to use another page for data insertion using cron job on the server. please let me know, how can i execute the another page?

  • very useful tutorial. but i have a problem in the login post method - the email and password parameters are being passed empty as it is not entering in the if condition.... and i am using google advanced rest client. any help please?

    云南快乐十分走势图基本走势图i have a problem with delete method. when i tested using advanced rest client addon in chrome i cant get the id in request in php. is there any problem with api.php.

  • 云南快乐十分走势图基本走势图why does the post method only work using x-www-form-urlencoded? is it possible to send the parameters in json? i tried using json format but the parameters were sent empty. any help please?

  • thanks, it works for me, and do help me a lot.

    please provide the rest api code using codeigniter.

  • Can some provide the NGINX configuration for this API.

    I m running on nginx server

  • I am getting the error Undefined index: email ,pwd on line 90,91
    $email="[email protected]";
    $pwd="abcd";
    $strPost= 'email='.$email.'&pwd='.$pwd;
    in curl I am passing values like this
    curl_setopt($ch, CURLOPT_POSTFIELDS,$strPost);

    云南快乐十分走势图基本走势图please help me

  • How we test the API?

    http://localhost/rest/users/ is referring me anything

  • Hi,

    I am trying to use this code and actually i am getting an notice like..


    Notice: Undefined index: rquest in C:\xampp\htdocs\rest\api.php on line 69

    Can you please explain what the problem..

  • Hi,

    I am trying to use this code and actually i am getting an notice like..


    Notice: Undefined index: rquest in C:\xampp\htdocs\rest\api.php on line 69

    Can you please explain what the problem..

    good nice tutorial



    Notice: Undefined index: rquest in C:\xampp\htdocs\rest\api.php on line 69


    iam getting this error how to handle it



    Notice: Undefined index: email in C:\xampp\htdocs\rest\api.php on line 89



    Notice: Undefined index: pwd in C:\xampp\htdocs\rest\api.php on line 90

    云南快乐十分走势图基本走势图{"status":"Failed","msg":"Invalid Email address or Password"}

    hi,
    i am use odbc php but i have a problem. can you help me? please

    code -- code -- code --

    $sorgu="SELECT mno,durum FROM dba.masa";
    [email protected]_exec($conn,$sorgu);
    if (!$sorgu) { echo"Sorgu Hatası"; }



    $result = array();

    while ($sorgu_yaz = odbc_fetch_array($sorgu)) {
    $result[] = $sorgu_yaz;
    }
    ..
    $this->response($this->json($result), 200);
    ..
    private function json($data){
    if(is_array($data)){
    return json_encode($data);
    }
    }



    云南快乐十分走势图基本走势图this is not working pleasee help me

    i am not able to change headers to json content type


    Host: localhost
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate

    Hi,

    It is very useful for me...Thank you for this article...

    I have a issue to close the connection of MySQL. I am using destruct function for close the connection but it is not working...Please help me.

    here is the code,
    function __destruct() {
    mysql_close($this->db);
    }

    you want use with html?that done using ajax.

    云南快乐十分走势图基本走势图authors, you should answer to those questions asked in your blog, else this rest api a waste of time. i see there is a lot of unanswered questions up there. please answer those. thanks.

    please try to use latest one http://fsqljkz.cn/2014/12/create-restful-services-using-slim-php.html

  • giving me 404 error

    云南快乐十分走势图基本走势图thanks for help me

  • Newer Post Older Post Home
    乐优彩票天天红单下载 乐优彩票登入,备用,官方网址 乐优彩票网址是多少 乐和彩彩票网 乐优炫彩app 乐优炫彩官网 乐优炫彩app天天红单 乐优炫彩彩票app下载 乐体育app下载 乐信pc下载