Starting from the php interview questions

Source: Internet
Author: User
Start with a php interview question :?? Setcookie ('name', test); echo $ _ cookies [name]; tell the program result (can you tell the difference between the first time and the second time )? At first I thought it was not just to set a cookie and read it out, but I was confused by the prompts behind it and never thought about this problem. I didn't come up with the answer during the interview, but I started with a php interview question.

Interview questions:

?

?

Setcookie ('name', 'test'); echo $ _ cookies ['name']; please state the program results (points for the first and second differences)

? At first I thought it was not just to set a cookie and read it out, but I was confused by the prompts behind it and never thought about this problem. I didn't come up with the answer during the interview, but I figured it out at the interviewer's guidance.

?

Answer:

?

?

1. empty for the first time 2. the second output of test explains: cookies are stored on the client. to obtain cookies, the client must pass the http header to the server. First time: first set a cookie value, then read the cookie value (because the client did not pass the cookie to the server for the first time), no cookie value for the second time: the cookie value is passed to the server and read
?

After the interviewer gave me some advice, I remembered that the bug of the previous project was related to this, but I avoided it in another way.

?

As a result, I saw the following code in setcookie in the php Manual these days:

?

?

 $ Value) {$ name = htmlspecialchars ($ name); $ value = htmlspecialchars ($ value); echo "$ name: $ value
\ N ";}}?> Highlights // after the page reloads, print them out
?

I think this prompt is too low-key. I think many of us are debugging

?

?

setcookie(‘name’,'test');echo $_cookies['name'];

?

The first time there is no value, and then refresh it out, I thought it was okay, so I don't want to see why.

?

The manual is very important, but there are so many things in the manual that you will surely notice the code in this place when reading the manual. So I was curious about the situation in which the interviewer encountered this problem. so I asked the interviewer and got the following answer:

?

?

Well, authentication should be regarded as the first and most important part of all web projects. Therefore, you must be familiar with the authentication. This problem mainly occurs when the COOKIE is sent to the browser by the server and when the browser is passed to the server.
?

From this point of view, we may find this problem. Then the interviewer said that he knew that the manual had this thing.

?

At last, the manual is very important, but it is too low-key. if you find a similar low-key issue in the manual, please share it. I am also preparing to collect the low-key questions in the manual.

?

?

?

?

?

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.