cindreta Posted September 9, 2009 Share Posted September 9, 2009 ok, basicly i don't understan how this api stuff works but here is what i wanna do: i have a small cms and i would like it if i could integrate some kind of version checking for the cms,for instance if a client has like v1.2 and there is a newer version it should warn him. so i think i am supposed to make an api call to my server and check the latest version and send it back to the clients cms. so i need help writing that server api and the client code. im thinking that the lateste version could be kept in a xml file like myserver.com/api.xml and then the client code reads it and compares it if somebody can post some code examples i would be very thankfull Quote Link to comment https://forums.phpfreaks.com/topic/173675-simple-php-api-help/ Share on other sites More sharing options...
JonnoTheDev Posted September 9, 2009 Share Posted September 9, 2009 There are many types of API calls you can make dependent on what the remote server is setup to accept i.e SOAP calls, XML-RPC & REST. REST are the most basic types of call and is really what you should implement for something so simple as you describe. The client code will make a call over HTTP GET to a script on your server. The response is XML. The client reads XML and processes i.e I would use CURL but heres a dirty example <?php // client api call $xml = file_get_contents("http://domain.com/api/getversion.php"); $obj = simplexml_load_string($xml); ?> getversion.php <?php // server receive call // get latest version from db $result = mysql_query("blah...."); $row = mysql_fetch_assoc($result); // display $output = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'; $output .= '<response>'; $output .= '<item>'; $output .= '<version>'.$row['version'].'</version>'; $output .= '</item>'; $output .= '</response>'; // display xml header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: '.gmdate('D, d M Y H:i:s').'GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); header('Content-Type: text/xml'); print $output; exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/173675-simple-php-api-help/#findComment-915520 Share on other sites More sharing options...
cindreta Posted September 9, 2009 Author Share Posted September 9, 2009 wow thank you so much i get it now, and thank you for the code sample u are the best : ) Quote Link to comment https://forums.phpfreaks.com/topic/173675-simple-php-api-help/#findComment-915564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.