Home > Backend Development > PHP Tutorial > PHP interview questions sharing, PHP test questions sharing_PHP tutorial

PHP interview questions sharing, PHP test questions sharing_PHP tutorial

WBOY
Release: 2016-07-13 09:44:35
Original
1110 people have browsed it

Sharing PHP interview questions, sharing PHP test questions

1. Which network protocol does nginx use?
nginx is the application layer. I think the transport layer is used from bottom to top. The tcp/ip application layer uses http
fastcgi is responsible for scheduling the process
2. There is no output result, what may be the reason, and a brief solution to this problem Process (tip: There is no problem with the syntax)
Maybe the short tag is not turned on on the server. short_open_tag = is set to Off, and the php.ini short tag control parameter is turned on: short_open_tag = On
3. Briefly describe the output results of the following program, Briefly explain why and how to solve this kind of problem?
$tmp = 0 == "a"? 1: 2;
echo $tmp;
?>
Result 1: 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 assign 1109063 in the string to $uid, milo to $user, and 1 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 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 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 processing $cnd and assign 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 their advantages Bad
mysql, memcache, and cookie maintain a unique status identification code
9. Possible reasons for the following HTTP status codes and how to deal with them
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 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 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 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
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 pattern is it often used in Use
singleton 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=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
Just multiply the numbers on each digit of the binary number starting from the rightmost, multiply the first number on the right by two raised to the zero power, and multiply the second Multiply the number by the power of two, multiply the third number by the power of two, and so on to get the nth number multiplied by the (n-1) power of two, 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.
The first, second, third and nth terms are expressed using the formula An*2^(n-1) Calculate and add them 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 end with t Cut the string and explode it into 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 issue a system warning and continue execution, require will issue a system warning but will cause a fatal error and terminate the script.
18. There is an existing 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] . "
}
}
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( 'a 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 {
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. Process global variables in a function (the function has no return statement) , and change its value, use two methods to implement (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. We often encounter Randomly retrieve 10 pieces of data from the user table for display. Briefly describe how you implement this function. SQL functions and order by statements cannot be used
Table user field uid, username

Estimate the interval in a user table, use php to get a random number in this interval, and use sql statements greater or less than this id to limit dozens of pieces (guaranteed 10 pieces of data), and then If the data is not scattered enough, the shuffle function of the retrieved data will disrupt the array, and array_rand will immediately retrieve 10
21. Assume that the uid in the following sql statement can obtain the specific value, what is the order of the 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 ascending order, there is a special situation where it is uncertain because some of the IDs in the middle may not be in ascending order if they are directly modified manually. If you follow the order of uid in, you need to recycle it again to get the value in the query result array according to the ID and put it in Just put it in the new array
22. Use PHP to replace the letters in a string with **
preg_replace('/[a-zA-Z]*/','**',$str);
If you specify the characters, you can str_replace('ooxx','**',$str);
23. What is the print 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 has ' in the sql statement / When waiting for words, 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, 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 on 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. Access assumes nginx has been configured server_name www.120.net xxx.120.net
Access http://www.120.net/index.php and http://xxx. After 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. The number indicates its permissions.
The directory permissions are 755. The owner u has read, write and modify permissions. The group it belongs to has g, which has read and modify permissions. People outside the group o have read and modify permissions
31. What is the theoretical download speed of 1Mbps broadband in KBps, the 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 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__ Get the current class name
3 Get the public static method Singleton
4 Override the __clone() method
----Ten words: private static variables, public static methods--------
2. Give some examples of commonly used magic tricks Method, and explain its function? How to display our customized content when printing an object?
Magic function
1. __construct()
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 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, title and other information
posts table records topic content, reply content and other information
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 of posts has reached 100 million, and the threads table is 2000 Thousands, there are about 5 replies in 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 library/cluster library, please ask when php mysql query How to achieve master-slave separation in a php program? What are the benefits of master-slave separation? Configure the master-slave array file, transfer several model functions by yourself, load the slave configuration for query and instantiate, and load the master for instantiation during the operation of destroying data. Advantages: Concurrency The load capacity is increased, 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 Log in and log out simultaneously.
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 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. The source code is compiled and installed in 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. Use PHP's memcache extension to write a function to obtain data (the cache is about to expire and timeout is locked) )
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, 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
can be regarded as one-dimensional arrays To operate, the queue is first in first out, the dequeue can only be at the head of the column, the queue can only be entered at the end of the column, the stack is last in first out, the push and pop are from the top of the stack
What is the working principle of the stack?
The stack is an abstract data structure whose operation 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 (search is guaranteed during the rebuilding process The service is still available)
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. Suppose 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 counting table in the database to record the last data ID of the indexed table each time the main index is rebuilt, so that only the data after this ID need to be indexed during incremental indexing, and the main index is rebuilt each time This table is updated every time.
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, 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. What is the principle? 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 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? 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 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1048753.htmlTechArticle Sharing of php interview questions, sharing of php test questions 1. Which network protocol does nginx use? nginx is the application layer. I think from From bottom to top, the transport layer uses tcp/ip and the application layer uses http. Fastcgi is responsible for scheduling...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template