note 89494 added to function.fopen

From: Date: Wed, 11 Mar 2009 06:47:25 +0000
Subject: note 89494 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-151713@lists.php.net to get a copy of this message
For anyone lazy dev who doesnt feel like changing file permissions for a simple cookie requests, I edited Adlez 04-Aug-2007 08:32's function to use a global variable as a cookie-holder. I only tested using 1 cookie. the function definitely has potential and needs a lot of improvement. also did couple of other improvements function open_page($url,$f=1,$c=2,$r=0,$a=0,$cf=1,$pd=""){ global $pm_cookie; global $oldheader; $url1 = $url; $url = str_replace("http://","",$url); if (preg_match("#/#","$url")){ $page = $url; $url = @explode("/",$url); $url = $url[0]; $page = str_replace($url,"",$page); if (!$page || $page == ""){ $page = "/"; } $ip = gethostbyname($url); }else{ $ip = gethostbyname($url); $page = "/"; } $open = fsockopen($ip, 80, $errno, $errstr, 60); if ($pd){ $send = "POST $page HTTP/1.0\r\n"; }else{ $send = "GET $page HTTP/1.0\r\n"; } $send .= "Host: $url\r\n"; if ($r){ $send .= "Referer: $r\r\n"; }else{ if ($_SERVER['HTTP_REFERER']){ $send .= "Referer: {$_SERVER['HTTP_REFERER']}\r\n"; } } if (!empty($pm_cookie)){ $send .= "Cookie: " . urldecode($pm_cookie) . "\r\n"; } $send .= "Accept-Language: en-us, en;q=0.50\r\n"; if ($a){ $send .= "User-Agent: $a\r\n"; }else{ $send .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n"; } if ($pd){ $send .= "Content-Type: application/x-www-form-urlencoded\r\n"; $send .= "Content-Length: " .strlen($pd) ."\r\n\r\n"; $send .= $pd; }else{ $send .= "Connection: Close\r\n\r\n"; } fputs($open, $send); while (!feof($open)) { $return .= fgets($open, 4096); } fclose($open); $return = @explode("\r\n\r\n",$return,2); $header = $return[0]; if ($cf){ if (preg_match("/Set\-Cookie\: /i","$header")){ $cookie = @explode("Set-Cookie: ",$header,2); $cookie = $cookie[1]; list($cookie) = explode("\r",$cookie); preg_match_all('/([^=]+=[^;]+)/', $cookie, $matches); $pm_cookie .= $matches[0][0]; } } if ($return[1]){ $body = $return[1]; }else{ $body = ""; } if ($c === 2){ if ($body){ $return = $body; }else{ $return = $header; } } if ($c === 1){ $return = $header; } if ($c === 3){ $return = "$header$body"; } if ($f){ if (preg_match("/Location: ([^\\s]+)/", $header, $ama)){ $url = str_replace('http:///', 'http://' . parse_url($url1, PHP_URL_HOST) . '/', $ama[1]); return open_page($url,$f,$c,$r,$a,$cf,$pd); }else{ return $return; } }else{ return $return; } } ---- Server IP: 69.147.83.197 Probable Submitter: 189.201.28.57 ---- Manual Page -- http://www.php.net/manual/en/function.fopen.php Edit -- https://master.php.net/note/edit/89494 Del: integrated -- https://master.php.net/note/delete/89494/integrated Del: useless -- https://master.php.net/note/delete/89494/useless Del: bad code -- https://master.php.net/note/delete/89494/bad+code Del: spam -- https://master.php.net/note/delete/89494/spam Del: non-english -- https://master.php.net/note/delete/89494/non-english Del: in docs -- https://master.php.net/note/delete/89494/in+docs Del: other reasons-- https://master.php.net/note/delete/89494 Reject -- https://master.php.net/note/reject/89494 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151713) next »