IMC!


Contents


Photos

 







Browsing around...
News  News Links  Links Blog  Blog Italiano  Español 
Request wepages with cURL

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
<?php

#This script requests a web page from internet, 
# and stores it in a variable

# Link of the webpage
$indirizzo_pagina="www.giacobbe85.altervista.org";

# cURL code. It requests the webpage and stores it in $data
$ch curl_init() or die(curl_error());
curl_setopt($chCURLOPT_URL,$indirizzo_pagina);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
$data=curl_exec($ch) or die(curl_error());

# Print of $data
echo $data;

# Errors
echo curl_error($ch);
curl_close($ch);
?>









Comments

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.

Your comment (lascia bianco!):
Uses (max 25 characters, required)
Web site (max 255 characters, optional)
e-Mail (max 255 characters, optional, will not be published) Your opinion (lascia bianco!):
Comment (max 4000 characters, required):





Valid HTML 4.01 Transitional
E-Mail - 70.06 ms

Valid HTML 4.01 Transitional