Request wepages with cURL
is a package of libraries and softwares which allows to interface with many different communication protocols, such as HTTP. PHP includes the extension libcurl
, which, if enabled, allows to use these functionalities. The following PHP code uses libcurl
to request a page from a webserver (as if it were a browser), and to store it in a variable. It can be very useful for including some code of a webpage into another page, without the use of iFrames or other similar solutions. The most interesting thing of this solution is surely the fact of getting the pure HTML code, after the sever side codes, like PHP or ASP, have been parsed.
Code of curl_en.php
#This script requests a web page from internet,
# and stores it in a variable
# Link of the webpage
# cURL code. It requests the webpage and stores it in $data
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data=curl_exec($ch) or die(curl_error());
# Print of $data
No comment present!
Write a comment
You can write here a comment to the article you've just read. Smiles, links and images are not allowed. The maximum comment length is 4000 characters. Please be polite, all the offensive messages will be deleted.