当前位置:首页 » 编程语言 » phpagent

phpagent

发布时间: 2024-03-22 19:37:59

Ⅰ 怎么阻止百度蜘蛛查询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;
热点内容
linuxpython2与3共存 发布:2024-11-28 21:43:41 浏览:904
短视频平台上传视频规范 发布:2024-11-28 21:41:22 浏览:553
c语言统计素数的个数 发布:2024-11-28 21:38:24 浏览:837
我的世界服务器管理员没了怎么办 发布:2024-11-28 21:37:22 浏览:183
请求分段存储 发布:2024-11-28 21:23:20 浏览:458
zip伪加密 发布:2024-11-28 21:23:17 浏览:226
linuxshell路径 发布:2024-11-28 21:13:05 浏览:994
存储为web所用格式切片 发布:2024-11-28 21:11:23 浏览:452
服务器电脑主机怎么装 发布:2024-11-28 21:06:41 浏览:222
android调用aidl 发布:2024-11-28 21:05:46 浏览:867