note 7986 added to Using remote files

From: Date: Wed, 23 Aug 2000 16:12:58 +0000
Subject: note 7986 added to Using remote files
Groups: php.notes 
Request: Send a blank email to php-notes+get-3021@lists.php.net to get a copy of this message
Here's how to get the html from a page that requires a cookie: $connection = fsockopen ('www.php.net', 80, &$errorNumber, &$errorString, 10); if ($connection) { //set non-blocking mode set_socket_blocking($connection, false); //tell server what document we want fputs ($connection, "GET /quickref.php HTTP/1.0"); fputs ($connection, "\r\n"); fputs ($connection, "Cookie: PUT_YOUR_COOKIES_HERE"); fputs ($connection, "\r\n\r\n"); $headerStart = 0; $headerEnd = 0; while (!feof($connection)) { $currentLine = fgets ($connection, 128); if ($headerEnd) { //this is the html from the page echo $currentLine; } else if ( ereg("^HTTP", $currentLine) ) { //came to the start of the header $headerStart = 1; } else if ( $headerStart && ereg("^[\n\r\t ]*$", $currentLine) ) { //came to the end of the header $headerEnd = 1; } else { //this is the header, if you want it... } } fclose ($connection); } else { echo "$errstr ($errno)<br>\n"; } (remove NO SPAM to get my email address) http://www.php.net/manual/features.remote-files.php

« previous php.notes (#3021) next »