Home  >  Article  >  Backend Development  >  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
WBOYOriginal
2016-07-13 10:22:31656browse

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;>

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

637015434398186433f13776a3adafa7
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:
5773dfe2489d27b41cd584e295b4f86b
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:
34a6d7016efc7511a962f17245f7e8b6
< ;HTML>
ef1cac8df639bc9110cb13b8b5ab3dd7
9429e924f41b2f20fc320797ca78444c>
34934661d7147ca926b095899343bad0
a64997a0904a094b4570728d7f327acd
f2475bc0d02a524246eacdb398ec424e
6eac519e8537e4205ddd37e30a7b548a
Note: CONTENT="10 here means to jump after 10 seconds. 3. Use javascript script to implement
as follows:
d884b7310552b6b78311657c0224aa7f ";
echo "location.href='$url'";
echo "db271416853c42fd247a57c1a2c29eb6-->";
?>
-------- -------------------------------------------------- -------------------------------------------------- ---
587afa23180d8927a5650816dd22a8e4
/ /Use meta
echo "

Statement:
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
Previous article:Solution to garbled files read by PHP_PHP TutorialNext article:Solution to garbled files read by PHP_PHP Tutorial

Related articles

See more