Magento WizardNo joke, this website relaunches on 1st April. New look, new features!

Contact the site  Make Money

Using PHP to Pull in External Data

 Add to Favourites  
(No Ratings Yet)
Loading ... Loading ...

A useful thing that I have discovered recently with PHP, is that you can literally “blag” contents from another web-site, whereby you pull in the source code from any site of your choice, and display it on your own page – disguising the fact that you had to utilise the “other” web-site in the first place.

Obviously, using RSS, you can do this already, but this relies on the data source having a ready-made feed for you to import.

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
class LiteHttp{
    function __construct(){
    }
 
    public static function getUrlContent($url){
    if( !extension_loaded('curl') ){
    die('Activate CURL');
    }
    // init curl
    $curlHandle = curl_init();
 
    // options
    curl_setopt($curlHandle, CURLOPT_URL, $url);
    // set the url to fetch
    curl_setopt($curlHandle, CURLOPT_HEADER, 0);
    // set headers (0 = no headers in result)
    curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); // type of transfer (1 = to string)
    curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10); // time to wait in seconds
    $content = curl_exec($curlHandle);
    // make the call
    curl_close($curlHandle);
    // close the connection
    return $content;
    }
    }
 
    $overalldisplay = LiteHttp::getUrlContent('http://www.bbc.co.uk');

The above chunk of code will reproduce the BBC home page on any given page when you echo the $overalldisplay variable. Now, obviously, the site would look a mess as it would be using relative paths for both images and hyperlinks alike, however this is nothing that couldn’t be loopholed using some clever coding.

However, the content is key here. As you can now manipulate $overalldisplay how you wish, you can pull in whichever textual parts of the page you want on your web-site, ensuring your web-page has got constantly updated fresh content on a regular basis.

I’ve implemented a similar system for TV Wall Brackets. Once a customer completes an order, they are emailed a tracking email an hour later which gives them their consignment/tracking number and a URL to click for more information on the delivery of their item.

Now, when customers are familiar with certain web environments, the last thing they want is a tracking link to some impersonal courier company web-site which gives them the data in a confusing manner, so it makes sense to pull in the data yourself and manipulate so it is showed in a way that they DO understand!

With this example, I’ve drilled down the information so much so that it lists them what time their parcel left the Bournemouth depot, the time it arrived at the destination depot, the telephone number of their local depot, and even the name of the driver that is delivering them their parcel!

This script has considerably reduced a high percentage of daily phone calls from customers who “want to know where their parcel is”. Instead, the sales staff are able to concentrate on selling! Similarly, the customers’ user experience since the integration has been considered as “better”, “more coherent”, and “incredibly useful”.

  • Digg
  • del.icio.us
  • Facebook
  • Google
  • LinkedIn
  • Live
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

about the author

    This article was written by Sam Davis on July 10, 2007.
    Computing over a glass of Grenache Shiraz... again!
    Sam is the Editor of Blasted Thing. Contact Us

related articles

 Send MIME/HTML emails with PHP Mailer
 Echo a Google search term on your page

comments

Leave a Reply




Spam protection by WP Captcha-Free



  • Sponsored Ads

  • Magento Themes
    • vtiger: great article, thank you....
  • Recent Tweets

    Magento Ecommerce Development http://tinyurl.com/ybbjw45

    #cursodeseo Curso Magento Templates é o destaque da próxima semana no RJ - http://ow.ly/1oQWv

    Magento Enterprise Edition http://tribords.com/0/127

    Top 10 extensiones para Magento | onestic http://icio.us/zeojvn

    Attenzione agli host per magento, non tutti lo supportano, per joomla invece rigorosamente hosting Linux