How to prevent session failure in php

藏色散人
Release: 2023-03-14 13:12:01
Original
1581 people have browsed it

php method to prevent session failure: 1. Create a PHP sample file; 2. Execute the "$_SESSION['refresh'] = rand();" code.

How to prevent session failure in php

#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.

php How to prevent session expiration?

A simple method for PHP to prevent session expiration

Recently some users have reported their hard work It’s really frustrating to click submit after working on an article for several hours, only to be told that you need to log in again. I think this is probably because the session has expired. So I used js timer to solve this problem.

The js code is as follows:

setInterval( function(){jQuery.get("/plugin.php?id=xxxxxx:refresh",function(data,status){});} , 2000);
Copy after login

In fact, there is no need to execute it every two seconds, just fifteen minutes. To prevent browser caching, you can add a random parameter after the path.

The code in the php page executed is as follows:

<?php
    echo $_SESSION[&#39;refresh&#39;] = rand();
?>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to prevent session failure in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template