哪位大哥用过fsockopen函数 如果是报fsockopen函数未定义,那么就是被禁用了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 新网互联的PHP配置PHP Version 4.1.0 System Linux unix27 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown Build Date Apr 5 2002 Configure Command './configure' '--prefix=/usr' '--with-mysql=/usr/local/mysql' '--enable-force-cgi-redirect' '--enable-safe-mode' Server API CGI Virtual Directory Support disabled Configuration File (php.ini) Path /usr/local/Zend/etc/php.ini ZEND_DEBUG disabled Thread Safety disabled 我使用了一个类: require("include/http.class.php"); $thisHttp = new cHTTP(); $thisHttp->getPage("http://www.ytht.net"); $content = $thisHttp->getContent(); if ( $content != "" ) echo $content; else echo "test";该类相关代码为: class cHTTP { var $referer; var $postStr; var $retStr; var $theData; var $theCookies; var $proxy_host=""; var $proxy_port="0"; function clsHTTP(){ } function setReferer($sRef){ $this->referer = $sRef; } function addField($sName, $sValue){ $this->postStr .= $sName . "=" . $this->HTMLEncode($sValue) . "&"; } function clearFields(){ $this->postStr = ""; } function checkCookies(){ $cookies = explode("Set-Cookie:", $this->theData ); $i = 0; if ( count($cookies)-1 > 0 ) { while(list($foo, $theCookie) = each($cookies)) { if (! ($i == 0) ) { @list($theCookie, $foo) = explode(";", $theCookie); list($cookieName, $cookieValue) = explode("=", $theCookie); @list($cookieValue, $foo) = explode("\r\n", $cookieValue); $this->setCookies(trim($cookieName), trim($cookieValue)); } $i++; } } } function setCookies($sName, $sValue){ $total = count(explode($sName, $this->theCookies)); if ( $total > 1 ) { list($foo, $cValue) = explode($sName, $this->theCookies); list($cValue, $foo) = explode(";", $cValue); $this->theCookies = str_replace($sName . $cValue . ";", "", $this->theCookies); } $this->theCookies .= $sName . "=" . $this->HTMLEncode($sValue) . ";"; } function getCookies($sName){ @list($foo, $cValue) = explode($sName, $this->theCookies); @list($cValue, $foo) = explode(";", $cValue); return substr($cValue, 1); } // Cookie format: Name1 = Value1;<NameN = ValueN;> function getFirstCookieName(){ @list($cValue, $foo) = explode("=", $this->theCookies); return $cValue; } function getFirstCookieValue(){ @list($foo, $cValue) = explode("=", $this->theCookies); @list($cValue, $foo) = explode(";", $cValue); return $cValue; } // function clearCookies(){ $this->theCookies = ""; } function getContent(){ @list($header, $foo) = explode("\r\n\r\n", $this->theData); @list($foo, $content) = explode($header, $this->theData); return substr($content, 4); } function getHeaders(){ list($header, $foo) = explode("\r\n\r\n", $this->theData); list($foo, $content) = explode($header, $this->theData); return $header; } function getHeader($sName){ list($foo, $part1) = explode($sName . ":", $this->theData); list($sVal, $foo) = explode("\r\n", $part1); return trim($sVal); } function postPage($sURL){ $host = ""; $port = ""; if ( $this->proxy_host != "" ) { $request = $sURL; $host = $this->proxy_host; $port = $this->proxy_port; } else { $sInfo = $this->parseRequest($sURL); $request = $sInfo['request']; $host = $sInfo['host']; $port = $sInfo['port']; } $this->postStr = substr($this->postStr, 0, -1); //retira a ultima & $httpHeader = "POST $request HTTP/1.0\r\n";// $httpHeader .= "Host: $host\r\n";// $httpHeader .= "Connection: Close\r\n";// $httpHeader .= "User-Agent: cHTTP/0.1b (incompatible; M$ sucks; Open Source Rulez)\r\n"; $httpHeader .= "Content-type: application/x-www-form-urlencoded\r\n"; $httpHeader .= "Content-length: " . strlen($this->postStr) . "\r\n"; $httpHeader .= "Referer: " . $this->referer . "\r\n"; $httpHeader .= "Cookie: " . $this->theCookies . "\r\n"; $httpHeader .= "\r\n"; $httpHeader .= $this->postStr; $httpHeader .= "\r\n\r\n"; $this->theData = $this->downloadData($host, $port, $httpHeader); // envia os dados para o servidor $this->checkCookies(); } function getPage($sURL){ if ( $this->proxy_host != "" ) { $request = $sURL; $host = $this->proxy_host; $port = $this->proxy_port; } else { $sInfo = $this->parseRequest($sURL); $request = $sInfo['request']; $host = $sInfo['host']; $port = $sInfo['port']; } $httpHeader = "GET $request HTTP/1.0\r\n";// $httpHeader .= "Host: $host\r\n";// $httpHeader .= "Connection: Close\r\n"; $httpHeader .= "User-Agent: cHTTP/0.1b (incompatible; M$ sucks; Open Source Rulez)\r\n";// $httpHeader .= "Referer: " . $this->referer . "\r\n"; $httpHeader .= "Cookie: " . substr($this->theCookies, 0, -1) . "\r\n"; $httpHeader .= "\r\n\r\n"; $this->theData = $this->downloadData($host, $port, $httpHeader); } function parseRequest($sURL){ list($protocol, $sURL) = explode('://', $sURL); // separa o resto list($host, $foo) = explode('/', $sURL); // pega o host list($foo, $request) = explode($host, $sURL); // pega o request @list($host, $port) = explode(':', $host); // pega a porta if ( strlen($request) == 0 ) $request = "/"; if ( strlen($port) == 0 ) $port = "80"; $sInfo = Array(); $sInfo["host"] = $host; $sInfo["port"] = $port; $sInfo["protocol"] = $protocol; $sInfo["request"] = $request; return $sInfo; } /* changed 06/30/2003 */ function HTMLEncode($sHTML){ $sHTML = urlencode($sHTML); return $sHTML; } function downloadData($host, $port, $httpHeader){ echo "$host,$port<br>"; // FOR TEST ONLY $fp = @fsockopen($host, $port); $retStr = ""; if ( $fp ) { fwrite($fp, $httpHeader); echo "write!"; // FOR TEST ONLY while(! feof($fp)) { echo "read!"; // FOR TEST ONLY $retStr .= fread($fp, 1024); } fclose($fp); } else echo "open sock wrong!"; // FOR TEST ONLY return $retStr; } } // class php网站开发文档需要数据流程图吗? Linux cp 实现强行覆盖不了,在线等 分享一下经验,容易被忽视的session_commit php页面接收返回值的问题 php数组整理的问题 怎样把多个pdf文件压缩成一个zip文件?急!!!!!!! 弱弱的问个问题 急!!!高手一定来帮我看看啊!php里如何得到post的数据?急需帮助!! 被正则玩疯了,为什么$matches[0]为空? PHP正则验证密码 需要一个 将生成的HTML转化JS的类或者函数,谁有? 保存用户登录状态问题,希望得到大家的帮助!
PHP Version 4.1.0 System Linux unix27 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
Build Date Apr 5 2002
Configure Command './configure' '--prefix=/usr' '--with-mysql=/usr/local/mysql' '--enable-force-cgi-redirect' '--enable-safe-mode'
Server API CGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /usr/local/Zend/etc/php.ini
ZEND_DEBUG disabled
Thread Safety disabled
require("include/http.class.php"); $thisHttp = new cHTTP();
$thisHttp->getPage("http://www.ytht.net");
$content = $thisHttp->getContent();
if ( $content != "" )
echo $content;
else
echo "test";
该类相关代码为:
class cHTTP { var $referer;
var $postStr; var $retStr;
var $theData; var $theCookies;
var $proxy_host="";
var $proxy_port="0";
function clsHTTP(){ }
function setReferer($sRef){
$this->referer = $sRef;
}
function addField($sName, $sValue){
$this->postStr .= $sName . "=" . $this->HTMLEncode($sValue) . "&";
}
function clearFields(){
$this->postStr = "";
} function checkCookies(){
$cookies = explode("Set-Cookie:", $this->theData );
$i = 0;
if ( count($cookies)-1 > 0 ) {
while(list($foo, $theCookie) = each($cookies)) {
if (! ($i == 0) ) {
@list($theCookie, $foo) = explode(";", $theCookie);
list($cookieName, $cookieValue) = explode("=", $theCookie);
@list($cookieValue, $foo) = explode("\r\n", $cookieValue);
$this->setCookies(trim($cookieName), trim($cookieValue));
}
$i++;
}
}
} function setCookies($sName, $sValue){ $total = count(explode($sName, $this->theCookies)); if ( $total > 1 ) {
list($foo, $cValue) = explode($sName, $this->theCookies);
list($cValue, $foo) = explode(";", $cValue); $this->theCookies = str_replace($sName . $cValue . ";", "", $this->theCookies);
}
$this->theCookies .= $sName . "=" . $this->HTMLEncode($sValue) . ";";
} function getCookies($sName){
@list($foo, $cValue) = explode($sName, $this->theCookies);
@list($cValue, $foo) = explode(";", $cValue);
return substr($cValue, 1);
} // Cookie format: Name1 = Value1;<NameN = ValueN;>
function getFirstCookieName(){
@list($cValue, $foo) = explode("=", $this->theCookies);
return $cValue;
} function getFirstCookieValue(){
@list($foo, $cValue) = explode("=", $this->theCookies);
@list($cValue, $foo) = explode(";", $cValue);
return $cValue;
}
// function clearCookies(){
$this->theCookies = "";
}
function getContent(){
@list($header, $foo) = explode("\r\n\r\n", $this->theData);
@list($foo, $content) = explode($header, $this->theData);
return substr($content, 4);
} function getHeaders(){
list($header, $foo) = explode("\r\n\r\n", $this->theData);
list($foo, $content) = explode($header, $this->theData);
return $header;
} function getHeader($sName){
list($foo, $part1) = explode($sName . ":", $this->theData);
list($sVal, $foo) = explode("\r\n", $part1);
return trim($sVal);
} function postPage($sURL){
$host = "";
$port = "";
if ( $this->proxy_host != "" )
{
$request = $sURL;
$host = $this->proxy_host;
$port = $this->proxy_port;
}
else
{
$sInfo = $this->parseRequest($sURL);
$request = $sInfo['request'];
$host = $sInfo['host'];
$port = $sInfo['port'];
} $this->postStr = substr($this->postStr, 0, -1); //retira a ultima & $httpHeader = "POST $request HTTP/1.0\r\n";
// $httpHeader .= "Host: $host\r\n";
// $httpHeader .= "Connection: Close\r\n";
// $httpHeader .= "User-Agent: cHTTP/0.1b (incompatible; M$ sucks; Open Source Rulez)\r\n";
$httpHeader .= "Content-type: application/x-www-form-urlencoded\r\n";
$httpHeader .= "Content-length: " . strlen($this->postStr) . "\r\n";
$httpHeader .= "Referer: " . $this->referer . "\r\n";
$httpHeader .= "Cookie: " . $this->theCookies . "\r\n"; $httpHeader .= "\r\n";
$httpHeader .= $this->postStr;
$httpHeader .= "\r\n\r\n"; $this->theData = $this->downloadData($host, $port, $httpHeader); // envia os dados para o servidor $this->checkCookies();
} function getPage($sURL){
if ( $this->proxy_host != "" )
{
$request = $sURL;
$host = $this->proxy_host;
$port = $this->proxy_port;
}
else
{
$sInfo = $this->parseRequest($sURL);
$request = $sInfo['request'];
$host = $sInfo['host'];
$port = $sInfo['port'];
} $httpHeader = "GET $request HTTP/1.0\r\n";
// $httpHeader .= "Host: $host\r\n";
// $httpHeader .= "Connection: Close\r\n";
$httpHeader .= "User-Agent: cHTTP/0.1b (incompatible; M$ sucks; Open Source Rulez)\r\n";
// $httpHeader .= "Referer: " . $this->referer . "\r\n";
$httpHeader .= "Cookie: " . substr($this->theCookies, 0, -1) . "\r\n";
$httpHeader .= "\r\n\r\n"; $this->theData = $this->downloadData($host, $port, $httpHeader);
} function parseRequest($sURL){ list($protocol, $sURL) = explode('://', $sURL); // separa o resto
list($host, $foo) = explode('/', $sURL); // pega o host
list($foo, $request) = explode($host, $sURL); // pega o request
@list($host, $port) = explode(':', $host); // pega a porta if ( strlen($request) == 0 ) $request = "/";
if ( strlen($port) == 0 ) $port = "80"; $sInfo = Array();
$sInfo["host"] = $host;
$sInfo["port"] = $port;
$sInfo["protocol"] = $protocol;
$sInfo["request"] = $request; return $sInfo;
} /* changed 06/30/2003 */
function HTMLEncode($sHTML){
$sHTML = urlencode($sHTML);
return $sHTML;
} function downloadData($host, $port, $httpHeader){
echo "$host,$port<br>"; // FOR TEST ONLY
$fp = @fsockopen($host, $port);
$retStr = "";
if ( $fp ) {
fwrite($fp, $httpHeader);
echo "write!"; // FOR TEST ONLY
while(! feof($fp)) {
echo "read!"; // FOR TEST ONLY
$retStr .= fread($fp, 1024);
}
fclose($fp);
}
else
echo "open sock wrong!"; // FOR TEST ONLY
return $retStr;
} } // class