SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot NuWeb's Avatar
    Join Date
    Aug 2005
    Location
    UK
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Guru
    Join Date
    Oct 2006
    Location
    Queensland, Australia
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,398
    Mentioned
    65 Post(s)
    Tagged
    1 Thread(s)
    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
    Software Developer and PHP Manual Author.

  6. #6
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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'
                        
    ))
                )
            ); 
    MySQL v5.1.58
    PHP v5.3.6


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •