Home > Backend Development > PHP Tutorial > PHP realizes the method of automatically jumping to the corresponding page according to the device type, php automatic jump_PHP tutorial

PHP realizes the method of automatically jumping to the corresponding page according to the device type, php automatic jump_PHP tutorial

WBOY
Release: 2016-07-13 10:22:31
Original
712 people have browsed it

PHP realizes the method of automatically jumping to the corresponding page according to the device type, php automatically jumps

With the popularity of today’s mobile devices, surfing the Internet has become more convenient than in the past. For mobile terminals such as Android smartphones and iPhone/iPad, many websites have successively launched web pages for access by mobile devices such as computers and such mobile phones. The example code described in this article can automatically jump to pages suitable for browsing based on these mobile device terminals. That is, it determines the PC side or the smart side of the mobile site and jumps.

The complete example code is as follows:

<&#63;php
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$iphone = (strpos($agent, 'iphone')) &#63; true : false;
$ipad = (strpos($agent, 'ipad')) &#63; true : false;
$android = (strpos($agent, 'android')) &#63; true : false;
if($iphone || $ipad)
{
 echo "<script>window.location.href='pc.html'</script>";//这里也可以是网址
}
if($android){
 echo "<script>window.location.href='andorid.html'</script>";//这里也可以是网址
}
&#63;>

Copy after login

HereUse the built-in function HTTP_USER_AGENT in PHP to obtain the client device type, then use the string processing function to extract it, then determine what device it is, and automatically locate the appropriate web page or page to send based on the device. to the client.

How to realize automatic jump of php page after 15 seconds


Basic HTML language can do it

The code can be added anywhere, This is an HTML tag. It can be recognized by any browser

How to realize the php page automatically jumps after 15 seconds

Php itself does not have a complete page jump function. Maybe the Header function is one, but it can only be used for the first line of the page. If placed at the end of the Php page, unless the previous Php does not output any characters, an error will be reported. The following are three methods for automatic page jump in Php:
1: Use the Header function.
Two: Use HTML inherent tags. (Not only applicable to Php, but also applicable to ASP, .Net, and Jsp).
Three: Output javascript and use Js code to achieve the purpose of automatic jump to the Php page. (It also applies to languages ​​other than Php, but the corresponding language codes are different). 1. Use HTTP header information (Header function)
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: xxxx/xxxx"), the attributes of the page ("No cache", "Expire"), etc.
The method to use HTTP header information to make Php automatically jump to another page is as follows:
$url = index.php
Header("HTTP/1.1 303 See Other") ;
Header("Location: $url");
exit;
?>
Note that there is a space after "Localtion:". 2. Use HTML tags (REFRESH attribute in META)
Use HTML tags, that is, use META’s REFRESH tag. For example:

< ;HTML>

as follows:
$url=index.php;
echo "";
?>
-------- -------------------------------------------------- -------------------------------------------------- ---
//PHP comes with function
Header("Location: www.php.com ");
?>
/ /Use meta
echo "

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template