How to prohibit session timeout in PHP: 1. Set "$_SESSION['refresh'] = rand();" in the PHP file; 2. Use js timer setInterval to prevent session expiration.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to prohibit session timeout in PHP?
A simple method for PHP to prevent session expiration
Recently some users have reported that they have worked hard 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);
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['refresh'] = rand(); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to disable session timeout in PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor
