Summary of common PHP knowledge points

Source: Internet
Author: User
Tags http cookie
Summary of common PHP knowledge points: 1. The difference between echoprintprint_r: Echo is a PHP statement, and print and print_r are functions. The statement does not return values. the function can return values. Print can only Print values of simple type variables. Print_r can print complex variable values (arrays or objects) and summarize common PHP knowledge points

PHP:
1. differences between echo print print_r
Echo is a PHP statement,Print and print_r are functions.,The statement does not return a value. a function can return a value..
Print can only Print values of simple type variables.
Print_r can print complex variable values (arrays or objects)
Echo outputs one or more strings.

2. differences between mysql_fetch_array () and mysql_fetch_row ()
Mysql_fetch_array () returns the array generated based on the rows obtained from the result set. If no more rows exist, false is returned. besides indexing data by fields, you can also use the field name as the index.
Mysql_fetch_row () returns an array of numeric indexes from the result set to obtain a row as an enumeration array. the offset starts from 0.
Mysql_fetch_array () is an extension of mysql_fetch_row.

3. Role of _ set () and _ construct in PHP object-oriented
_ Set () --- used to set a value for the property, _ get () to get the property value
_ Construct --- only one constructor can be declared in a class. The constructor can be called only once when an object is created, so it is usually used to execute some useful initialization tasks.

4. differences between session and cookie in PHP
Cookie is the information stored on the client. it is a mechanism for storing data in a remote browser and tracking and identifying users. The http header of PHP sends cookies. Therefore, the setcookie () function must be called before other information is output, which is similar to the header () function.
Session is the information stored on the server. From this perspective, session is safer than cookie. When a session is created, the server returns an encrypted session_id from the client to identify the user. when the browser is closed, the session will be destroyed, and the value of the session will be lost.

5. how to set a cookie and specify a valid time
Bool setcookie (string name, string value, int expire, string path, string domain, bool secure, bool httponly)
Name: cookie variable Name
Value: cookie variable Value
Expire: the end time of the validity period
Path: valid directory
Domain: valid Domain name, top-level or unique
Secure: if the value is 1, the cookie can only be valid for https connections. if the default value is 0, both http and https can

Set cookie in Php
$ Value = 'something from somewhere ';

Setcookie ("TestCookie", $ value);/* simple cookie setting */
Setcookie ("TestCookie", $ value, time () + 3600);/* valid for 1 hour */
Setcookie ("TestCookie", $ value, time () + 3600, "/~ Rasmus/"," .example.com ", 1);/* valid directory /~ Rasmus, valid domain name example.com and all its subdomains */
?>
Use header () to set the cookie;
Header ("Set-Cookie: name = $ value [; path = $ path [; domain = xxx.com [;]");
The following parameters are the same as those listed in the setcookie function above.

Cookie mechanism principle:
A) the server sends an http Set-Cookie header in response and sets a cookie in the client (multiple cookies require multiple heads ).
B) the client automatically sends an http cookie header to the server, and the server receives and reads the cookie.
HTTP/1.x 200 OK
X-Powered-By: PHP/5.2.1
Set-Cookie: TestCookie = something from somewhere; path =/
Expires: Thu, 19 Nov 2007 18:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check = 0, pre-check = 0
Pragma: no-cache
Content-type: text/html

This line implements the cookie function. after receiving this line
Set-Cookie: TestCookie = something from somewhere; path =/
The browser will create a cookie file on the disk of the client, and write:
TestCookie = something from somewhere;
/
This line is the result of using setcookie ('testcookie ', 'Something from somewhere. that is, the result of using header ('set-Cookie: TestCookie = something from somewhere; path =.
6. PHP object-oriented access control
Public indicates global and can be accessed by external subclass inside the class.
Private indicates Private, which can be called only within this class.
Protected indicates that it is Protected and can be accessed only by this class, subclass, or parent class.

7What is php mvc? the role and principle of MVC
MVC is a design pattern that forcibly separates the input, processing, and output of an application. the MVC application is divided into three core parts: Model, view, controller, they process their own tasks.

MVC principle: first, the controller accepts user requests and determines which model should be called for processing. then, the model uses the business logic to process user requests and return data, the controller then formats the data returned by the model with the corresponding view and presents it to the user through the presentation layer.
Basic principle: requests from the presentation layer (V) are sent to the controller (C). The controller calls the business layer (M) based on the request type and displays the call presentation layer.

8. Differences Between include require in PHP
These two structures are different in terms of processing failures. include generates a warning, while require leads to a fatal error. In other words, if you want to stop processing the page when a file is lost, use require. This is not the case for Include. the script will continue to be executed.
The use of Require is as follows: require ("Myfile. php); this table is usually placed at the top of the PHP program. before PHP is executed, it will read the file specified by require to make it part of the PHP program webpage.
The use of Include is the same as the preceding method. this program is generally placed in the process section of process control. only when the php program webpage reads the include file can it be read, the process during program execution can be simplified.

When the page is executed to require (), if require is a PHP or HTML page, it will be immediately forwarded to the execution page. The include is generally used to include some inc files. For example, you can use the page header and header of your website as an inc file, so that you can include them in each php file. The include operation only embeds the file you want to include into the current page. And require is to immediately execute the page you requested.
---------------------------
Incluce loaded when used
Require load at the beginning
_ Once suffix indicates that the loaded files are not loaded.
The php System has a pseudo-compilation process when loading the php program, which can speed up the program running. However, the CE documentation is still interpreted.
An error occurred in the include file. the main program continues to execute.
The require file has an error and the main program has stopped.
Therefore, if the error of the contained file does not affect the system much (such as the interface file), use include. Otherwise, use require.
For the include_once () function, the require_once () function first checks whether the content of the target file has been imported before. If yes, the same content will not be imported again.

10. calculate the time difference between the two instances: 2009.5.12 2009.5.20.
$ Regist1 = "05/12/2006 ″;
$ Regist2 = "10/05/2007 ″;
List ($ month1, $ day1, $ year1) = explode ("/", $ regist1 );
List ($ mon2,$ day2, $ year2) = explode ("/", $ regist2 );
$ Regist1 = mktime (0, 0, $ month1, $ day1, $ year1 );
$ Regist2 = mktime (0, 0, $ mon2, $ day2, $ year2 );
$ Time_difference = $ regist2-$ regist1;

11. what protocols do you know? What does an HTTP error prompt mean?
SMTP (Simple Mail Transfer Protocal) is a Simple Mail transmission protocol designed to provide efficient and reliable Mail transmission to users.
POP stands for Post Office Protocol, which is the Post Office Protocol for receiving emails. it uses TCP port 110 and is now commonly used in the third edition.
IMAP is short for Internet Message Access Protocol. as its name suggests, it mainly provides a Protocol for retrieving information through the Internet.
HyperTextTransferProtocol is short for hypertext transfer protocol. it is used to transmit WWW data. for details about HTTP, see rfc2616.
Internet Explorer prompts HTTP 403-access prohibited
Internet Explorer prompts HTTP 403.9-access prohibited: too many connected users
IE prompts HTTP 404-the file cannot be found
Internet Explorer prompts HTTP 500-Internal Server Error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.