How to implement URL forwarding code in php: 1. Use the "$_SERVER["SERVER_NAME"]" variable; 2. Use the "header("location:http://youname.com");" function; 3. Use the frame element.
Recommended: "PHP Video Tutorial"
PHP implements URL forwarding code
I spent some time researching it and found that it is quite interesting.
Mainly relies on 3 things:
1. $_SERVER["SERVER_NAME"] This variable
2. header("location:http://youname.com"); This function
3. frame This element
The implementation code is as follows:
<?php //Copyleft - Felix021 的 PHP 转发代码 http://www.felix021.com $dn=$_SERVER["SERVER_NAME"]; $url=""; //转发地址 $flag=0; //转发方式 0-直接重定向 1-frame隐藏 switch($dn) { case "www.felix021.com": case "felix021.com" $url="http://www.felix021.com/blog"; $flag=0; break; case "blog.felix021.com": $url="http://www.felix021.com/blog"; $flag=0; break; case "wap.felix021.com": $url="http://www.felix021.com/blog/mobile"; $flag=0; break; case "me.felix021.com": $url="http://localhost"; $flag=0; break; case "login.felix021.com": $url="http://www.felix021.com/login"; $flag=1; break; case "eming.felix021.com": $url="http://eming.whu.edu.cn"; $flag=0; break; case "post.felix021.com": $url="http://post.baidu.com/f?kw=%B7%EB%C3%F4"; $flag=1; break; case "tools.felix021.com": $url="http://www.felix021.com/tools"; $flag=1; break; default: $url="http://www.felix021.com/blog/"; $flag=0; break; } if($flag==0) { header("location:".$url); exit(0); } //后面的是隐藏URL转发 ?> <html> <head> <title>Felix的导航器</title> </head> <frameset framespacing="0" border="0" rows="0" frameborder="0"> <frame name="main" src="<?php echo $url; ?>" scrolling="auto"> </frameset> </html>
The above is the detailed content of How to implement URL forwarding code in php. For more information, please follow other related articles on the PHP Chinese website!