How should I set cookie expiration?

Source: Internet
Author: User
Tags set cookie
How should I set the cookie expiration hypothesis & nbsp; setcookie (abc [admin], & nbsp; zhang, & nbsp; time () & nbsp; + & nbsp; 3600); setcookie (abc [name], & nbsp; Zhang San, & nbsp; time () & nbsp; + & nbsp; 3600); when I refresh the page, how should I set the expiration time from the current cookie?
Assume that after I log on to the website
Setcookie (abc ["admin"], "zhang", time () + 3600 );
Setcookie (abc ["name"], "James", time () + 3600 );

When I refresh the page, the expiration time should be from the current plus 3600 seconds

For ASP, you can directly set it in conn. asp.
Response. Cookies ("abc"). expires = DateAdd ("n", 60, Now ())
After the page is refreshed, all cookies under abc will change the expiration time to the current time plus 60 minutes.

In PHP, how do I batch extend the expiration time?

Share: More


------ Solution --------------------
Modify php. ini
------ Solution --------------------
Setcookie (abc ["admin"], "zhang", time () + 3600 );
You have set the Expiration Time. modify the time zone of php. ini.

------ Solution --------------------
All the cookies set in php will be placed in the predefined variable $ _ cookie value (this will be available only when $ _ COOKIE is loaded next time ).
You can loop through the $ _ COOKIE array to achieve batch latency.

------ Solution --------------------
In addition, why don't you set the Expiration Time to O directly ??
When 0, the browser is disabled.
------ Solution --------------------
Reference:
Quote: reference:

Setcookie (abc ["admin"], "zhang", time () + 3600 );
You have set the Expiration Time. modify the time zone of php. ini.


If you submit the logon information, you can use check. php determines that the logon information is correct, setcookie (abc ["admin"], "zhang", time () + 3600);, and then jumps to other operation pages, after that, check will not be called. php. if the expiration time is not extended when you browse other operation pages, the user will expire no matter whether the page is browsed or not, but what I want to do is to expire in 1 hour without the user's operation.

Session. gc_maxlife time = 3600
That is, if you haven't accessed the website for more than 60 minutes, the server will destroy your SESSION and you will be logged out!
------ Solution --------------------
You can continue to execute those two items on other pages.
------ Solution --------------------
Reference:
Quote: reference:

In addition, why don't you set the Expiration Time to O directly ??
When 0, the browser is disabled.


What I need is that if personnel A stays on A page for too long, he may do other things. when personnel B wants to operate his page, it will be unable to operate because of timeout. specified time (for example, the above 1 hour) there will always be no expiration problem on the operation page, because expiration will continue to be delayed by 1 hour according to the current operation

I know how to implement ASP, PHP is just learning, but I still don't know how to handle it.

0, as long as the browser does not turn off the cookie will never expire.

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.