phpagent
Ⅰ 怎麼阻止百度蜘蛛查詢admin php文件
在網站根目錄添加robots.txt文件試試
格式為
User-agent: *
Disallow: /admin.php
Ⅱ 在 PHP 開發中如何判斷用戶是否使用手機
PHP通過內置全局變數$_SERVER['HTTP_USER_AGENT']來獲取用戶信息,包括瀏覽器信息,操作系統等;判斷是否是手機還是電腦終端訪問,只需判斷他的$_SERVER['HTTP_USER_AGENT']信息是否存在手機終端類型即可。示例如下:
<?php
//1.獲取用戶瀏覽器信息等;
$user_agent=$_SERVER['HTTP_USER_AGENT'];
//2.列舉常用手機終端類型
$mobile_agents=array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi",
"android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio",
"au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu",
"cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly",
"fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi",
"htc","huawei","hutchison","inno","ipad","ipaq","iphone","ipod","jbrowser","kddi",
"kgt","kwc","lenovo","lg","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo",
"mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-",
"moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia",
"nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-",
"playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo",
"samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank",
"sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit",
"tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin",
"vk-","voda","voxtel","vx","wap","wellco","wigbrowser","wii","windowsce",
"wireless","xda","xde","zte");
foreach($mobile_agentsas$device){
if(stristr($user_agent,$device)){
//手機訪問
$is_mobile=true;
break;
}
}
//判斷手機標識是否為真
if($is_mobile){
echo"手機訪問!";
}else{
echo"電腦訪問!";
}
?>
Ⅲ PHP判斷瀏覽器
用 $_SERVER["HTTP_USER_AGENT"] 取瀏覽器信息,里邊有瀏覽器的類型及版本
隨手網上搜的
<?php
if(strpos($_SERVER["HTTP_USER_AGENT"],」MSIE 8.0″))
echo 「Internet Explorer 8.0″; // 這里可以寫其他的執行命令
else if(strpos($_SERVER["HTTP_USER_AGENT"],」MSIE 7.0″))
echo 「Internet Explorer 7.0″;
else if(strpos($_SERVER["HTTP_USER_AGENT"],」MSIE 6.0″))
echo 「Internet Explorer 6.0″;
else if(strpos($_SERVER["HTTP_USER_AGENT"],」Firefox/3″))
echo 「Firefox 3″;
else if(strpos($_SERVER["HTTP_USER_AGENT"],」Firefox/2″))
echo 「Firefox 2″;
else if(strpos($_SERVER["HTTP_USER_AGENT"],」Chrome」))
echo 「Google Chrome」;
else if(strpos($_SERVER["HTTP_USER_AGENT"],」Safari」))
echo 「Safari」;
else if(strpos($_SERVER["HTTP_USER_AGENT"],」Opera」))
echo 「Opera」;
else echo $_SERVER["HTTP_USER_AGENT"];
?>
Ⅳ 在PHP中如何模擬HTTP_USER_AGENT
在curl里可以設置UA
<?php
//client
$ch=curl_init();
curl_setopt_array($ch,
array(
CURLOPT_URL=>'http://localhost/ua.php',
CURLOPT_USERAGENT=>"YeRenChai_v1.0",
CURLOPT_RETURNTRANSFER=>True,
CURLOPT_FOLLOWLOCATION=>True,
)
);
$response=curl_exec($ch);
if(!$response)exit(curl_error($ch));
var_mp($response);
?>
<?php//server
echo$_SERVER['HTTP_USER_AGENT'];
?>
Ⅳ 如何用php偽造瀏覽器ua
file_get_contents 和 curl 這倆強悍的函數,在遠程抓取時候相當有用處。不過一些網站會根據來訪ip是否攜帶user_agent來判斷是正常的瀏覽器客戶端還是機器。所以,我們的任務就是給他們偽造user_agent。
file_get_contents偽造user_agent 方法如下:
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;http://www..com)');
curl偽造user_agent的方法:
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;http://www..com)');
附帶上curl的完整函數方法:
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($c, CURLOPT_HEADER, 1);//輸出遠程伺服器的header信息
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;http://www..com)');
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) {return $contents;}
else {return FALSE;}
}
這樣就可以抓取了,user_agent是可以自己修改的。
Ⅵ php如何判斷當前的操作系統是linux還是windows
PHP判斷當前操作系統的方法很多,比如:
1.直接使用PHP預定義常量PHP_OS來獲取;
<?php
header("Content-type:text/html;charset=utf-8;");
$os_name=PHP_OS;
if(strpos($os_name,"Linux")!==false){
$os_str="Linux操作系統";
}elseif(strpos($os_name,"WIN")!==false){
$os_str="Windows操作系統";
}
echo$os_str;
2.還可以通過用戶瀏覽器信息來判斷操作系統。
<?php
header("Content-type:text/html;charset=utf-8;");
//測試
echoget_user_os();
//Windows操作系統
functionget_user_os(){
//獲取用戶瀏覽信息參數
$agent=$_SERVER['HTTP_USER_AGENT'];
//獲取操作系統類型
if(strpos($agent,"NT6.1")){
$os_name="Windows7";
}elseif(strpos($agent,"NT5.1")){
$os_name="WindowsXP(SP2)";
}elseif(strpos($agent,"NT5.2")&&strpos($agent,"WOW64")){
$os_name="WindowsXP64-bitEdition";
}elseif(strpos($agent,"NT5.2")){
$os_name="Windows2003";
}elseif(strpos($agent,"NT6.0")){
$os_name="WindowsVista";
}elseif(strpos($agent,"NT5.0")){
$os_name="Windows2000";
}elseif(strpos($agent,"4.9")){
$os_name="WindowsME";
}elseif(strpos($agent,"NT4")){
$os_name="WindowsNT4.0";
}elseif(strpos($agent,"98")){
$os_name="Windows98";
}elseif(strpos($agent,"95")){
$os_name="Windows95";
}elseif(strpos($agent,"Linux")){
$os_name="Linux";
}
//判斷
if(strpos($os_name,"Linux")!==false){
$os_str="Linux操作系統";
}elseif(strpos($os_name,"Windows")!==false){
$os_str="Windows操作系統";
}else{
$os_str="未知操作系統";
}
return$os_str;
}
3.使用php_uname函數來獲取;
<?php
header("Content-type:text/html;charset=utf-8;");
$os_name=php_uname();
if(strpos($os_name,"Linux")!==false){
$os_str="Linux操作系統";
}elseif(strpos($os_name,"Windows")!==false){
$os_str="Windows操作系統";
}
echo$os_str;