How to prevent web pages from jumping in php?

青灯夜游
Release: 2023-02-28 19:02:01
Original
3188 people have browsed it

How to prevent web pages from jumping in php? The following article will introduce you to some methods in PHP to prevent web pages from jumping. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to prevent web pages from jumping in php?

How to prevent web pages from jumping in PHP

1. Through the header function Prevent web pages from jumping

The main function of the header() function is to output the HTTP protocol header (header) to the browser.

Syntax

void header (string string [,bool replace [,int http_response_code]])
Copy after login

The optional parameter replace specifies whether to replace the previous similar header or add a header of the same type. The default is replacement.

The second optional parameter http_response_code forces the HTTP corresponding code to the specified value. The Location type header in the header function is a special header call, often used to implement page jumps.

Note

1) There cannot be a space between location and ":", otherwise it will not jump.

2). There cannot be any output before using the header.

2. Use JavaScript’s window.location.href method in PHP to prevent web pages from jumping

Can be placed anywhere

< ?php
$url = "http://bbs.lampbrother.net"; 
echo "< script language=&#39;javascript&#39; type=&#39;text/javascript&#39;>"; 
echo "window.location.href=&#39;$url&#39;"; echo "< /script>";
?>
Copy after login

For more related knowledge, please pay attention to PHP中文网! !

The above is the detailed content of How to prevent web pages from jumping in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template