Home Backend Development PHP Tutorial PHP程序header location 进行跳转的注意细节及ie兼容问题!

PHP程序header location 进行跳转的注意细节及ie兼容问题!

Jun 20, 2016 pm 01:01 PM
Page jump

使用PHP程序header location 进行跳转的注意的一个细节!

众所周知,PHP网站跳转有三种方法:JS、HTML META Refresh、PHP header("location: $url")。但是这里有一个非常小的细节,很容易导致出错。

有一次制作一个跳转程序,结果忽略了这一点,导致跳转其实都是没有成功。

程序全部源码如下,程序地址:http://www.***.com/go.php

<?php error_reporting(7);
$url = urldecode( trim($_REQUEST['url']));
if($url)
{
    header("Location: $url");

} else {

    exit('Error Input,<a href="http://www.***.com/?f=go.php">go back');
}
Copy after login


当访问地址为:http://www.***.com/go.php?url=http%3A%2F%2Fwww.zbphp.com%2F 的时候,firefox浏览器是正常的。后来把这个跳转程序复制到公司的另外一个网站,让QQ上的一些好友测试,结果很多人都说打不开:IE内核的浏览器直接提示无法访问或者找不到,chrome有时候会提示被重置或找不到,使用firefox测试也偶偶会提示无法找到,但多刷新一次才显示正常。

仔细检查代码,是没有问题的。况且firefox是可以跳转,后想到了以往阅读到的一点就是:IE浏览器如果输出的内容字节太小(小于512字节),那么就会被忽略。然后将源码由header location跳转修改为 js html才所有浏览器都测试通过,原先偶偶出现firefox点击提示找不到xxx服务器也没有再出现过,现go.php全部源码:

<?php error_reporting(7);
function gheader($url)
{
echo '<html><meta http-equiv="Content-Language" content="zh-CN"><meta http-equiv="Content-Type" content="text/html;charset=gb2312"><meta http-equiv="refresh" content="0;url='.$url.'"><title>loading ... </title><div style="display:none">
<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id=\'cnzz_stat_icon_5696423\'%3E%3C/span%3E%3Cscript src=\'" + cnzz_protocol + "s9.cnzz.com/stat.php%3Fid%3D5696423%26show%3Dpic1\' type=\'text/javascript\'%3E%3C/script%3E"));</script>
</div>
<script>window.location="'.$url.'";</script>
Copy after login
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of PHP page jump function: page jump skills of header, location, redirect and other functions Detailed explanation of PHP page jump function: page jump skills of header, location, redirect and other functions Nov 18, 2023 pm 05:08 PM

Detailed explanation of PHP page jump functions: Page jump techniques for header, location, redirect and other functions, which require specific code examples. Introduction: When developing a Web website or application, jumping between pages is an essential function. PHP provides a variety of ways to implement page jumps, including header functions, location functions, and jump functions provided by some third-party libraries, such as redirect. This article will introduce in detail how to use these functions

Use uniapp to achieve page jump animation effect Use uniapp to achieve page jump animation effect Nov 21, 2023 pm 02:15 PM

Title: Using uniapp to achieve page jump animation effect In recent years, the user interface design of mobile applications has become one of the important factors in attracting users. Page jump animation effects play an important role in improving user experience and visualization effects. This article will introduce how to use uniapp to achieve page jump animation effects, and provide specific code examples. uniapp is a cross-platform application development framework developed based on Vue.js. It can compile and generate applications for multiple platforms such as mini programs, H5, and App through a set of codes.

How to use routing to implement page jump in Vue? How to use routing to implement page jump in Vue? Jul 21, 2023 am 08:33 AM

How to use routing to implement page jump in Vue? With the continuous development of front-end development technology, Vue.js has become one of the most popular front-end frameworks. In Vue development, page jump is an essential part. Vue provides VueRouter to manage application routing, and seamless switching between pages can be achieved through routing. This article will introduce how to use routing to implement page jumps in Vue, with code examples. First, install the vue-router plugin in the Vue project.

PHP code example: How to use POST to pass parameters and implement page jumps PHP code example: How to use POST to pass parameters and implement page jumps Mar 07, 2024 pm 01:45 PM

Title: PHP code example: How to use POST to pass parameters and implement page jumps In web development, it often involves the need to pass parameters through POST and process them on the server side to implement page jumps. PHP, as a popular server-side scripting language, provides a wealth of functions and syntax to achieve this purpose. The following will introduce how to use PHP to implement this function through a practical example. First, we need to prepare two pages, one to receive POST requests and process parameters

WeChat applet realizes page jump animation effect WeChat applet realizes page jump animation effect Nov 21, 2023 pm 03:10 PM

WeChat applet implements page jump animation effect In WeChat applet, page jump is a very common function. In order to improve the user experience, we can make page switching smoother and more vivid by adding animation effects. Below I will introduce how to use the WeChat applet API to achieve page jump animation effects, and attach specific code examples. First, we need to understand the life cycle function of the page in the WeChat applet. When the page is about to be displayed, you can implement page jump animation by listening to the onShow life cycle function of the page.

UniApp error: Unable to find a solution for 'xxx' page jump UniApp error: Unable to find a solution for 'xxx' page jump Nov 25, 2023 am 09:53 AM

UniApp is a cross-platform development framework that can be used to quickly develop multi-terminal applications such as applets, apps, and H5. However, during the development process using UniApp, we will also encounter some problems. One of the common problems is the error message "Unable to find 'xxx' page jump". So, how do we solve this problem? First, we need to identify what is causing the problem. This problem is usually caused by an incorrect path setting on the page. In UniApp, we usually use routing (router

How to implement page jump and navigation in uniapp How to implement page jump and navigation in uniapp Oct 20, 2023 pm 02:07 PM

How to implement page jumps and navigation in uniapp. uniapp is a front-end framework that supports one-time coding and multi-end publishing. It is based on Vue.js. Developers can use uniapp to quickly develop mobile applications. In uniapp, implementing page jumps and navigation is a very common requirement. This article will introduce how to implement page jump and navigation in uniapp, and provide specific code examples. 1. Page jump Use the methods provided by uniapp to jump the page. uniapp provides a set of methods for implementation.

Best practices for using Golang to implement page jumps Best practices for using Golang to implement page jumps Mar 05, 2024 pm 01:18 PM

Best practices for using Golang to implement page jumps When developing web applications, page jumps are a common functional requirement. In Golang, we can use some libraries to implement page jumps, such as using the Gin framework to handle routing and page jumps. This article will introduce the best practices on how to implement page jumps in Golang, and give specific code examples. Introduction to Gin framework Gin is a web framework written in Go language, which is powerful and easy to use.

See all articles