Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/173675-simple-php-api-help/
Share on other sites

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();
?>

 

Link to comment
https://forums.phpfreaks.com/topic/173675-simple-php-api-help/#findComment-915520
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.