note 53497 added to function.fopen

From: Date: Fri, 03 Jun 2005 13:14:06 +0000
Subject: note 53497 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-89858@lists.php.net to get a copy of this message
When used with URL address, I've seen some scripts that use fsockopen() instead of fopen() becouse you have more power (control) over the headers you are sending. This control passes you the job of interpreting the headers sent to you (e.g. Location, Redirect, must be interpreted by you to actually receive the page you are redirected to). I believe fopen() works faster and interprets the headers received. If you are trying to send/change header User-Agent in an request you can use ini_set() : ini_set("user_agent","Opera/8.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n"); $wp=fopen("http://www.yourURLaddress.com/","r"); // ... fclose($wp); "user_agent" is a php variable sent by PHP when a fopen with URL is made. My idea is that some of the headers (not only User-Agent) can be sent to server by appending the headers you need to send to the user_agent variable. To send User-Agent and Language use: <?php $header = "Opera/8.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n"; $header .= "Accept-Language: ro-en\r\n"; $content = ''; ini_set("user_agent",$header); $wp=fopen("http://www.yourURLaddress.com/","r"); // here you receive content of page while(!feof($wp)) { $content .= fread($wp,4096); } fclose($wp); ?> You can try with diferent headers to see if it works, I only needed the Language to be sent and it saved me some time. ---- Manual Page -- http://www.php.net/manual/en/function.fopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53497 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53497&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53497&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53497&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53497&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53497&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53497&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89858) next »