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

Undress AI Tool
Undress images for free

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

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

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Writing good code and annotations can improve project maintainability and professionalism. 1.CleanCode emphasizes clear naming, single responsibilities and structures, so that it is easy for others to understand; 2. Comments should explain "why" rather than duplicate code functions; 3. PHP comments should cover class descriptions, method parameters, and key logical backgrounds; 4. Practical suggestions include using meaningful variable names, unified annotation style, and using tool specifications.

Defining constants in PHP, const is more suitable for constant definitions inside classes, and define() is more flexible and suitable for global or dynamic definitions. 1.const is a language structure, and must be a compile-time constant expression when defined, which is suitable for class or global namespaces; define() is a function, and the value can be the result of runtime calculation. 2.const is affected by the namespace, and the constants defined by define() are visible globally by default. 3. The const structure is clear and the IDE is good, which is suitable for object-oriented design; define() has high flexibility but may have higher maintenance costs. 4. define() supports runtime condition judgment and dynamic definition, but const does not support it. Therefore, class-related constants preferentially use co

When writing PHP comments, you should clarify the purpose, logic and structure. 1. Each function and class uses DocBlock format to explain the role, parameters and return values; 2. Explain "why" in the key logic rather than just "what was done"; 3. Add a brief description at the top of the file, including functions, dependencies and usage scenarios; 4. Avoid nonsense comments, add only necessary instructions before complex logic, and do not record the modification history. This improves code readability and maintenance efficiency.

TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech

The first step is to select the integrated environment package XAMPP or MAMP to build a local server; the second step is to select the appropriate PHP version according to the project needs and configure multiple version switching; the third step is to select VSCode or PhpStorm as the editor and debug with Xdebug; in addition, you need to install Composer, PHP_CodeSniffer, PHPUnit and other tools to assist in development.

Comments are crucial in code because they improve the readability and maintenance of the code, especially in projects like PHP that are multi-collaborative and long-term maintenance. Reasons for writing comments include explaining “why do this” to save debugging time and be friendly to newbies and reduce communication costs. The representation of good comments includes explaining the role of functions or classes to explain complex logic intent marking to-dos or potential problems, and writing API interface documentation annotations. Typical manifestations of bad comments include repeated code content comments that are inconsistent with code and using comments to cover up bad code and retaining old information. Suggestions for writing comments include prioritizing comments "why" keeping comments synced with code Use a unified format to avoid emotional statements and consider optimizing code rather than relying on comments when the code is difficult to understand.

PHP comparison operators need to pay attention to type conversion issues. 1. Use == to compare values only, and type conversion will be performed, such as 1=="1" is true; 2. Use === to require the same value as the type, such as 1==="1" is false; 3. Size comparison can be used on values and strings, such as "apple"

There are three common methods for PHP comment code: 1. Use // or # to block one line of code, and it is recommended to use //; 2. Use /.../ to wrap code blocks with multiple lines, which cannot be nested but can be crossed; 3. Combination skills comments such as using /if(){}/ to control logic blocks, or to improve efficiency with editor shortcut keys, you should pay attention to closing symbols and avoid nesting when using them.
