Hongmu Notes
Home Language Notes Use PHP to output HTML code that pauses for three seconds before redirecting to a specified URL.
Language Notes PHP

Use PHP to output HTML code that pauses for three seconds before redirecting to a specified URL.

Use PHP to output HTML code that pauses for three seconds before redirecting to a specified URL.

In PHP, you can use output HTML and JavaScript to jump to the specified address after a three-second pause. Here is some sample code:

 隐藏内容:登录后可查看
echo '<html>';
echo '<head>';
echo '<meta http-equiv="refresh" content="3; url=https://www.example.com">';
echo '</head>';
echo '<body>';
echo '<p>请等待三秒钟,即将跳转到 <a href="https://www.example.com">https://www.example.com</a>。</p>';
echo '</body>';
echo '</html>';

In the above code,<meta>tag is used to set HTTP response headers that instruct the browser to jump to the specified URL after three seconds.<p>Markers are used to display a message telling the user what is about to happen. Note that you can changecontentThe value of the property to specify additional wait time (in seconds) and URL.

If you don't want to display the waiting message, you can change<meta>Tags are replaced with JavaScript code, for example:

echo '<html>';
echo '<head>';
echo '<script>setTimeout(function() { window.location.href = "https://www.example.com"; }, 3000);</script>';
echo '</head>';
echo '</html>';

In the above code,<script>tag is used to define an anonymous function that usessetTimeoutThe function sets a timer to redirect the browser to the specified URL after three seconds. Note that the time unit used by the timer is in milliseconds, so you need to multiply the wait time by 1000.

Common codes

if(count($u) >= $_GET['n']){
    $_GET['n']++;
    $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?n=".$_GET['n'];
    echo '<html>';
    echo '<head>';
    echo '<meta http-equiv="refresh" content="1; url='.$url.'">';
    echo '</head>';
    echo '<body>';
    echo '<p>请等待三秒钟,即将跳转到 <a href="'.$url.'">'.$url.'</a>。</p>';
    echo '</body>';
    echo '</html>';
}
微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

(Adaptive mobile phone version) Immigration and study abroad website pbootcms template Education and training institution website source code download 0701

(Adaptive mobile phone version) Immigration and study abroad website pbootcms template Education and training institution website source code download 0701 Practical Collection pbootcms Template

A PbootCMS website template designed for immigration, overseas study, and educational training purposes, compatible with both PC and WAP devices. Its professional, international design makes it ideal for immigration agencies and overseas study institutions to showcase their services and success stories. This template helps overseas education service providers attract interested students and families online. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 51
Responsive Heavy-Duty Equipment Accessories Website Template 0369

Responsive Heavy-Duty Equipment Accessories Website Template 0369 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the heavy-duty equipment and accessories industry, featuring a professional industrial design style that effectively showcases heavy-duty equipment products, accessory ranges, technical specifications, and industrial applications. It enables heavy-duty equipment manufacturers to present their products online and attract industrial customers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 52
Highly efficient web page caching page code

Highly efficient web page caching page code Summary of pitfalls

Previously studied, high-performance PHP cache system design: intelligent cleaning and counting management. But I found that this can only cache individual html, not some data that I want to cache. At the same time, in order to solve the limitations of inode. So I tried to put the cache files into the db database to achieve efficient storage. 1. System Overview Core Class: ApiCache (located in ApiCache.php) Cache Mode: Normal…
👁 161
(Adaptive mobile version) Responsive intelligent logistics equipment website PBootCMS template – Download HTML5 blue AI equipment website source code – 0702

(Adaptive mobile version) Responsive intelligent logistics equipment website PBootCMS template – Download HTML5 blue AI equipment website source code – 0702 Practical Collection pbootcms Template

A responsive intelligent logistics equipment and AI-powered device PbootCMS website template, compatible with both PC and WAP devices. Featuring a cutting-edge design style, this template is ideal for showcasing high-end equipment such as smart warehousing systems and logistics robots. It enables smart logistics enterprises to present their solutions online and attract industry clients. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www....
👁 56
Responsive Furniture Sales Website Template 0370

Responsive Furniture Sales Website Template 0370 Practical Collection Yiyou template

An EyouCMS responsive website template designed specifically for the furniture and home furnishings sales industry. Its modern and practical design is ideal for showcasing furniture products, furniture collections, home decor combinations, and brand stories. This template helps furniture brands showcase their products online and attract home consumers. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 37
(Adaptive Mobile Version) Responsive Blue Mechanical and Electrical Equipment Installation PBootCMS Template – Download HTML5 Mechanical and Electrical Installation Project Website Template (0703)

(Adaptive Mobile Version) Responsive Blue Mechanical and Electrical Equipment Installation PBootCMS Template – Download HTML5 Mechanical and Electrical Installation Project Website Template (0703) Practical Collection pbootcms Template

A responsive blue PbootCMS website template designed for mechanical and electrical installation projects, compatible with both PC and WAP devices. Its professional and sophisticated design is ideal for showcasing mechanical and electrical installation projects, technical expertise, and project case studies. This template helps mechanical and electrical installation companies demonstrate their construction capabilities online and secure project partnerships. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www....
👁 51