Fass schreef:Codeblok (voorbeeld.php):
1
2
3
4
5
6
$site = http://one2xs.com/; // belangrijk! In het formaat http://site/ $source = file_get_contents($site);echo htmlentities
($source);?>
Zoiets?
Wat Dylan zegt is een stuk betere oplossing.
file_get_contents is eigenlijk alleen bedoeld voor interne connecties. Met file_get_contenst is het bijvoorbeeld meestal niet mogelijk om websites die gebruiken van SSL op te halen.
Curl is zowel sneller als uitgebreider en beter. Daarbij kan je ook POST, GET en PUT requests meesturen (waar file_get_contents alleen GET kan)
Codeblok (voorbeeld.php): 1
2
3
4
5
6
7
8
9
10
11
12
function curl_get_contents($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla Firefox");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = curl_exec($ch);
curl_close($ch);
return $result
}
Nogmaals, probeer file_get_contents niet te gebruiken.