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 the beginning, I thought it was not just about setting a cookie and then reading it out, but I was confused by the prompts behind it. I never 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.
?
?
?
?
?