In PHP development, especially in MVC frameworks or projects, you will encounter many jump situations, such as jumps after successful or failed login, etc.
The main content of this article is the implementation process of the jump prompt box based on PHP. The code is attached, friends in need can refer to it.
The following is based on the MVC framework development, with examples:
In the basic controller class: Conrtoller.class.php
<?php /**
* 基础控制器类
*/
class Controller {
/**
* 跳转
* $url 目标url
* $info 提示信息
* $time 等待时间(单位秒)
*/
protected function jump($url,$info=NULL,$time=3) {
//判断是立即跳转还是刷新跳转
if(is_null($info)) {
//立即跳转
header('location:'. $url);
die;
} else {
//刷新跳转,给出提示
echo <<<TIAOZHUAN
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>提示信息</title>
<style>
* {margin:0; padding:0;}
div {width:390px; height:287px; border:1px #09C solid; position:absolute; left:50%; margin-left:-195px; top:10%;}
div h2 {width:100%; height:30px; line-height:30px; background-color:#09C; font-size:14px; color:#FFF; text-indent:10px;}
div p {height:120px; line-height:120px; text-align:center;}
div p strong {font-size:26px;}
</style>
<div>
<h2 id="提示信息">提示信息</h2>
<p>
<strong>$info</strong><br>
页面在<span>$time</span>秒后会自动跳转,或点击<a>立即跳转</a>
</p>
</div>
<script>
var url = document.getElementById('tiao').href;
function daoshu(){
var scd = document.getElementById('second');
var time = --scd.innerHTML;
if(time<=0){
window.location.href = url;
clearInterval(mytime);
}
}
var mytime = setInterval("daoshu()",1000);
</script>
TIAOZHUAN;
die;
}
}
}
In the automatic loading of MVC, automatically load and register Controller.class.php
After inheriting the above Controller.class.php basic controller class through different controller classes, you can call the defined jump Transfer prompt.
<?php /**
* 后台管理员控制器(登录、注销、管理员的增删改查等)
*/
class AdminController extends Controller {
/**
* 展示登录表单动作
*/
public function loginAction() {
// 载入当前的视图文件
$this->display('login.html');
}
/**
* 后台注销功能
*/
public function logoutAction() {
@session_start();
// 删除相关会话数据
unset($_SESSION['adminInfo']);
// 删除会话数据区
session_destroy();
// 立即跳转到登录页面
$this->jump('index.php?c=Admin&a=login','您已退出后台登录!');
}
}
Of course, this is implemented in MVC, you can also use jump() separately.
Attached is a rendering:

Related tutorials: PHP video tutorial
The above is the detailed content of Implementation example of jump prompt box based on PHP. For more information, please follow other related articles on the PHP Chinese website!
The Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AMWhat’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.
PHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AMPHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.
PHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AMPHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
PHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AMPHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.
Choosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AMPHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.
PHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AMPHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.
PHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AMPHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip
How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AMPHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.







