Url in php laden
Das Laden eines URLs in PHP kann auf mehreren Wegen lösen. Hier habe ich mal die wichtigsten Best Practices zusammengefasst:
1. readfile$url = "http://www.meineseite.de/"; $content = readfile($url); echo $content;
2. fopen$url = "http://www.meineseite.de/"; $handle = fopen('http://example.com/', "r"); $content stream_get_contents($handle);
3. file_get_contents$url = "http://www.meineseite.de/"; $content = file_get_contents($url); echo $content;
4. include$url = "http://www.meineseite.de/"; $content = include($url); echo $content;
5. curl$url = "http://www.meineseite.de/"; $ch = curl_init(); $timeout = 5; url_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $content = curl_exec($ch); curl_close($ch);
Was ist denn nun das Richtige für mich?… Weiterlesen