The content of this article is the interview questions that must be asked in the PHP interview. I share them with you here, and you can also give some reference to friends in need. Let’s take a look together
Related recommendations: "2019 PHP interview questions summary (collection)》
position means "position" in English. It is mainly used to realize the positioning ofelements
There are three types of positioning in CSS:
position:fixedFixed positioning
position:relatvieRelative positioning
position:absoluteAbsolute positioning
position:static No special positioning (default value).
Note:
When using the positioning attribute, it must be used in conjunction with the positioning coordinates!
left:indicates how far the positioned element is from the left
right:indicates positioning How far is the element from the right
top:Indicates how far the positioned element is from the top
bottom:Indicates how far the positioned element is from the bottom
1 Fixed positioning
Syntax:
position:fixed
Fixed positioning, it is positioned relative to thebrowser window. No matter how the page is scrolled, the position displayed by the fixed positioning element will not change!
Features:
Fixed positioning elements are separated from the standard document flow
The level of fixed positioning elements is higher than the elements in the standard document flow, so fixed positioning elements will Cover the elements in the standard document flow
Fixed positioning elements will no longer take up space
Fixed positioning elements will not scroll as the browser scrolls
2 Relative positioning
Syntax:
position:relative;
Relative positioning is relative to "original self"Come and position!"
Features:
The relatively positioned element does not break away from the standard document flow
If the relative positioned element does not set the positioning coordinates, then the relatively positioned element will still be in its original position
After the relative positioning element sets the positioning coordinates, it will leave a pit in its hometown.
The relative positioning element will cover the elements in the standard document flow.
The positioning coordinate value of a relatively positioned element can be a negative number
Note:
Relatively positioned elements will leave a hole in their hometown, so generally they are rarely left alone Use, relative positioning elements are mainly used in conjunction with "absolute positioning" elements.
3Absolute positioning
Grammar:
position:absolute;
What is absolute positioning?
Absolutely positioned elements are positioned relative to "ancestor positioned elements"!
What is an ancestor positioned element?
Absolutely positioned elementIt will first check whether its parent element has a positioning attribute set
If there is a positioning attribute set, then it will be relative to its parent element to perform positioning;
But if its parent element does not have a positioning attribute set, then it will find whether the upper-level element of its parent element has a positioning attribute set.
If it is set Positioning is performed relative to the upper-level element of its parent element
But if it is not set, it will continue to search one level higher.
If its ancestor elements do not set the positioning attribute, then It will be positioned relative to "browser window"!
①When you set absolute positioning yourself: If the parent element does not set the positioning attribute, then it will be positioned relative to the body
②When you set absolute positioning yourself: If the parent elementalsoSet the positioning attribute, then it will be positioned relative to the parent element
③When you set the absolute positioning yourself: If the parent elementalsosets the positioning attribute, then it will be positioned relative to the parent element Element positioning
jQuery.ajax(options)
Parameter description:
options: There is only one parameter, which is required to be data in JSON format. The following attributes can be set:
async: Whether it is asynchronous, true means asynchronous, false means synchronous. The default is true
cache: Whether to cache, true means caching, false means no caching, the default is true
complete: The callback function triggered when the Ajax status code is 4
contentType: Request header, if it is a POST request, this parameter is application/x-www-form-urlencoded
data: The parameter passed when sending an Ajax request, the requirement is a string
dataType: The expected return value type, which can be text/xml/json data type
success: The callback function triggered when the Ajax status code is 4 and the response status code is 200
type: The http request sent can be get or post
url: The URL address of the request
1. What is a synchronous request: (false)
A synchronous request means that after the current request is issued, the browser cannot do anything and must wait. After the request is completed and the data is returned, the subsequent code will be executed, which is equivalent to queuing. The previous person has completed his or her own affairs before the next person can continue. That is to say, when the JS code is loaded into the current AJAX, all the code in the page will stop loading, and the page will be in a state of suspended animation. When the AJAX is completed, it will continue to run other codes and the page will release the suspended animation state (that is, when ajax returns After receiving the data, the following function 2) is executed.
2. What is an asynchronous request: (true)
An asynchronous request means that while the request is being made, the browser can continue to do anything. Ajax sending the request will not affect the loading of the page and the user's operation, which is equivalent to On both lines, each goes its own way without affecting each other.
Generally the default value is true, asynchronous.Asynchronous requests do not affect the user experience at all. No matter how long or short the request is, the user is concentrating on operating other content on the page and does not feel like waiting.
Magic methods include:
__construct(), class constructor
__destruct(), class destructor
__call(), call
__callStatic() when calling an inaccessible method in the object, call
__get() when calling an inaccessible method in static mode, get
__set() is called when setting a member variable of a class,
__isset() is called when setting a member variable of a class, and is called when isset() or empty() is called on an inaccessible property.
__unset(), called when unset() is called on an inaccessible property.
__sleep(), when executing serialize(), this function will be called first
__wakeup(), when unserialize() is executed, this function will be called first
__toString( ), the response method when the class is treated as a string
__invoke(), the response method when calling an object by calling a function
__set_state(), when calling var_export() to export a class, This static method will be called.
__clone(), call
__autoload() when the object copy is completed, try to load an undefined class
__debugInfo(), print the required debugging information
① Different parameter passing methods
The get request passes parameters at the end of the url
Post request is to pass parameters at the position of requesting a blank line
② The size of the passed parameters is different
Get request, the maximum value of the passed parameters is 2kb
post request has no limit in theory, but in actual application, it is affected by the php.ini file, which is generally 2M
③ The type of parameters passed is different
get request, only Pass string
Post request, you can pass not only string but also binary data
④ Different security
Relatively speaking, the security of post request is slightly higher get request
The request header parameters are different
I receiving function
M: Instantiate basic model class
D: Instantiate custom model class
U: Assemble URL address
#1. The interface is used through the keyword implements. The use of abstract classes is through the keyword extends. Of course, interfaces can also be inherited through the keyword extends.
2. Member variables (including class static variables) cannot be declared in the interface, but class constants can be declared. Various types of member variables can be declared in abstract classes to implement data encapsulation
3. Interfaces do not have constructors, while abstract classes can have constructors.
4. Methods in interfaces are of public type by default, while methods in abstract classes can be modified with private, protected, or public.
5. A class can implement multiple interfaces at the same time, but a class can only inherit from one abstract class.
Common points: used for specification
Abstract class: cannot be instantiated, can only be inherited; declared through the keyword abstract; the abstract class must contain at least
An abstract method, which has no method body and must be overridden by subclasses;
Interface: declared through interface; member constants and methods in the interface are public, and the method does not need to write the keyword public; the interface can implement multiple inheritance;
drawLikekindisakindcannotcan
#implement
Can
makefor
otherhim
likeParent
Class
To Use
.
abstract
.
interface also have no method body. The methods in the interface are also inherently intended to be implemented by subclasses. The functions implemented by abstract classes and interfaces are very similar. The biggest difference is that interfaces can implement multiple inheritance. The choice between abstract
# in an application and interface depends on the specific implementation.
Subclasses inherit abstract classes using extends
, and subclasses implement interfaces using implements. 8. How to understand namespace? ?#PDO: A lightweight consistent interface defined by PHP for accessing the database.
###CURL Extension######GD Extension######Memcache######Mysql######11. What should I do if there is a conflict in SVN? ? ###############SVN role: collaborative development. ######Integration:######Update:######12. How to understand MVC? ? ###############MVC is a framework pattern that enforces separation of application input, processing, and output. Applications using MVC are divided into three core components: model, view, and controller. They each handle their own tasks. ######MVC refers to a programming model in software design. In this mode, business operations, data display, and data interaction will be split into operations######M: The representative is a specific model (model), and its main function is to interact with the database for data###### V: The representative is a specific view (view) whose main function is to interact with users for data ######C: the representative is a specific controller (controller) whose main function is to process specific business logic ###### By An application is completed by model, view, and controller. The model layer is responsible for providing data. Operations related to the database are handled by the model layer. The view layer provides an interactive interface and outputs data. , and the controller layer is responsible for receiving the request, distributing it to the corresponding model for processing, and then calling the view layer for display. ###Product id, product name, product number, product category id, market price, store price, product thumbnail, product thumbnail, whether it is a hot seller 1 means hot seller 0 means no, whether it is recommended 1 means Recommendation 0 means not recommended, whether it is a hot seller 1 means new product 0 means no, adding time, indicating whether the product has been deleted 1 normal 0 deletion status, whether the product is on sale 1 sales 0 off-shelf status,
The attributes in the product table are stored as a set. The attribute table
Compare the two, there are The following points are different:
1. Position of action: cookie saves user information on the client side, session saves user information on the server side;
2. Save content: cookie saves a string , objects are saved in the session;
3. Action time: cookies can be stored on the client for a long time, and the session is closed when the session ends;
4. Generally, cookies store unimportant user information , important information is saved by session.
5. Cookies are divided into two types: session cookies and file cookies. When the browser is closed, the session cookie data disappears. The file cookie stores the data in a file and sets the expiration time. After closing the browser, if the expiration time has not expired, the data still exists when the browser is opened again.
There are two situations:
1. The user is not logged in, and the data is stored in the cookie , if the user logs in, the data in the cookie will be transferred to the database.
2. After the user logs in, the data is directly stored in the database.
Role-Based Access Control
Five tables: two intermediate tables admin, role, rule, admin_role, role_rule
Three tables: an intermediate table
The process of controlling whether different administrators can access a certain method through code is permission control.
RBAC (Role-Based AccessControl, role-based access control) means that users are associated with permissions through roles. Simply put, a user has several roles, and each role has several permissions. In this way, a "user-role-permission" authorization model is constructed. In this model, there is generally a many-to-many relationship between users and roles, and between roles and permissions.
Download the third-party interface file first.
JS client verification
Mobile phone number limit number of text messages (counter)
(1) Add graphic verification
Malicious attackers use automated tools to call the "Dynamic SMS Acquisition" interface to send dynamic SMS messages. The main reason is that attackers can automatically make a large number of calls to the interface.
The use of image verification codes can effectively prevent automatic calls of tools. That is, before the user performs the "Get dynamic SMS" operation, an image verification code pops up and requires the user to enter the verification code. The server then sends a dynamic SMS to the user's mobile phone. This method can effectively solve the problem of text message bombing.
The secure graphic verification code must meet the following protection requirements
-Secure generation process:The picture verification code must be in The server side generates and verifies;
- The usage process is safe: it is valid once and is subject to the user's verification request;
- The verification code itself is safe: it is not easy to be recognized by identification tools and can effectively prevent brute force cracking.
Example of graphic verification:
(2) Single IPRequest limit
Using image verification After the code is passed, it can prevent the attacker from effectively making automated calls to the "Dynamic SMS" function;
However, if the attacker ignores the verification error of the image verification code, a large number of execution requests will bring additional burden to the server and affect the business. use. It is recommended that the server side limits the number of requests for a single IP within a unit time. Once the number of user requests (including the number of failed requests) exceeds the set threshold, requests to the IP will be suspended for a period of time; if the situation is particularly serious, the IP can be added Blacklist, prohibit access requests from this IP. This measure can limit a large number of requests from an IP address, prevent attackers from attacking a large number of users through the same IP, increase the difficulty of attacks, and ensure the normal development of business.
(3) Limit sending time
It is recommended to limit the interval between repeated sending of dynamic text messages. That is, when a single user requests to send a dynamic text message, the server-side limit can only be carried out after a certain period of time (usually 60seconds here). Second dynamic SMS request. This function can further protect the user experience and avoid malicious spam verification SMS messages including manual attacks.
Complete dynamic SMS verification code usage process
Specific synchronous callback and asynchronous callback
Synchronous callback function: to enable the user to jump to the corresponding merchant page after the payment is completed (to ensure that the user payment is completed Afterwards, the user's payment can be processed correctly)
Asynchronous callback function: Ensure that the merchant processes the user's payment correctly
1. Apply for Alipay account information and get the corresponding APPID, public key (give it to Alipay), and private key (keep it yourself)
2. Download Official document, build a demo test locally, set APPID, synchronous and asynchronous callback address, Alipay private key and other information in config.php.
3. Create a background application
4. Use code specifically to implement the payment function
The function of asynchronous callback: ensure that the merchant handles the user's payment correctly
1. Ensure that synchronization is not executed and asynchronous unilateral request is made. ()
2. Solve the problem of dropped orders
3. Relatively safe
Synchronous callback function: When the user completes the payment, he can jump to the corresponding merchant page (make sure After the user's payment is completed, the user's payment can be processed correctly) (get method)
Asynchronous callback function: Ensure that the merchant has correctly processed the user's payment (post method)
Find files:
find
-name Search based on the file name
-group: Search according to the group to which the file belongs
-user: Search according to the owner of the file
locatecommand, Used to retrieve data
locate file name
df command: display disk information
-l: display local diskDisk information
-h: Display disk information in1024
-H: Display disk information in1000
##- T: Display disk format information
-t: Display disk information in the specified format
cd User Name: Enter for cd ~: Return home yy: Copy p: Paste vim File name: View file 27, hppt status code? ? 1, 301 MovedPermanently: 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.Permanent Redirect.
2. 302 Move temporarily: The requested resource temporarily responds to the request from a different URI. Since suchredirection is temporary, the client should continue to send future requests to the original address
3. 404 Not Found: The request failed and the resource requested was not found. Found on the server. There is no information to tell the user whether this situation is temporary or permanent 4. 200 OK: The request has been successful, and the response header or data body expected by the request will be returned with this response. This status code is200 (Success): The server has successfully processed the request. Typically, this means that the server served the requested web page
201 (Created): The request was successful and the server created the new resource
202 (Accepted): The server accepted the request, but it has not yet been processed
203 ( Unauthorized information): The server successfully processed the request, but the information returned may have come from another source
204 (No content): The server successfully processed the request, but no content was returned
205 (Reset content) : The server successfully processed the request, but did not return any content
206 (Partial content): The server successfully processed part of the GET request
404 (Not Found): The server cannot find the requested web page
500 (Server Internal error): The server encountered an error and could not complete the request
The performance of the require() statement is similar to include() , all include and run the specified file.
The difference is: for the include() statement, it must be read and evaluated every time when executing the file; when an error is reported, it will not prevent subsequent code from running; and for require() , the file is processed only once (in fact, the file content replaces the require() statement). This means that if code is likely to be executed multiple times, it is more efficient to use require(). On the other hand, if you read a different file each time you execute the code, or have a loop that iterates through a set of files, use the include() statement
include to load when used
require is loaded at the beginning
1. Find the software compressed package and unzip it
2. Compile make &&make install
3. Configure php.ini
4. Restart Apache
A logical set of operations contains several components. These parts form a whole, and all operations are successful. , or all fail and return to the original state!
Before executing the SQL statement, execute start transaction first, which opens a transaction (the starting point of the transaction), then you can execute multiple SQL statements, and finally end the transaction. Commit means submission, that is, in the transaction The effects of multiple SQL statements will be persisted to the database. Or rollback, which means rollback, that is, rolling back to the starting point of the transaction, and all previous operations have been undone!
Four major characteristics of transactions (ACID)
Atomicity: All operations in a transaction are atomic units that cannot be divided. All operations in the transaction either execute successfully or fail.
Consistency: After the transaction is executed, the database state remains consistent with other business rules. For example, in a transfer business, regardless of whether the transaction is executed successfully or not, the sum of the balances of the two accounts involved in the transfer should remain unchanged.
Isolation: Isolation means that in concurrent operations, different transactions should be isolated so that each concurrent transaction will not interfere with each other.
Durability: Once the transaction is submitted successfully, all data operations in the transaction must be persisted to the database. Even if the database crashes immediately after the transaction is submitted, it must be guaranteed when the database is restarted. Recover data through some mechanism.
PHP gets the current time time()
Php intercepts the string: substr function
PHP finds whether there is a substring in the string:
In_array: Determine whether an element exists in the array
array_reverse() flashbacks the elements in the array, and the return value is the array after the flashback.
array_splice(array1,start,length,array2) removes the corresponding element from the array and replaces it with a new element
array_push() (push) adds an or to the end of the array Multiple elements,
array_pop() (pop) deletes the last element from the array
JSONP
CORS
Mysiam and innodb
The MyISAM type does not support advanced processing such as transaction processing, while the InnoDB type does.
The MyISAM type table emphasizes performance, and its execution speed is faster than the InnoDB type, but it does not provide transaction support, while InnoDB provides transaction support and advanced database functions such as foreign keys.
Create index: alert tabletablename add index (`field name`)
6379
String, hash, list (linked list), set (set), zset (ordered set)
Flash sales:
Use Redis' list linked list and pop operation, even for many users When they arrive at the same time, they are also executed in sequence
1. Now store the inventory of the product table in the queue
2. Start the rush purchase and set the cache cycle of the inventory
3. The client executes the following Single operation, determine the redis queue inventory before placing an order
Counter:
Left join (left join): The left table shall prevail. The records in the left table will appear in the query results. If there are no matching records in the right table, they will be filled with null.
Right join (right join): It is based on the right table. The records in the right table will appear in the query results. If there is no matching record in the left table, it will be filled with null.
Inner join (inner join): The status of the two tables is equal, and only records that meet the join conditions will appear in the query results.
27017,28017
Memcache cache saves all data in memory, using hash table. Each piece of data is composed of key and value. Each key is unique. When a certain value is to be accessed, the value is found first, and then the result is returned. Memcache uses the LRU algorithm to gradually clear out expired data
1. Database design
2. Index creation
3. Separation of reading and writing
4. Caching
#1. When adding products, the product inventory increases. The inventory table adds
for different attributes. 2. When the order payment is successful, the inventory will be reduced
3. The order payment fails, the inventory will not be reduced
4. Customer returns , inventory increase
1. Avoid full table query and create indexes for corresponding fields
2. Avoid query statements that are too long and query in batches .
3. There cannot be any functional operation after where
4. The first field of left principle like must have an index
5. Create an index after where and group by
Related recommendations:
PHP interview questions collection and sharing
record of common questions in php interviews
The above is the detailed content of Must-ask interview questions for PHP interviews. For more information, please follow other related articles on the PHP Chinese website!