In the past few days, when I used PHP to write novel site code, I found that using header() to jump would sometimes report an error. I don’t know the reason. I checked online and some people said it was caused by something being output earlier, and some said it was caused by something being outputted earlier. It's a problem with UTF8. Before I figured it out, I found a few other jump methods and also realized this function. Let's briefly introduce it below.
1. Use HTTP header information
That is, use PHP’s HEADER function. The function of the HEADER function in PHP is to issue control instructions to the browser that should be passed through the WEB server specified by the HTTP protocol, such as declaring the type of return information ("Context-type: xxx/xxx"), the attributes of the page ("No cache", "Expire"), etc.
The method of redirecting to another page using HTTP header information is as follows:
<? if (isset($url)) { Header("HTTP/1.1 303 See Other"); Header("Location: $url"); exit; } ?>
Note that there is a space after "Localtion:".
Second, use HTML tags
Use HTML tags, that is, use REFRESH tags of META, for example:
<? if (!isset($url)) exit;?> <HTML> <HEAD> <META HTTP-EQUIV="REFRESH" CONTENT="5; URL=<? echo $url;?>> </HEAD> <BODY> </BODY> </HTML>
Three, use scripts to implement
For example:
<? $url="http://www.PHPuser.com"; echo "<!--<SCRIPT LANGUAGE="JavaScript">"; echo "location.href='$url'"; echo "</SCRIPT>-->"; ?>
src="/ inc/gad/ad2.js">