note 9979 deleted from function.fsockopen by jimw
| From: | jimw@php.net | Date: | Sat, 08 Dec 2001 21:56:21 +0000 |
| Subject: | note 9979 deleted from function.fsockopen by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22250@lists.php.net to get a copy of this message | ||
To upload a file manually using fsockopen :
<?php
// the receiver of file
$remote_page = "http://127.0.0.1/upload.php";
// the file you want to upload
$file = "/home/alexander/sql.txt"; // the file location
$con_type = "text/plain"; // the file mime type
$content_file = join("",file($file));
// define boundary
srand((double)microtime()*1000000);
$boundary = "---------------------------".substr(md5(rand(0,32000)),0,10);
$data = "--$boundary
Content-Disposition: form-data; name=\"file\"; filename=\"$file\"
Content-Type: $con_type
$content_file"."--$boundary--\r\n\r\n";
$msg =
"POST $remote_page HTTP/1.0
Content-Type: multipart/form-data; boundary=$boundary
Content-Length: ".strlen($data)."\r\n\r\n";
$f = fsockopen("127.0.0.1",80);
fputs($f,$msg.$data);
$result = fread($f,32000);
fclose($f);
print $result;
?>
Another usage of fsockopen to read content of specific url :
Without proxy :
<?php
$fp = fsockopen("www.wahoo.com",80);
fputs($fp, "GET http://www.yahoo.com/
HTTP/1.0\r\n\r\n");
$data="";
while (!feof($fp)) $data.=fgets($fp,64000);
fclose($fp);
print $data;
?>
With proxy :
<?php
$ip = "1.2.3.4"; // proxy IP, change this according to your proxy setting in your IE or NS
$port = 1234; // proxy port, change this according to your proxy setting in your IE or NS
$fp = fsockopen($ip,$port); // connect to proxy
fputs($fp, "GET http://www.yahoo.com/
HTTP/1.0\r\n\r\n");
$data="";
while (!feof($fp)) $data.=fgets($fp,64000);
fclose($fp);
print $data;
?>
With proxy and authentication :
<?php
$ip = "1.2.3.4"; // proxy IP, change this according to your proxy setting in your IE or NS
$port = 1234; // proxy port, change this according to your proxy setting in your IE or NS
$fp = fsockopen($ip,$port); // connect to proxy
$login = "alexander"; // login name
$passwd = "kiss me"; // password
fputs($fp, "GET http://www.yahoo.com/
HTTP/1.1\r\nHost:www.yahoo.com:80\r\nProxy-Authorization: Basic
".base64_encode("$login:$passwd") ."\r\n\r\n");
$data="";
while (!feof($fp)) $data.=fgets($fp,64000);
fclose($fp);
print $data;
?>
Alexander Yanuar Koentjara
System Developer
www.globalsources.com