CURL - client URL
evo ti uvod iz PHP manuala
PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.
These functions have been added in PHP 4.0.2.
Ja recimo koristim CURL za dohvat sadržaja s pojedinih stranica, dohvatim HTML kod čitave stranice i spremim ga kao string pa se onda dalje igram s time.
Postoji jako puno opcija i stvari koje možeš time raditi. Npr. na jednom projektu sam trebao napraviti aplikaciju koja dohvaća podatke sa stranice koja se nalazi iza logina. I onda sam napravio nešto slično ovome.
Code:
<?php
/*
This script is an example of using curl in php to log into on one page and
then get another page passing all cookies from the first page along with you.
If this script was a bit more advanced it might trick the server into
thinking its netscape and even pass a fake referer, yo look like it surfed
from a local page.
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/checkpwd.asp");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "UserID=username&password=passwd");
ob_start(); // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.myterminal.com/list.asp");
$buf2 = curl_exec ($ch);
curl_close ($ch);
echo "<PRE>".htmlentities($buf2);
?>
Tu sam uspio raditi i sa https-om.
Pogledaj u PHP manual, na google upiši "PHP CURL" pa malo pročitaj što ima.
Evo ti neki od linkova:
http://curl.haxx.se/libcurl/php/
http://blog.unitedheroes.net/curl/
http://www.phpfreaks.com/tutorials/49/1.php