-
Recent Posts
Post Categories
-
Networks
-
Blogroll - Developers
-
Ads
Borrow or lend money with the peer-to-peer lending company Zopa UK
Send great value flower gifts throughout the UK with Send Flowers By Post
Original art, giftware, jewellery and leather craft tropicalarchipelago Etsy Store
Category Archives: PHP
PHP Database Based Session Handling
Due to a move to a multi-server environment at work to cope with peak time performance I was asked to implement a replacement to PHP’s standard session handling so that sessions would work in this new environment. In PHP 5.4 … Continue reading
PHP cURL Wrapper
I’ve put up a gist of a simple PHP cURL wrapper which simplifies basic content fetching with cURL. The class throws standard Exceptions in case of no content being returned or incorrect settings being passed as arguments. Setup:
1 2 3 4 5 6 7 8 |
$curl = new glowingminds\Curl('http://www.example.com/page.html'); $result = $curl->fetch(); //or $curl = new glowingminds\Curl(); $curl->setAddress('http://www.example.com/page.html'); $result = $curl->fetch(); |
Simple setters for … Continue reading
Arrays In PHP $_POST / $_GET Values
HTTP requests can of course be spoofed, just because your form says data should be transferred using GET or POST with specified names for element keys, this does not mean someone can’t alter the form before submission or even just use a … Continue reading
PHP Error Handling – Part Two, Standard Error Handling
This is a short post continuing the topic of errors in PHP, following on from error types & exceptions and leading to custom error handling, this post is a quick summary of the standard error reporting provided by PHP. In … Continue reading
Zend PHP 5.3 Certification
As of last week I am officially a Zend Certified Engineer (proof) and thought I should post something on preparing for the exam and share some useful resources for others who may be working towards the 5.3 certification. The “Zend … Continue reading
PHP Error Handling – Part One, Error Types & Exceptions
As a study aid whilst working towards Zend Certification and also due to a post on the topic being requested by a colleague (Barry) and after a rant by me after a talk at PHP UK 2012, here is the … Continue reading
Facebook Likes, Twitter Follows and Feedburner Count in PHP with cURL/SimpleXML (Deluxe)
So API’s from common providers are unreliable… below is the same code as my previous post but with two layers (1h + 24h) of Alternative PHP Cache (APC) caching and exception handling for the SimpleXML. Worth noting that the code … Continue reading
Facebook Likes, Twitter Follows and Feedburner Count in PHP with cURL/SimpleXML
Basic (no error handling) copy and paste code for getting Facebook Likes, Twitter Follows and a Feedburner Subscription count using PHP (with cURL):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
//Settings $facebookPageId = 'yourFacebookPageId'; $twitterHandle = 'yourTwitterHandle'; $feedburnerURI = 'yourFeedBurnerURI'; //Facebook Likes $curl = curl_init('http://graph.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id='.$facebookPageId); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $results = curl_exec($curl); $xml = new SimpleXMLElement($results); $facebookLikesCount = $xml->page->fan_count; curl_close($curl); $xml = NULL; unset($results); //Twitter Follows $curl = curl_init('https://api.twitter.com/1/users/show.xml?screen_name='.$twitterHandle.'&include_entities=true'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $results = curl_exec($curl); $xml = new SimpleXMLElement($results); $twitterFollowerCount = $xml->friends_count; curl_close($curl); $xml = NULL; unset($results); //Feedburner Subscribers $curl = curl_init('https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri='.$feedburnerURI); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $results = curl_exec($curl); $xml = new SimpleXMLElement($results); $feedburnerSubscriberCount = $xml->feed->entry->attributes()->circulation; curl_close($curl); $xml = NULL; unset($results); //Output echo '<p>Facebook like count: '.$facebookLikesCount.'</p>'; echo '<p>Twitter follower count: '.$twitterFollowerCount.'</p>'; echo '<p>Feedburner subscriber count: '.$feedburnerSubscriberCount.'</p>'; |
Note: PHP must be compiled with cURL: http://uk.php.net/manual/en/curl.installation.php Note: For the Feedburner API request to work you … Continue reading