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 the process
2. echo 'hello tusheng' ; ?> There is no output result, what is the possible reason, and the process of solving this problem is briefly described (tip: there is no problem with the grammar)
Maybe the short tag is not turned on on the server. short_open_tag = is set to Off, and php.ini turns on the short tag. Tag control parameters: short_open_tag = On
3. Briefly describe the output results of the following program, briefly explain why, and how to solve this type of problem?
$tmp = 0 == "a"? 1: 2;
echo $tmp;
?>
Result 1 is caused by int and string type coercion, 0==="a"
0 == 0 must be true
PHP is a weak type. .
$tmp = 0 === "a"? 1: 2;
echo $tmp; This is 2
4. It is known that a string is as follows: $str = "1109063 milo 1";
Use one line of code to replace the character 1109063 in the string is assigned to $uid, milo is assigned to $user, 1 is assigned to $type
The spaces are 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 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 in one line 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)
{
// Pseudo code processes $cnd and assigns a value 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 describe the advantages and disadvantages of each
mysql, memcache, and cookie maintain a unique status identification code
9. The following HTTP status code appears Possible reasons, how to handle
200, 301, 404, 502, 503
200
The request has been successful, and the response header or data body expected by the request 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 permanent 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 using 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
A server working as a gateway or proxy received an invalid response from the upstream server when trying to perform a request.
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 to 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 Subdirectory
$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, set the level 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
Change to: error_reporting = E_ALL & ~E_NOTICE
3.error_reporting( 0); or modify php.inidisplay_errors=Off
14. The role of instanceof, what design patterns are often used in
Single case mode, but other modes will also use
15. 1023 is expressed in binary, and the calculation process is briefly described
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
Just use the numbers on each digit of the binary number starting from the rightmost, multiply the first number on the right by two to the power of zero, and multiply the second number by Multiply 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 (n-1) power, and then 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 nth number starting from the rightmost binary number.
Calculate the first, second, third and nth terms using the formula An*2^(n-1) Just add them together
16. What is the content output by 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, and 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?
include will issue a system warning and continue execution, require will issue a system warning but will cause a fatal error and terminate the script.
18. Now There is a function with an uncertain number of parameters (maybe 5 or 50), how to define 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( 'Three' );
18 }
19
20 function otest ()
21 {
In 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. Briefly describe how 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. Use PHP to get a random number in this interval. If the SQL statement is greater or less than this ID, limit dozens of pieces (guaranteed 10 pieces of data). If it is not scattered enough, the shuffle function of the retrieved data will be disrupted. Array, array_rand then takes 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 where it is uncertain because the middle Some 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 values in the query result array based on the ID and put them into a new array
22. Use PHP to replace letters in a string Success **
preg_replace('/[a-zA-Z]*/','**',$str);
If you specify the characters, you can str_replace('ooxx','**',$str);
23. What is the printed result in 2.php below? Why? Execution sequence 1.php->2.php
Cookie, there is a problem with 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 the header in php Information
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, the output results will be the same.
b. If include or include_once is called in a function or method, if you want to have results for the second and subsequent calls, you must use include instead of include_once. 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. Visit assuming nginx has been configured server_name www.120.net xxx.120.net
Visit http://www.120.net/index.php and http://xxx.120.net/ After index.php, what are
$_SERVER["SERVER_NAME"] and $_SERVER["REQUEST_URI"] respectively?
www.120.net xxx.120.net
/index.php /index.php
30. A certain file under linux The attribute is drwxr-xr-x. The number indicates that the permissions are
The directory permissions are 755. The owner u has read, write and modify permissions. The group to which he belongs has g and the group to which he belongs has read and modify permissions. Other than the group to which he belongs, o has read and modify permissions.
31. Broadband How many KBps is the theoretical download speed of 1Mbps? Calculation method
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 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( ) // Clone is not allowed { 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 singleton
4 Override the __clone() method
----Ten words: private static variables, public static methods--------
2. Give examples of several commonly used magic methods and explain their functions? How to print When displaying our customized content as an object?
Magic function
1. __construct()
is called when instantiating an object,
When __construct and a function with the class 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 little bit before serializing it, 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 Constant
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 (newly added 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, reply content and other information
threads table primary key is tid
posts table The primary key is pid, and the topic tag is tid
Associate threads and posts one-to-many through tid
Now the data volume posts has reached 100 million, the threads table has 20 million, and there are about 5 replies per topic
Please design a sub-table , divide the posts table and threads table into mysql tables
5. Now there is a mysql main library/cluster library. How can I achieve master-slave separation in the php program when querying php mysql? What are the benefits of master-slave separation and configuring the master-slave array? File, seal and transfer several model functions yourself, load slave configuration instantiation for query, and load master for instantiation for operations that destroy data. Advantages: Improved concurrent load capacity, 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 is nothing more than several sites sharing a user center to achieve synchronous login and synchronous logout.
In fact, it is the user who logs in in the end, but it uses ajax (javascript uses src to make asynchronous cross-domain calls) and the user will not notice it.
And it is implemented using the p3p header, 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 slow 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 to / usr/local/test directory
c. It relies on the mysql package, located in the /usr/local/mysql directory
Write out the download, compile 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. Use PHP's memcache extension to write a function to obtain data (the cache is about to expire and timeout and lock)
a. After the data times out, go to mysql to obtain it. After obtaining it, Update memcache
b. Lock when going to mysql to get data, let one process go to mysql to pull the data, and 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
Both can be regarded as one-dimensional arrays to operate, and queues are advanced First out, dequeue can only be at the head of the column, inline can only be at the end of the column, the stack is last in first out, push and pop are from the top of the stack
What is the working principle of the stack?
The stack is a kind of abstract data Structure, its operating 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 is defined as follows, use it to implement an array
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 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. Assume that the coreseek installation directory is /usr/local/coreseek
The configuration file is /usr/local/coreseek/etc/test.conf
The index name is post
a. Create the index
b. Start the service
c. Rebuild the index (make sure the search service is still available during the rebuilding process)
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. Assume that you have a posts table and perform sphinx incremental quasi-real-time indexing on the table. Describe your Solution
There is a simple implementation using the "main index + incremental index" method. Add a count table in the database to record the last data ID of the indexed table each time the main index is rebuilt, so that when the incremental index is You only need to index the data after this id, and update this table every time the main index is rebuilt.
13. PHP code:
$i = 97;$a = ($i++) + (++$i) + $i ;$b = (--$i) + ($i--) + $i + 6;
echo "$i, $a, $b";What is the output result
97, 295, 299
97
97+99+99
98+98+97+6
14. The following code is used to obtain the client 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'];} However, the request headers starting with HTTP_ are information that can be forged by the client. In a reverse proxy environment, how to ensure that PHP will not receive forged HTTP_CLIENT_IP , HTTP_X_FORWARDED_FOR value?
15. For example, for large websites such as Google and Baidu, when the same URL is accessed using different clients (such as mobile phones and PCs), the pages presented are different. Why is this? Bonus points if you can give a practical solution.
It can be easily judged by user_agent, but it is very preliminary.
If possible, 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? 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? Being hung?
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. You also need to set the timeout curl_setopt($s,CURLOPT_TIMEOUT,$timeout);
18. Same as the above question, how to avoid too slow DNS query Cause 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?
In To defend against CSRF vulnerabilities on the web application side, referer, token or verification code are generally used. The tokenf method is relatively trustworthy
The above has introduced the sharing of PHP interview questions, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.