PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php面试题分享,php试题分享

原创
2016-06-13 08:55:43 2101浏览

php面试题分享,php试题分享

1.nginx使用哪种网络协议? 
nginx是应用层 我觉得从下往上的话 传输层用的是tcp/ip 应用层用的是http 
fastcgi负责调度进程 
2. echo 'hello tusheng' ; ?> 没有输出结果, 可能是什么原因, 简述的解决此问题的过程(提示: 语法没有问题)
可能服务器上面没有开启短标签short_open_tag =设置为off,,php.ini开启短标签控制参数: short_open_tag = on 
3. 简述下面程序的输出结果, 简要说明为什么, 如何解决这类问题? 
$tmp = 0 == "a"? 1: 2; 
echo $tmp; 
?> 
结果 1 int和string类型强制转换造成的,0==="a" 
0 == 0 肯定是true啊 
php是弱类型。。 
$tmp = 0 === "a"? 1: 2; 
echo $tmp; 这样就是2 
4. 已知一个字符串如下: $str = "1109063 milo 1"; 
用一行代码将该字符串里面的1109063赋值给$uid, milo赋值给$user, 1赋值给$type 
空格如下 
list($uid, $user, $type) = explode(" ", $str); 
\t如下 
list($uid, $user, $type) = explode("\t", $str); 
list($uid, $user, $type) = sscanf($str, "%d %s %d"); 
$n = sscanf($auth, "%d\t%s %s", $id, $first, $last); 
5. 分别列出如下类型的有符号和无符号范围 tinyint smallint mediumint int 
tinyint-2^7 - 2^7-10 ~ 2^8-1 
smallint-2^15 - 2^15-1 0 ~ 2^16-1 
mediumint-2^23 - 2^23-1 0 ~ 2^24-1 
int-2^31 - 2^31-1 0 ~ 2^32-1 
6. 将下面的数组用一行拼装成一个字符串i am milo! day day up! 
$arr = array( 
'i', 'am', 'milo!', 'day', 'day', 'up!' 
); 
?> 
$str = strtolower(implode(" ",$arr)); 
7. 调用如下函数获取函数并获取count的值 
function get_list($cnd = array(), &$count = false) 

// 伪代码 处理$cnd 并赋值datas 
$datas = 'i am call back'; 
$count && $count = rand(1, 10000); 
return $datas; 

?> 
$count=1; 
$data = get_list($cnd,&$count); 
echo $count; 
8. 几种方式去取代session机制, 简单描述各自的优劣 
mysql、memcache、cookie保持一种唯一状态标识码 
9. 下列http状态码出现的可能原因, 如何处理 
200, 301, 404, 502, 503 
200 
  请求已成功,请求所希望的响应头或数据体将随此响应返回。 
301 
  被请求的资源已永久移动到新位置,并且将来任何对此资源的引用都应该使用本响应返回的若干个 uri 之一。如果可能,拥有链接编辑功能的客户端应当自动把请求的地址修改为从服务器反馈回来的地址。除非额外指定,否则这个响应也是可缓存的。   新的永久性的 uri 应当在响应的 location 域中返回。除非这是一个 head 请求,否则响应的实体中应当包含指向新的 uri 的超链接及简短说明。   如果这不是一个 get 或者 head 请求,因此浏览器禁止自动进行重定向,除非得到用户的确认,因为请求的条件可能因此发生变化。   注意:对于某些使用 http/1.0 协议的浏览器,当它们发送的 post 请求得到了一个301响应的话,接下来的重定向请求将会变成 get 方式。 

404 
  请求失败,请求所希望得到的资源未被在服务器上发现。没有信息能够告诉用户这个状况到底是暂时的还是永久的。假如服务器知道情况的话,应当使用410状态码来告知旧资源因为某些内部的配置机制问题,已经永久的不可用,而且没有任何可以跳转的地址。404这个状态码被广泛应用于当服务器不想揭示到底为何请求被拒绝或者没有其他适合的响应可用的情况下。 
502 
  作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应。 
503 
  由于临时的服务器维护或者过载,服务器当前无法处理请求。这个状况是临时的,并且将在一段时间以后恢复。如果能够预计延迟时间,那么响应中可以包含一个 retry-after 头用以标明这个延迟时间。如果没有给出这个 retry-after 信息,那么客户端应当以处理500响应的方式处理它。   注意:503状态码的存在并不意味着服务器在过载的时候必须使用它。某些服务器只不过是希望拒绝客户端的连接。 
200 ok 一切正常,对get和post请求的应答文档跟在后面。 
301 moved permanently 客户请求的文档在其他地方,新的url在location头中给出,浏览器应该自动地访问新的url 
404 not found 无法找到指定位置的资源。这也是一个常用的应答。 
502 bad gateway 服务器作为网关或者代理时,为了完成请求访问下一个服务器,但该服务器返回了非法的应答。 
503 service unavailable 服务器由于维护或者负载过重未能应答。例如,servlet可能在数据库连接池已满的情况下返回503。服务器返回503时可以提供一个retry-after头。 
10. 有如下数据库, 用原生态mysql扩展去连接并查询user表的前十行 
host: 192.168.0.254 
port: 3306 
user: one 
pass: piece 
database: db_user 
table: user 
$link = mysql_connect("192.168.0.254:3306","one","piece") or die('could not connect: '.mysql_error()); 
mysql_select_db('db_user',$link); 
$query = mysql_query("select * from user limit 10"); 
while($rs = mysql_fetch_array($query,mysql_assoc)) 
{} 

11. 用autoload($class) 实现lib目录下的类的自动加载并可以兼容子目录 
$request->action = lcfirst(implode(array_map( 
'ucfirst', 
explode('-', strtolower($request->action)) 
))); 
------------------------------------------------------------ 
function __autoload($class) 

$cls = strtolower(str_replace("_","/",$class)); 


if(file_exsits(lib.$cls.'.php')) 

include_once(lib.$cls.'.php'); 

else 

die("not found {$class} class"); 


defined("lib",'/data/wwwroot/www.xx.com/lib/'); 
$author = new lib_author(); 
----------------------------------------------------------- 
function __authload($class) 

$cls = explode("_",$class); 
if(@is_dir($cls[1])) 

if(@is_file($cls[2])) 

include_once("con_path".$cls[1].'/'.$cls[2].".php"); 

else 

dir('error'); 


else if(@is_file($cls[1].".php")) 

include_once("con_path".$cls[1].".php"); 

else 

dir('error'); 


--------------------------------------- 
function __autoload($class) 

$cls = explode("_",$class); 
$file = get_file($cls); 
if($file=='error') 

die('error'); 

include_once($file); 

function get_file($dir) 

if(is_array($dir)) 

foreach($dir as $k=>$v) 

$tmpdir .= $v.'/'; 
if(is_dir('con_path'.$tmpdir)) 

continue(); 

else if(is_file('con_path'.$tmpdir.".php")) 

return 'con_path'.$tmpdir.".php"; 

else 

return 'error'; 


return 'error'; 

return 'error'; 



defined("con_path","/data/wwwroot/www.xx.com/app/cntroller/"); 
$sb = new controller_sb(); 
------------------------------------ 
function __autoload_my_classes($classname) 

# ... your logic to include classes here 

