PHP Basic Questions (1-10)

Source: Internet
Author: User
Tags setcookie

1. What is PHP?

PHP is a scripting language that creates dynamic Web sites based on the server, and can generate Web pages from PHP and HTML.

2. What is object-oriented? What are the main features?

Object-oriented is a design method of the program, which helps to improve the reusability of the program and make the program structure clearer. Main features: encapsulation, inheritance, polymorphism.

What is the difference between 3.session and cookie? Please explain the reason and function from the agreement.

1.http protocol is a stateless protocol, can not distinguish whether the user is from the same site, the same user request different pages can not be regarded as the same user.

2. Storage location is different: session is stored on server side, cookie is saved on client;

Security: Session is more secure, cookies can be changed by some means, unsafe. The session relies on the cookie for delivery, and when the cookie is disabled, the session does not work properly.

3.session Disadvantage: Protect the server side, each read from the server to read, the server has resource consumption. The session is saved in the file or database on the server side and is saved by default in the file, and the file path is specified by Session.save_path of the PHP configuration file. The session file is public.

4. How to send a cookie to the client without using cookies.

Understanding: When Session_Start () is turned on, a constant SID is generated, and when the cookie is turned on, the constant is empty, and when the cookie is closed, the value of PHPSESSID is stored in the constant.  By adding a SID parameter after the URL to pass the value of the SessionID, the client page can use the value inside the session. When the client opens the cookie and server-side open session. On the first request of the browser, the server sends a SessionID stored in a cookie to the browser, and when the browser requests it a second time, it submits the existing cookie to the server side.

5. Briefly describe the settings of cookies and the process of obtaining them.

Set the value of the cookie: Setcookie ($cookieName, $value, time () + seconds), or//In order: Cookie name, cookie value, save period.

Example: Create a cookie with a name of username and a value of ZS with an expiration time of 2 weeks

The code is as follows:

Setcookie ("UserName", "Zs", Time () +2*7*24*3600);

If you do not set the time, it is not saved to the cookie file. can be accessed when the browser is not closed. When the browser is closed, it cannot be accessed.

Example:

The code is as follows:
Setcookie ("Age", "18");

2. Take the value of the cookie

$_cookie[$cookieName];

Example: Remove the value of the username and place it in the variable $uname

$uName =$_cookie[' UserName '];

When a value is taken, it is generally judged whether it is empty, and then the value operation is taken. The above value operation is generally written like this:

if (!empty ($_cookie[' UserName '))
{

$uName =$_cookie[' UserName '];

}

3. Delete the specified cookie

Setcookie ($cookieName, Value,time ()-seconds);
Or
Setcookie ($cookiename, ");
Or
Setcookie ($cookiename, NULL);

Example: Delete username

Setcookie ("UserName", "Zs", Time ()-3600);

4. Delete all cookies for the current session

foreach ($_cookie as $key = = $val) {
Setcookie ($key, "", Time ()-100);
}

What does the 302,403,500,200,404,502 code mean in 6.http status?

12345 principles:

One: Message Queue two: Success Series three: REDIRECT series four: request Error series five: server-side Error series

302: The temporary transfer succeeds, the requested content has been transferred to the new location

403: No Access

500: Server Internal Error

401: Delegate not authorized

200: Request succeeded

404: File Not Found

502: Server Internal Error

7. Please write out the meaning of the data type (int char varchar datetime text) and the difference between char and varchar?

int integer char fixed-length character varchar variable-long character datetime date-time type text literal

The difference: Char is a fixed-length character type, the amount of space allocated, the amount of space occupied, varchar is a variable-length character type, the content of how large, occupies much space, can effectively save space. Therefore, the lookup efficiency of the char type is faster, because varchar is a non-training length, when looking for the length of the first, and then extract the data, more than the type of char a step, so less efficient.

8. What are the main storage engines in the database? Where are the basic differences between MyISAM and InnoDB? How does an indexed structure statement write?

MySQL's storage engine includes: MyISAM, InnoDB, BDB, Memory, MERGE, EXAMPLE, Ndbcluster, ARCHIVE, CSV, blackhole, federated, etc. where InnoDB and BDB provide transaction security tables, other storage engines are non-transactional security tables.

  

The default is MyISAM when creating a data table, where MyISAM does not support advanced features such as transactional processing, and InnoDB support, MyISAM-type tables emphasize performance, perform faster, InnoDB provide transactional support, and advanced database features such as external keys.  Create an index: ALTER TABLE tablename Add index (' field name '); 9.isset () and empty? Isset (), empty () is used to determine if the variable is empty.

PHP Basic Questions (1-10)

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.