How does PHP correctly generate cookies to ensure that the specified webpage is opened in a specific path?

Source: Internet
Author: User
How does PHP correctly generate cookies to ensure that the specified webpage is opened in a specific path? I have an image verification webpage verification. php, that is, login webpage. & nbsp; PHPcode & lt ;? Phpif (the entered image verification code is correct & amp; generate Cookie) {How does one generate a Cookie in PHP to ensure that the specified webpage is opened in a specific path?

I have an image verification webpage verification. php, that is, login webpage.


PHP code
  
  















There is also a data webpage data. php.

PHP code
  
  








I have been worried that some users will directly use the browser to log on to the data. php page, instead of logging on to the verification page verification. php.

How does PHP verify the Cookie generated by verification. php on the data webpage data. php? Note: it cannot be confused with cookies generated by other websites or other websites.

Is it necessary to use SHA1 to verify the Cookie?





------ Solution --------------------
Do you want to confuse the name of a cookie with other cookies?

Then you can define a complicated name. it doesn't matter if it is long.
------ Solution --------------------
If you directly log on to the data page using a browser, data. php does not have cookie variables.
If you are worried about cookie forgery, you can add a special token in the cookie and compare it with the cached value on the server.
------ Solution --------------------
In my previous projects, I used the session to store a login_flg field in it to identify the login status.
Make login_flg in php to determine whether there is no login and directly perform location jump to let him log on.
------ Solution --------------------
Only the server knows how to decrypt the encrypted data. for example, you can encrypt the data at the current time and resolve it to a time difference of less than 10 minutes.
------ Solution --------------------
Discussion

In my previous projects, I used the session to store a login_flg field in it to identify the login status.
Make login_flg in php to determine whether there is no login and directly perform location jump to let him log on.

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.