/* 確保重定向后,后續(xù)代碼不會(huì)被執(zhí)行 */
exit;
?>
<?php
header("location;http://www.****.com");
?>
<?php
echo "<meta http-equals=refresh content='0;url=http://www.***.com'>";
?>
4.php 獲取當(dāng)前絕對(duì)路徑
<?php
??????? echo $_SERVER["DOCUMENT_ROOT"];
?>
jsp獲取當(dāng)前絕對(duì)路徑
String path = request.getRealPath("");
5.模擬HTTP 連線
<?php??
? $fp?? =?? fsockopen("m.tkk7.com",?? 80,?? &$errno,?? &$errstr,?? 10);??
? if(!$fp)?? {??
????????????????? echo?? "$errstr?? ($errno)<br>\n";??
? }?? else?? {??
????????????????? fputs($fp,"GET?? /?? HTTP/1.0\nHost:?? m.tkk7.com\n\n");??
????????????????? while(!feof($fp))?? {??
????????????????????????????????? echo?? fgets($fp,128);??
????????????????? }??
????????????????? fclose($fp);??
? }??
? ?>??
5.print_r(HTTPrequest('get',?? 'www.w3.org',?? '/'));?
沒有二級(jí)域名 以/代替
6.PHP 模擬POST GET
<?php
?print_r(HTTPrequest
('post','lnc.ep.duba.net','/***.aspx','ksn=*****));??
?function HTTPrequest($method,$host,$usepath,$postdata = "")??
?{??
??if(is_array($postdata))??
??{??
???foreach($postdata as $key=>$val)?
???{??
????if(!is_integer($key))??
????$data? .=? "&$key=".urlencode($val);??
???}??
???$data = substr($data,1);??
??}
??else??
??{??
???$data = $postdata;??
??}??
??$fp = fsockopen($host, 80, &$errno, &$errstr, 30);??
??if(!$fp)
??{??
???print "$errstr ($errno)<br>\n";??
???return false;??
??}??
??else
??{??
???if(strtoupper($method) == "GET")
???{??
????$headers = "GET $usepath HTTP/1.1\r\n";??
???}
???else if(strtoupper($method) == "POST")
???{??
????$headers = "POST $usepath HTTP/1.1\r\n";??
???}??
????$headers .= "Host:?? $host\n";??
????$headers .= "Connection:?? close\r\n";??
???//$headers?? .=?? "Accept-Encoding:?? gzip\r\n";??
???if(strtoupper($method) == "POST")??
???{??
????$strlength?? =?? strlen($data);??
????$headers?? .=?? "Content-Type:?? application/x-www-form-
urlencoded\r\n";??
????$headers?? .=?? "Content-Length:?? ".$strlength."\r\n";??
???}??
???$headers?? .=?? "\r\n";??
???$headers?? .=?? "$data\r\n";??
???fputs($fp,?? $headers);??
???while(!feof($fp))??
???{??
????$output[]?? =?? fgets($fp,?? 1024);??
???}??
???fclose(?? $fp);??
???return?? $output;??
??}??
?}??
?>
7.逐行讀取文件
<?php
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
??? while (!feof($handle)) {
??????? $buffer = fgets($handle, 4096);
??????? echo $buffer;
??? }
??? fclose($handle);
}
?>
8.取當(dāng)前路徑
echo?? dirname($_SERVER['SCRIPT_FILENAME']);??
:D:/kingsoft/KAN5/CONSOLE/trunk/src/V5WebConsole
echo $_SERVER['PHP_SELF'];
:/test.php
posted on 2007-12-24 01:56
-274°C 閱讀(814)
評(píng)論(3) 編輯 收藏 所屬分類:
PHP