The example of this article describes the method of rewriting the jump prompt page in thinkPHP5 (TP5). Share it with everyone for your reference, the details are as follows:
Everyone knows that the success and failure pages of the Tp framework have always been not particularly good-looking, but this also gives developers a good choice. We can rewrite this jump prompt page according to our own preferences
I am using the Tp5 framework. The rewriting of the jump prompt page of Tp5 is similar to that of Tp3. First, let’s take a look at the Tp framework. I directly pasted the code for the jump prompt page that comes with it:
{NOLAYOUT}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>跳转提示</title> <style type="text/css"> *{ padding: 0; margin: 0; } body{ background: #fff; font-family: "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif; color: #333; font-size: 16px; } .system-message{ padding: 24px 48px; } .system-message h1{ font-size: 100px; font-weight: normal; line-height: 120px; margin-bottom: 12px; } .system-message .jump{ padding-top: 10px; } .system-message .jump a{ color: #333; } .system-message .success,.system-message .error{ line-height: 1.8em; font-size: 36px; } .system-message .detail{ font-size: 12px; line-height: 20px; margin-top: 12px; display: none; } </style> </head> <body> <p class="system-message"> <?php switch ($code) {?> <?php case 1:?> <h1 id="">:)</h1> <p class="success"><?php echo(strip_tags($msg));?></p> <?php break;?> <?php case 0:?> <h1 id="">:(</h1> <p class="error"><?php echo(strip_tags($msg));?></p> <?php break;?> <?php } ?> <p class="detail"></p> <p class="jump"> 页面自动 <a id="href" href="<?php echo($url);?>" rel="external nofollow" >跳转</a> 等待时间: <b id="wait"><?php echo($wait);?></b> </p> </p> <script type="text/javascript"> (function(){ var wait = document.getElementById('wait'), href = document.getElementById('href').href; var interval = setInterval(function(){ var time = --wait.innerHTML; if(time <= 0) { location.href = href; clearInterval(interval); }; }, 1000); })(); </script> </body> </html>
Let’s rewrite it below. First of all, the css can be deleted directly. It has almost no effect. I forgot to mention it. The replacement jump prompt used is the layer plug-in. This plug-in does a good job. The official website: http://layer.layui.com/. If you want to see it, please turn left
1. Download layer plug-in, decompress it. The decompressed file package is as follows:
After decompression, it contains these three main files, of which we need to introduce layer.js into the file.
But don’t forget to introduce jquery.js
Then let’s take a look at a few more important lines of code in Tp’s original code:
<p class="success"><?php echo(strip_tags($msg));?></p> <?php echo($url);?> <?php echo($wait);?>
These three points are tips. Information, jump path, waiting time
Just have these. When rewriting, use the hidden field technique. Use the hidden field to obtain the information you need in the form of jquery, and then insert it below In js:
<script type="text/javascript"> (function(){ layer.open({ content: msg, yes: function(index, layero){ //do something layer.close(index); //如果设定了yes回调,需进行手工关闭 } }); var wait = document.getElementById('wait'), href = document.getElementById('href').href; var interval = setInterval(function(){ var time = --wait.innerHTML; if(time <= 0) { location.href = href; clearInterval(interval); }; }, 1000); })(); </script> var msg = $('#msg').val(); 提示信息 var url = $('#url').val(); 跳转url var wait = $('#wait').val(); 等待时间
Rewritten js:
<script type="text/javascript"> (function(){ var msg = $('#msg').val(); var url = $('#url').val(); var wait = $('#wait').val(); layer.open({ content: msg, yes: function(index, layero){ //do something location.href = url; layer.close(index); //如果设定了yes回调,需进行手工关闭 } }); })(); </script>
Here I did not use automatic jump, but manually clicked to jump, so the following timer was deleted directly, and It will be rewritten successfully without affecting
The above is the detailed content of Implementation method of rewriting jump prompt page in TP5. For more information, please follow other related articles on the PHP Chinese website!

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.

The main advantages of using database storage sessions include persistence, scalability, and security. 1. Persistence: Even if the server restarts, the session data can remain unchanged. 2. Scalability: Applicable to distributed systems, ensuring that session data is synchronized between multiple servers. 3. Security: The database provides encrypted storage to protect sensitive information.

Implementing custom session processing in PHP can be done by implementing the SessionHandlerInterface interface. The specific steps include: 1) Creating a class that implements SessionHandlerInterface, such as CustomSessionHandler; 2) Rewriting methods in the interface (such as open, close, read, write, destroy, gc) to define the life cycle and storage method of session data; 3) Register a custom session processor in a PHP script and start the session. This allows data to be stored in media such as MySQL and Redis to improve performance, security and scalability.

SessionID is a mechanism used in web applications to track user session status. 1. It is a randomly generated string used to maintain user's identity information during multiple interactions between the user and the server. 2. The server generates and sends it to the client through cookies or URL parameters to help identify and associate these requests in multiple requests of the user. 3. Generation usually uses random algorithms to ensure uniqueness and unpredictability. 4. In actual development, in-memory databases such as Redis can be used to store session data to improve performance and security.

Managing sessions in stateless environments such as APIs can be achieved by using JWT or cookies. 1. JWT is suitable for statelessness and scalability, but it is large in size when it comes to big data. 2.Cookies are more traditional and easy to implement, but they need to be configured with caution to ensure security.


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 Linux new version
SublimeText3 Linux latest version

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

Atom editor mac version download
The most popular open source editor

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

Zend Studio 13.0.1
Powerful PHP integrated development environment
