Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP > PHP Application Design
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 17, 2009, 08:00   #1
NuWeb
SitePoint Zealot
 
NuWeb's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 117
API Development - SimpleXML

Hello All,

I have made a lightweight CMS with SimpleXML and Smarty. The idea being the database can be hosted on "the cloud" and the website on the odd hosting package.

The "content" part is great and working fine, Now im getting to the "management system" part, and not sure how to process data between user and server.

I first thought I'd append the API Request
PHP Code:

simplexml_load_file($uri.'api.php?key=x&item_id=4'); 

becomes (on user submit)
PHP Code:

simplexml_load_file($uri.'api.php?key=x&item_id=4&user_id=4&comment=xxxxxxxxxxxxxxxxxxxxxxxx'); 

Then I remembered that URI's have a character limit so it would fail?

The next idea, if no one can correct the above or alternate method.
Is to use PHP Curl, to POST data to a listener and return a Fail or Success.

First API based website, so tad confused.
NuWeb is offline   Reply With Quote
Old Nov 17, 2009, 08:30   #2
AnthonySterling
Twitter: @AnthonySterling
 
AnthonySterling's Avatar
 
Join Date: Apr 2008
Location: North-East, UK.
Posts: 3,274
If you're going to this extent, you may as well embrace cURL and REST then do it properly I reckon.

GET, POST, DELETE, HEAD and so forth...
AnthonySterling is offline   Reply With Quote
Old Nov 17, 2009, 09:57   #3
PHPycho
SitePoint Wizard
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 1,128
When web services comes in my mind, I always prefer SOAP. Though its a bit tough to start with ( as we have to deal with WSDL), once know makes your life in web service easier.
PHPycho is offline   Reply With Quote
Old Nov 18, 2009, 01:45   #4
Wardrop
SitePoint Guru
 
Join Date: Oct 2006
Location: Queensland, Australia
Posts: 700
For any system dependant on http transfers, I'd always use cURL as it's opens up all the functionality and power of HTTP, and provides a better level of error reporting.
Wardrop is offline   Reply With Quote
Old Nov 18, 2009, 07:28   #5
Salathe
/(?i:\Abb\z)|(?![Bb]{2})/
 
Salathe's Avatar
 
Join Date: Dec 2004
Location: Wigan, United Kingdom
Posts: 636
Quote:
Originally Posted by NuWeb View Post
The next idea, if no one can correct the above or alternate method.
Is to use PHP Curl, to POST data to a listener and return a Fail or Success.
If you want to stick with simplexml_load_file then you can POST the data by using a stream context.
Salathe is offline   Reply With Quote
Old Nov 18, 2009, 10:28   #6
BrandonK
SitePoint Guru
 
Join Date: Dec 2005
Posts: 932
Ran into this problem just recently myself. I switched from GET similar to how you are doing it and now I am using POST via stream context just like Salathe recommended. The change took me roughly 10 minutes to figure out. I used these params:
PHP Code:

    $request_params = array(
          
'http' => array(
              
'method'  => 'POST'
            
, 'header'  => 'Content-type: application/x-www-form-urlencoded'
            
, 'content' => http_build_query(array(
                      
'postvar' => 'postval'
                    
))
            )
        );
BrandonK is offline   Reply With Quote
Old Nov 20, 2009, 03:53   #7
dowker
SitePoint Member
 
Join Date: Nov 2009
Posts: 6
Hey i feel this is a good work you are doing.
dowker is offline   Reply With Quote
Old Nov 25, 2009, 09:32   #8
xigmapro
SitePoint Member
 
xigmapro's Avatar
 
Join Date: Nov 2009
Posts: 1
Arrow

The idea what you describe a great idea!
xigmapro is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 23:07.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved