1. Which network protocol does nginx use?
nginx is the application layer. I think from bottom to top, the transport layer uses tcp/ip and the application layer uses http.
fastcgi is responsible for scheduling processes
2. echo 'hello tusheng' ; ?> There is no output result, what may be the reason, and a brief process of solving this problem (tip: there is no problem with the syntax)
Maybe the short tag is not enabled on the server. short_open_tag = is set to Off, and the short tag control parameter is enabled in php.ini: short_open_tag = On
3. Briefly describe the output results of the following program, briefly explain why and how Solve this kind of problem?
$tmp = 0 == "a"? 1: 2;
echo $tmp;
?>
Result 1 is caused by forced conversion of int and string types, 0==="a"
0 == 0 must be true
PHP is a weak type. .
$tmp = 0 === "a"? 1: 2;
echo $tmp; This is 2
4. A string is known As follows: $str = "1109063 milo 1";
Use one line of code to assign 1109063 in the string to $uid, milo to $user, 1 to $type
space As follows
list($uid, $user, $type) = explode(" ", $str);
t is as follows
list($uid, $user, $type) = explode("t" , $str);
list($uid, $user, $type) = sscanf($str, "%d %s %d");
$n = sscanf($auth, "%dt%s %s", $id, $first, $last);
5. List the following types of signed and unsigned ranges respectively 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. Assemble the following array into a string i am milo! day day up!
$arr = array(
'I', 'AM', ' MILO!', 'DAY', 'DAY', 'UP!'
);
?>
$str = strtolower(implode(" ",$arr)) ;
7. Call the following function to get the function and get the value of count
function get_list($cnd = array(), &$count = false)
{
// Pseudocode processes $cnd and assigns datas
$datas = 'i am call back';
$count && $count = rand(1, 10000);
return $datas ;
}
?>
$count=1;
$data = get_list($cnd,&$count);
echo $count;
8. Several ways to replace the session mechanism, briefly describing the advantages and disadvantages of each
mysql, memcache, and cookie maintain a unique status identification code
9. Possible reasons for the following HTTP status codes, how to deal with them
200, 301, 404, 502, 503
200
The request was successful, the requested response was requested Headers or data body will be returned with this response.
301
The requested resource has been permanently moved to a new location, and any future references to this resource should use one of several URIs returned in this response. If possible, clients with link editing capabilities should automatically modify the requested address to the address returned from the server. Unless otherwise specified, this response is also cacheable. The new persistent URI should be returned in the Location field of the response. Unless this is a HEAD request, the response entity should contain a hyperlink to the new URI and a brief description. If this is not a GET or HEAD request, the browser prohibits automatic redirection unless confirmed by the user, because the conditions of the request may change accordingly. Note: For some browsers that use the HTTP/1.0 protocol, when the POST request they send receives a 301 response, the subsequent redirect request will become a GET method.
404
The request failed. The requested resource was not found on the server. There is no information to tell the user whether the condition is temporary or permanent. If the server knows the situation, it should use the 410 status code to inform that the old resource is permanently unavailable due to some internal configuration mechanism problems, and there is no jump address. The 404 status code is widely used when the server does not want to reveal why the request was rejected or no other suitable response is available.
502
When a server working as a gateway or proxy attempted to perform a request, it received an invalid response from the upstream server.
503
Due to temporary server maintenance or overload, the server is currently unable to process the request. This condition is temporary and will be restored after a period of time. If a delay can be expected, the response can include a Retry-After header to indicate the delay. If this Retry-After message is not given, the client SHOULD handle it the same way it handles a 500 response. Note: The existence of the 503 status code does not mean that the server must use it when it is overloaded. Some servers simply wish to deny connections from clients.
200 OK Everything is fine, and the response documents for GET and POST requests follow.
301 Moved Permanently The document requested by the client is elsewhere. The new URL is given in the Location header. The browser should automatically access the new URL.
404 Not Found The resource at the specified location cannot be found. This is also a common response.
502 Bad Gateway When the server acts as a gateway or proxy, it accesses the next server to complete the request, but the server returns an illegal response.
503 Service Unavailable The server failed to respond due to maintenance or overload. For example, a Servlet may return 503 when the database connection pool is full. The server can provide a Retry-After header when returning 503.
10. There is the following database, use the original mysql extension to connect and query the first ten rows of the user table
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. Use autoload($class) to realize automatic loading of classes in the Lib directory and be compatible with subdirectories
$ 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. Use set_error_handle to capture errors and output them. The level is determined by yourself
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. Briefly describe two methods of shielding notice warnings from php programs
Initialize variables, set the error level at the beginning of the file or modify php.ini to set error_reporting
set_error_handler and @ suppress errors
1. Add: error_reporting (E_ALL & ~E_NOTICE);
2. Or modify php.ini: error_reporting = E_ALL
changed to: error_reporting = E_ALL & ~E_NOTICE
3.error_reporting(0); or modify php.inidisplay_errors=Off
14. The role of instanceof, in what design patterns is it often used?
singleton mode, but other modes will also use
15. 1023 is represented in binary , and briefly describe the calculation process
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=
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
Simply multiply the digits in each bit of the binary number starting from the rightmost, and multiply the first number on the right by two To the power of zero, multiply the second number by two to the power of one, multiply the third number by two to the power of two, and so on to get the nth number multiplied by two to the power of (n-1), and then get Just add the results
For example: 110011=1*2^0+1*2^1+0*2^2+0*2^3+1*2^4+1*2^5=51
This can also be regarded as a formula, which is An*2^(n-1) An represents the n-th number starting from the rightmost side of the binary number.
The first, second, and third items all the way to the n-th item Use the formula An*2^(n-1) to calculate it and add it together
16. What is the output of the following php program? Why?
$str = "aatbbtcc";
@list($a, $b, $c) = explode('t', $str);
echo $a,$b ,$c;
?>
aabbcc;//'t' will not cut the string with t. After explode, it will create an array (0=>"aatbbtcc"), so . . ., 't' will be cut if replaced with "t"
17. What error levels do include and require return respectively?
include will give a system warning and continue execution, while require will Issue a system warning but cause a fatal error to terminate the script
18. There is an existing function with an uncertain number of parameters (maybe 5 or 50), how to define it? This function
Method 1: Without using PHP built-in functions
Method 2: Prompt 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 < $numargs ; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "
n";
}
}
param(1,2,3,4,5);
/**
2 * After I finished writing the example, I thought it was done, but I met someone asking about call_user_func_array() and read the manual
3 * It turns out that the test function I above can be simplified into the following example,
4*/
5 function otest1 ($a)
6 {
7 echo( 'One parameter' );
8 }
9
10 function otest2 ( $a,$b)
11 {
12 echo( 'Two Parameters' );
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. To handle global variables in a function (the function has no return statement) and change its value, use two methods to achieve it (global and reference &)
$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. In applications, we often encounter situations where 10 pieces of data are randomly retrieved from the user table for display. Brief description How do you implement this function? You cannot use sql functions and order by statements.
Table user fields uid, username
Estimate the interval in a user table, and use PHP to get a random number in this interval , if the sql statement is larger or smaller than this ID, limit dozens of items (guaranteed 10 pieces of data). If it is not scattered enough, the shuffle function of the retrieved data will disrupt the array, and array_rand will immediately take out 10
21 . Assume that the uid in the following sql statement can get the specific value. What is the order of uid after querying the following statement? How to sort according to the order of uid in input
select uid from user where uid in (10, 1, 3, 8, 11, 4, 7);
The impressive result is 1,3,4,7,8,10,11 in ascending order. There is a special situation that is uncertain because the middle Some of the IDs may not be in ascending order if they are directly modified manually. If you need to recycle according to the order of uid in, get the value in the query result array based on the ID and put it into a new array
22. Use PHP replaces letters in a string with **
preg_replace('/[a-zA-Z]*/','**',$str);
if specified The characters can be str_replace('ooxx','**',$str);
23. What is the printed result in 2.php below? Why? Execution sequence 1.php-> 2.php
There is a problem with cookie, cookie time time()+3600
24. Briefly describe the commonly used json encoding functions in php, How to return an array when decoding json
25. mysql When there are words such as ' / in the sql statement, what should be done to each specific value of the sql statement
mysql_real_escape_string
26. How to set header information in php
header('');
27. There are several scripts as follows. Please tell me the output of 2.php
1.php
setcookie('test', 'cookie_test', 3600);
?>
2.php
$cookie = isset($_COOKIE['test'])? $_COOKIE['test']: 'cookie';
echo $cookie;
?>
i am here
1
Summary
a. If include or include_once is not called in a function or method, output the result All the same.
b. If include or include_once is called in a function or method, you must use include instead of include_once if you want results to be generated on the second and subsequent calls. This must be noted.
28. Briefly describe the function of call_user_func
Call a function or a function in a class and return the value of the first parameter.Similar function call_user_func_array
29. Access assuming nginx has been configured server_name www.120.net xxx.120.net
Access http://www.120.net/index.php and After http://xxx.120.net/index.php
What are $_SERVER["SERVER_NAME"] and $_SERVER["REQUEST_URI"] respectively
www.120.net xxx .120.net
/index.php /index.php
30. The attribute of a file under Linux is drwxr-xr-x and the number indicates that its permission is
Directory permissions are 755. Owner u has read, write and modify permissions. Group g to which he belongs has read and modify permissions. Other than the group o belongs to, he has read and modify permissions.
31. Theoretically 1Mbps broadband What is the download speed in KBps? The calculation method is
1*1024/8
1M=1024KB
1KB=1024B
1B=8bit
Part 2
1. Simple implementation of a singleton + factory design pattern 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; // Static private class 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)) { //If no static private class instance is set, create it $c = __CLASS__; //Get the class name self:: $instance = new $c } return self::$instance; } // Example method public function bark() { echo 'Woof!'; } // Prevent users to clone the instance public function __clone() // Not allowed Clone { trigger_error('Clone is not allowed.', E_USER_ERROR);
}}Keywords:
1 Private static member variable
2 __CLASS__ gets the current class name
3 Public static method gets the list Example
4 Override the __clone() method
----Ten words: private static quantity, public static method--------
2. Example Several commonly used magic methods, and explain their functions? How to display our customized content when printing an object?
Magic function
1. __construct()
is called when instantiating an object.
When __construct and a function with the class name and function name exist at the same time, __construct will be called and the other will not be called.
2. __destruct()
Called when an object is deleted or the object operation terminates.
3. __call()
The object calls a certain method.
If the method exists, it will be called directly;
If it does not exist, the __call function will be called.
4. __get()
When reading the attributes of an object,
If the attribute exists, the attribute value will be returned directly;
If it does not exist, the __get function will be called.
5. __set()
When setting the attributes of an object,
If the attribute exists, the value will be assigned directly;
If it does not exist, the __set function will be called.
6. __toString()
Called when printing an object. Such as echo $obj; or print $obj;
7. __clone()
Called when cloning an object. For example: $t=new Test();$t1=clone $t;
8. __sleep()
is called before serialize. If the object is relatively large and you want to delete a few things before serializing, you can consider this function.
9. __wakeup()
is called when unserialize and does some object initialization work.
10. __isset()
Called when checking whether an object's attributes exist. For example: isset($c->name).
11. __unset()
Called when unsetting a property of an object. For example: unset($c->name).
12. __set_state()
Called when var_export is called. Use the return value of __set_state as the return value of var_export.
13. __autoload()
When instantiating an object, if the corresponding class does not exist, this method is called.
Magic Constants
1. __LINE__
Returns the current line number in the file.
2. __FILE__
Returns the full path and file name of the file. If used in an include file, returns the include file name. As of PHP 4.0.2, __FILE__ always contains an absolute path, while versions before that sometimes contained a relative path.
3. __FUNCTION__
Returns the function name (new in PHP 4.3.0). Since PHP 5 this constant returns the name of the function as it was defined (case sensitive). In PHP 4 this value is always lowercase.
4. __CLASS__
Returns the name of the class (new in PHP 4.3.0). Since PHP 5 this constant returns the name of the class when it was defined (case sensitive). In PHP 4 this value is always lowercase.
5. __METHOD__
Returns the method name of the class (newly added in PHP 5.0.0). Returns the name of the method as it was defined (case-sensitive).
3. Comparison and advantages and disadvantages of class static methods and instantiated class methods
4. There is a forum
threads table records topic and title information
posts table records topic content As well as information such as reply content
The primary key of the threads table is tid
The primary key of the posts table is pid, and the topic tag is tid
Associate threads and posts one-to-many through tid
Now the data volume posts is expressed 100 million, the threads table is 20 million, and there are about 5 replies for one topic
Please design a sub-table and divide the posts table and threads table into mysql tables
5. Now there is a mysql main database/ Congku, how to achieve master-slave separation in PHP program when querying PHP mysql? What are the benefits of master-slave separation? Configure the master-slave array file, transfer several model functions by yourself, load the slave configuration and instantiate the query, and destroy the data. The operation loads the master for instantiation. Advantages: The concurrent load capacity is improved, which is beneficial to data maintenance and security, and improves availability. Disadvantages: There is some delay in data synchronization
6. Briefly describe the single sign-on mechanism of UCenter
The so-called single sign-on , it is nothing more than several sites sharing a user center to achieve synchronous login and synchronous exit.
In fact, it is the user who logs in in the end, but ajax is used (javascript uses src to make asynchronous cross-domain calls) and the user will not notice.
And it is implemented using p3p headers, different domain names, single sign-on (cookie used by ucenter)
The disadvantage is that it uses ajax client request. If there are more than 10 applications, the login speed will be slow. Slowed down.
7. There is a Linux-related package http://www.120.net/test-1.0.0.tar.gz
a. Download it to /usr/local/src
b. Compile and install its source code into the /usr/local/test directory
c. It relies on the mysql package, which is located in the /usr/local/mysql directory
Write out the download, compilation and installation process
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. Written using PHP’s memcache extension A function to get data (the cache is about to expire, timeout and lock)
a. After the data times out, go to mysql to get it, and update memcache after getting it.
b. When going to mysql to get the data, lock it, and let a process go to mysql to pull it. data, others return the data in 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 . Briefly describe the principles of queues and stacks
can be regarded as one-dimensional arrays to operate. Queues are first in, first out, dequeuing can only be at the head of the column, and enqueueing can only be at the end of the column. Stack It is last in first out, and the stack is pushed and popped from the top of the stack
What is the working principle of the stack?
The stack is an abstract data structure, and its operations The mechanism is last in, first out. When you push a new item onto the stack, any items already on the stack are pushed deeper into the stack. Likewise, removing an item from the stack causes all other items in the stack to move toward the top of the stack. Only the topmost item on the stack can be removed from the stack, and items leave the stack in the same order in which they were pushed onto the stack. You might as well think back to the loading and picking up process of a vending machine to understand.
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; } /*** Implement four methods * offsetExists(), used to identify whether an element has been defined * offsetGet(), used to return the value of an element * offsetSet(), used to set a new value for an element * offsetUnset(), used to Delete an element and corresponding value **/ 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时,呈现的页面却不相同,这是何原理? 如果能给出实际解决方案,可加分。
You can simply use user_agent to judge, but it is very preliminary
If possible, you can use server or mobile terminal characteristics or wap gateway accept information, etc.
16. What should the magic_quotes_gpc and magic_quotes_runtime values in the production environment php.ini be set to? onoff17. File_get_contents can be used when PHP calls the remote http interface. However, when the remote host is unreachable or the response is too slow, it will cause the local PHP process to be suspended for a long time, thus affecting the stability of the local server. How to avoid timeout when the PHP process takes a long time? Suspended?
file_get_contents can set the timeout $ctx = stream_context_create(array( 'http' => array( 'timeout' => 1
)
)
);
file_get_contents("http://www.want.com/", 0, $ctx);
curl can also be used to obtain the remote http interface, and the timeout also needs to be set Time curl_setopt($s,CURLOPT_TIMEOUT,$timeout);
18. Same as the above question, how to avoid DNS query being too slow and causing timeout? 19. Which system variables are set by the mysql character set set names * command? (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. Which of the following collation rules is not case-sensitive? (A) A. utf8_general_ci B. utf8_general_cs C. utf8_general_bin21. How to prevent XSS attacks?
strip_tags can be initially filtered, or you can write your own filter function to process special tags and replace them with ascii codes. 23. How to prevent CSRF attacks?
To defend against CSRF vulnerabilities on the web application side, referer, token or verification code are generally used. The tokenf method is still more trustworthy.