spl_autoload_register('__autoload_my_classes'); 
----------------------------------------------------------- 
12. 用set_error_handle 去捕获错误并输出, 级别自己定 
set_error_handle(callback,level) 
function callback(int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] ){ 

function dealerrorhandler($errno,$errstr,$errfile,$errline) 

switch($errno){ 
case e_user_error: 
echo "error [$errno] $errstr fatal error on line $errline in file $errfile"; 
break; 
case e_user_warning: 
echo "my warning [$errno] $errstr": 
break; 
case e_user_notice: 
echo "my notice[$errno] $errstr"; 
break; 
default: 
echo "unkonwn error type :[$errno] $errstr"; 
break; 


set_erro_handler(dealerrorhandler); 
trigger_error("notice", e_user_notice); 
trigger_error("warning", e_user_warning); 
trigger_error("error", e_user_error); 
13. 简述两种屏蔽php程序的notice警告的方法 
初始化变量,文件开始设置错误级别或者修改php.ini 设置error_reporting 
set_error_handler 和 @抑制错误 
1.在程序中添加:error_reporting (e_all & ~e_notice); 
2.或者修改php.ini中的:error_reporting = e_all 
改为:error_reporting = e_all & ~e_notice 
3.error_reporting(0);或者修改php.inidisplay_errors=off 
14. instanceof的作用, 经常在什么设计模式中使用 
单例模式,但是其他的模式也会用到 
15. 1023用二进制表示, 并简述计算过程 
10-2 
1023%2=1 
511%2 =1 
255%2 =1 
127%2 =1 
63%2 =1 
31%2 =1 
15%2 =1 
7%2 =1 
3%2 =1 
1%2 =1 
0 =0 
------------------------------------------- 
1023 
2^9=511 

k=9 
10 9 8 7 6 5 4 3 2 1 
1 1 1 1 1 1 1 1 1 1 
---------------------- 
1023 1 
1023-1/2=511 1 
511-1/2=255 1 
255-1/2=127 1 
127-1/2=63 1 
63-1/2=31 1 
31-1/2=15 1 
15-1/2=7 1 
7-1/2=3 1 
3-1/2=1 1 
----------------------------------------------- 
2-10 
只需用将二进制数的各个位上的数从最右边开始,最右边的第一个数乘以二的零次方,第二个数乘以二的一次方,第三个数乘以二的二次方,依次类推可得第n个数乘以二的(n-1)次方,然后把得到的结果相加即可 
例如:110011=1*2^0+1*2^1+0*2^2+0*2^3+1*2^4+1*2^5=51 
这也可以算是一个公式就是an*2^(n-1) an表示二进制数最右边开始的第n个数, 
将第一项第二项第三项一直到第n项用式子an*2^(n-1) 计算出来并加在一起即可 
16. 下面php程序输出的内容是什么? 为什么? 
$str = "aa\tbb\tcc"; 
@list($a, $b, $c) = explode('\t', $str); 
echo $a,$b,$c; 
?> 
aabbcc;//'\t'不会以\t切割字符串,explode之后申城一个array(0=>"aa\tbb\tcc")所以。。。,'\t'换成"\t"就被切割
17. include和require 分别返回什么错误级别 
include会系统警告并继续执行,require会发出系统警告但是会引致致命错误令脚本终止运行 
18. 现有一个函数, 有不确定多少个的参数(可能有5个也可能有50个), 如何去定义这个函数 
方法一: 不借助php内置函数 
方法二: 提示func_num_args() func_get_arg() unc_get_args() 
function param() 

$numargs = func_num_args(); 
echo "number of arguments: $numargs
\n"; 
if ($numargs >= 2) { 
echo "second argument is: " . func_get_arg(1) . "
\n"; 

$arg_list = func_get_args(); 
for ($i = 0; $i echo "argument $i is: " . $arg_list[$i] . "
\n"; 


param(1,2,3,4,5); 
/** 
2 * 例子写完后,本来认为完事了,结果遇到有人问call_user_func_array(),看了一下手册 
3 * 原来,我上面的那个test函数还可以精简成如下的例子, 
4 */ 
5 function otest1 ($a) 
6 { 
7 echo( '一个参数' ); 
8 } 

10 function otest2 ( $a,$b) 
11 { 
12 echo( '二个参数' ); 
13 } 
14 
15 function otest3 ( $a,$b,$c) 
16 { 
17 echo( '三个啦' ); 
18 } 
19 
20 function otest () 
21 { 
22 $args=func_get_args(); 
23 $num=func_num_args(); 
24 call_user_func_array( 'otest'.$num,$args ); 
25 } 
26 
27 otest(1,2); 
19. 在一个函数(该函数没有return语句)里面去处理全局变量, 并且改变他的值, 用两种方法去实现(global和引用&) 
$var=1; 
function get_pra() 

global $var; 
$var = 'xxx'; 
echo $var; 

echo $var.'--'; 
get_pra(); 
echo $var; 
---------------------------------- 
$test = 1; 
$test1 = 2; 
function get_yinyong() 

global $test1; 
$globals["test"] = &$test1; 

echo $test."\n"; 
get_yinyong(); 
echo $test; 
---------------------------- 
20. 应用中我们经常会遇到在user表随机调取10条数据来展示的情况, 简述你如何实现该功能, 不能使用sql函数以及order by等语句 
表 user 字段uid, username 

估计一个user表中的区间,在此区间用php去一个随机数,sql语句大于或者小于此id去limit几十条(保证10条数据),再不够散乱的话,取出来的数据shuffle函数打乱数组,array_rand随即取出10个 
21. 假设下面的sql语句里面的uid都能获取到具体值, 经过下面语句查询后uid的顺序是什么, 如何去按照uid in 输入的顺序去排序 
select uid from user where uid in(10, 1, 3, 8, 11, 4, 7); 
可观的结果是1,3,4,7,8,10,11升序,有种情况特殊就是不确定因为中间的某些id人为直接修改可能不是升序了,如果按照uid in的顺序需要重新循环一次根据id获取查询结果数组中的值放进新数组中即可 
22. 用php将一个字符串中的字母替换成** 
preg_replace('/[a-za-z]*/','**',$str); 
如果指定的字符就可以str_replace('ooxx','**',$str); 
23. 下面2.php中打印结果是什么? 为什么? 执行顺序1.php->2.php 
cookie,cookie时间就有问题time()+3600 
24. 简述php常用的json编码函数, 如何将json解码的时候返回数组 
25. mysql 在sql语句中有' / 等词的时候, 要对sql语句的每个具体值做些什么处理 
mysql_real_escape_string 
26. 如何在php中设置header头信息 
header(''); 
27.有如下几个脚本, 请问2.php的输出结果 
1.php 
setcookie('test', 'cookie_test', 3600); 
?> 
2.php 
$cookie = isset($_cookie['test'])? $_cookie['test']: 'cookie'; 
echo $cookie; 
?> 
i am here 

总结 
a.如果include或include_once不是在函数或方法中被调用,则输出结果均一样。 
b.如果include或 include_once在函数或方法中被调用,则如果想让第二次及以后调用时有结果,则必须用include,而不能用include_once,这一点一定要注意。 
28. 简述call_user_func的功能 
调用函数或者类里面的函数,返回第一个参数的值。类似的功能call_user_func_array 
29. 访假设nginx已经配置server_name www.120.net xxx.120.net 
访问问http://www.120.net/index.php和http://xxx.120.net/index.php之后 
$_server["server_name"] 和 $_server["request_uri"]分别是什么 
www.120.net xxx.120.net 
/index.php /index.php 
30. linux下某文件的属性为 drwxr-xr-x 用数字表示其权限是 
目录权限为755所有者u拥有读写修改权限所属组g拥有读、修改权限所属组之外o的拥有读和修改权限 
31. 宽带的1mbps理论上的下载速度是多少kbps, 计算的方法 
1*1024/8 
1m=1024kb 
1kb=1024b 
1b=8bit
第二部分 
1. 简单实现一个单例+工厂的设计模式abstract class example{ // the parameterized factory method public static function factory($type) { if (include_once 'drivers/' . $type . '.php') { 
$classname = 'driver_' . $type; 
return new $classname; 
} else { 
throw new exception ('driver not found'); 

}}// load a mysql driver$mysql = example::factory('mysql'); 
// load a sqlite driver 
$sqlite = example::factory('sqlite'); 
definded('driver','/data/wwwroot/www.want.com/core/driver/');abstract class example(){ private function __construct() { } public static function factory($type) { if(include_once(driver.$type.'.php')) { return exampleson::singleton($type); } else { throw new exception("driver is not found!"); } } }class exampleson implements example{ // hold an instance of the class private static $instance; //静态私有的类实例 // a private constructor; prevents direct creation of object private function __construct() { echo 'i am constructed'; } // the singleton method public static function singleton() { if (!isset(self::$instance)) { //如果没有设置静态私有类实例,创建之 $c = __class__; //获得类名称 self::$instance = new $c } return self::$instance; } // example method public function bark() { echo 'woof!'; } // prevent users to clone the instance public function __clone() //不允许被克隆 { trigger_error('clone is not allowed.', e_user_error); 
}}关键词: 
1 私有静态成员变量 
2 __class__获取当前类名 
3 公共静态方法获取单例 
4 覆盖__clone()方法 
----十个字:私有静态量,公共静态法-------- 
2. 例举几个常用的魔术方法, 并说明作用? 如何在打印一个对象的时候展示我们自定义的内容? 
魔术函数 
1。__construct() 
实例化对象时被调用, 
当__construct和以类名为函数名的函数同时存在时,__construct将被调用,另一个不被调用。 
2。__destruct() 
当删除一个对象或对象操作终止时被调用。 
3。__call() 
对象调用某个方法, 
若方法存在,则直接调用; 
若不存在,则会去调用__call函数。 
4。__get() 
读取一个对象的属性时, 
若属性存在,则直接返回属性值; 
若不存在,则会调用__get函数。 
5。__set() 
设置一个对象的属性时, 
若属性存在,则直接赋值; 
若不存在,则会调用__set函数。 
6。__tostring() 
打印一个对象的时被调用。如echo $obj;或print $obj; 
7。__clone() 
克隆对象时被调用。如:$t=new test();$t1=clone $t; 
8。__sleep() 
serialize之前被调用。若对象比较大,想删减一点东东再序列化,可考虑一下此函数。 
9。__wakeup() 
unserialize时被调用,做些对象的初始化工作。 
10。__isset() 
检测一个对象的属性是否存在时被调用。如:isset($c->name)。 
11。__unset() 
unset一个对象的属性时被调用。如:unset($c->name)。 
12。__set_state() 
调用var_export时,被调用。用__set_state的返回值做为var_export的返回值。 
13。__autoload() 
实例化一个对象时,如果对应的类不存在,则该方法被调用。 
魔术常量 
1。__line__ 
返回文件中的当前行号。 
2。__file__ 
返回文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自 php 4.0.2 起,__file__ 总是包含一个绝对路径,而在此之前的版本有时会包含一个相对路径。 
3。__function__ 
返回函数名称(php 4.3.0 新加)。自 php 5 起本常量返回该函数被定义时的名字(区分大小写)。在 php 4 中该值总是小写字母的。 
4。__class__ 
返回类的名称(php 4.3.0 新加)。自 php 5 起本常量返回该类被定义时的名字(区分大小写)。在 php 4 中该值总是小写字母的。 
5。__method__ 
返回类的方法名(php 5.0.0 新加)。返回该方法被定义时的名字(区分大小写)。 
3. 类静态方法和实例化类方法比较及优缺点 
4. 有一个论坛 
threads表记录主题以及标题等信息 
posts表记录主题内容以及回复内容等信息 
threads 表主键为 tid 
posts 表主键为 pid, 所属主题标记为tid 
通过tid将threads和posts 一对多关联起来 
现在数据量posts表达到了1亿, threads表2000万, 大约一个主题有5篇回复 
请你设计一下分表, 将posts表和threads表进行mysql分表 
5. 现在有一个mysql 主库/丛库, 请问php mysql查询的时候怎么在php程序中实现主从分离? 主从分离有什么好处配置主从数组文件,自己封转几个model函数,查询的加载slave配置实例化,破坏数据的操作加载master进行实例化优点:并发负载能力提高,利于数据维护和安全,提高可用性缺点:数据同步有些延迟 
6. 简述ucenter的单点登录机制 
所谓单点登录,无非就是几个站点共用一个用户中心,实现同步登陆,同步退出。 
其实最终还是用户去登录,只是采用了ajax (javascript利用src异步跨域调用)用户不会发现。 
而且利用了p3p头实现了,不同域名,单点登录(ucenter用的cookie) 
缺点就是采用ajax 客服端请求 ,如果有10个以上应用,登录速度就慢下来了。 
7. linux相关 有一个包 http://www.120.net/test-1.0.0.tar.gz 
a. 将它下载到/usr/local/src 
b. 将其源码编译安装到/usr/local/test 目录 
c. 他依赖mysql包, 位于/usr/local/mysql 目录 
写出下载编译安装过程 
wget - c http://www.120.net/test-1.0.0.tar.gz/usr/local/srctar zxvf /usr/local/src/test-1.0.0.tar.gzcd /usr/local/src/test-1.0.0./configure --prefix=/usr/local/test --exec--prefix=/usr/local/mysqlmake testmake install 
8. 使用php 的memcache扩展编写一个获取数据的函数(缓存即将过期超时加锁) 
a. 数据超时之后去mysql获取, 获取完后更新memcache 
b. 去mysql获取数据的时候加锁, 让一个进程去mysql拉数据, 其他人返回memcache中的数据 
public function get_cache($key) { if($this->memcahe) { $var = $this->memcahe->get($this->pre.$key); $valid = $this->memcahe->get($this->pre.$key.'_valid'); if($var && !$valid) { $lock = $this->memcahe->get($this->pre.$key.'_lock'); if(!$lock) { $this->memcahe->set($this->pre.$key.'_lock', true, 0, 60); return false; } } return $var; } return false; } 
public function set_cache($key, $var = null, $expire = 0) { if($this->memcahe) { $expire = (int)$expire; $expire = ($expire ? $expire : $this->expire); $this->memcahe->set($this->pre.$key, $var, 0, $expire+300); $this->memcahe->set($this->pre.$key.'_lock', false, 0, $expire); $this->memcahe->set($this->pre.$key.'_valid', true, 0, $expire); return true; } return false; } 
9. 简述队列, 堆栈的原理 
都可以看做是一维数组来操作,队列先进先出,出列只能在列头,进列只能在列尾,堆栈是后进先出,进栈和出栈都是从栈顶 
堆栈的工作原理是什么? 
堆栈是一种抽象数据结构,其操作机理是后进先出。当你把新条目推进堆栈时,已经在堆栈内的任何条目都会压到堆栈的深处。同样的,把一个条目从堆栈移出则会让堆栈内的其他条目都向堆栈的顶部移动。只有堆栈最顶端的条目能从堆栈中取出,条目离开堆栈的顺序和它们被推进堆栈的顺序一样。你不妨回想下自动售货机的装货和取货过程就明白了。 
10. arrayaccess 定义如下 用它实现一个数组 
arrayaccess { 
/* methods */ 
abstract public boolean offsetexists ( string $offset ) 
abstract public mixed offsetget ( string $offset ) 
abstract public void offsetset ( string $offset , string $value ) 
abstract public void offsetunset ( string $offset ) 

class single implements arrayaccess{ private $name; private static $_instance = null; private function __construct() { } static function load() { if(null == self::$_instance) { self::$_instance = new single(); } return self::$_instance; } public function setname($name) { $this->name = $name; } public function getname() { return $this->name; } /** * 实现四个方法 * offsetexists(),用于标识一个元素是否已定义 * offsetget(),用于返回一个元素的值 * offsetset(),用于为一个元素设置新值 * offsetunset(),用于删除一个元素和相应的值 **/ public function offsetset($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetget($offset) { return isset($this->container[$offset]) ? $this->container[$offset] : null; } public function offsetexists($offset) { return isset($this->container[$offset]); } public function offsetunset($offset) { unset($this->container[$offset]); }}$s = single::load();$s->setname("jack");$s["name"] = "mike";echo $s->getname(); //jackecho $s["name"]; //mike 
11. 假设coreseek安装目录为/usr/local/coreseek 
配置文件为/usr/local/coreseek/etc/test.conf 
索引名为 post 
a. 创建索引 
b. 启动服务 
c. 重建索引(重建过程中保证搜索服务仍然可用) 
indexer -c /usr/local/coreseek/etc/test.conf --allsearchd -c /usr/local/coreseek/etc/test.conf indexer -c /usr/local/coreseek/etc/test.conf --all --rotate12. 假设您有一张posts帖子表 对该表进行sphinx增量准实时索引, 描述你的方案 
使用“主索引+增量索引”方法有个简单的实现,在数据库中增加一个计数表,记录每次重新构建主索引时,被索引表的最后一个数据id,这样在增量索引时只需要索引这个id以后的数据即可,每次重新构建主索引时都更新这个表。 
13. php代码: 
$i = 97;$a = ($i++) + (++$i) + $i ;$b = (--$i) + ($i--) + $i + 6; 
echo "$i, $a, $b";输出结果是什么 
97, 295, 299 
97 
97+99+99 
98+98+97+6 
14. 以下代码,用于取得客户端ip: if(getenv('http_client_ip') && strcasecmp(getenv('http_client_ip'), 'unknown')) { $onlineip = getenv('http_client_ip');} elseif(getenv('http_x_forwarded_for') && strcasecmp(getenv('http_x_forwarded_for'), 'unknown')) { $onlineip = getenv('http_x_forwarded_for');} elseif(getenv('remote_addr') && strcasecmp(getenv('remote_addr'), 'unknown')) { $onlineip = getenv('remote_addr');} elseif(isset($_server['remote_addr']) && $_server['remote_addr'] && strcasecmp($_server['remote_addr'], 'unknown')) { $onlineip = $_server['remote_addr'];}但是以http_开始的请求header均属于客户端可以伪造的信息,在反向代理环境下,如何保证php不会接收到伪造的http_client_ip, http_x_forwarded_for值? 
15. 例如google,baidu等大型网站,当使用不同客户端(如手机和pc机)访问同样的url时,呈现的页面却不相同,这是何原理? 如果能给出实际解决方案,可加分。 
简单的可以用user_agent判断,但是及其初步 
可以的话通过服务器或者手机终端特征或者wap网关accept信息等 
16. 生产环境php.ini中magic_quotes_gpc及magic_quotes_runtime值应该设置为什么?onoff17. php调用远程http接口时可使用file_get_contents, 但当远程主机不可达或响应过慢,会导致本地php进程被长时间挂起,从而影响本地服务器稳定性,如何避免超时时,php进程长时间被挂起? 
file_get_contents可以设置下超时时间$ctx = stream_context_create(array( 'http' => array( 'timeout' => 1 


); 
file_get_contents("http://www.want.com/", 0, $ctx); 
curl实现获取远程http接口也可以,同样需要设置超时时间curl_setopt($s,curlopt_timeout,$timeout); 
18. 同上题,如何避免dns查询过慢导致超时?19. mysql字符集set names * 命令设置哪几个系统变量的值?(ace) a、character_set_client b、character_set_system c、character_set_results d、character_set_server e、character_set_connection f、character_set_database20. 以下哪种校对规则不区分大小写?(a) a、utf8_general_ci b、utf8_general_cs c、utf8_general_bin21. 如何杜绝xss攻击? 
strip_tags可以初步过滤,也可以自己写过滤函数针对特殊标签进行处理,用ascii码进行替换23. 如何杜绝csrf攻击? 
在web应用程序侧防御csrf漏洞,一般都是利用referer、token或者验证码,tokenf方式还是比较可信

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。