好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php如何实现URL转发代码

php实现URL转发代码的方法:1、使用“$_SERVER["SERVER_NAME"]”变量;2、通过“header("location:http://youname测试数据");”函数;3、利用frame元素。

推荐:《PHP视频教程》

PHP实现URL转发代码

花了一点时间研究了一下,发现还是蛮有意思的

主要是依靠3个东西:

1. $_SERVER["SERVER_NAME"] 这个变量

2. header("location:http://youname测试数据"); 这个函数

3. frame 这种元素

实现代码如下:

<?php
//Copyleft  -  Felix021 的 PHP 转发代码 http://HdhCmsTestfelix021测试数据
$dn=$_SERVER["SERVER_NAME"];
$url=""; //转发地址
$flag=0; //转发方式 0-直接重定向 1-frame隐藏
switch($dn)
{
  case "HdhCmsTestfelix021测试数据":
  case "felix021测试数据"
    $url="http://HdhCmsTestfelix021测试数据/blog";
    $flag=0;
    break;
  case "blog.felix021测试数据":
    $url="http://HdhCmsTestfelix021测试数据/blog";
    $flag=0;
    break;
  case "wap.felix021测试数据":
    $url="http://HdhCmsTestfelix021测试数据/blog/mobile";
    $flag=0;
    break;
  case "me.felix021测试数据":
    $url="http://localhost";
    $flag=0;
    break;
  case "login.felix021测试数据":
    $url="http://HdhCmsTestfelix021测试数据/login";
    $flag=1;
    break;
  case "eming.felix021测试数据":
    $url="http://eming.whu.edu.cn";
    $flag=0;
    break;
   
  case "post.felix021测试数据":
    $url="http://post.baidu测试数据/f?kw=%B7%EB%C3%F4";
    $flag=1;
    break;
   
  case "tools.felix021测试数据":
    $url="http://HdhCmsTestfelix021测试数据/tools";
    $flag=1;
    break;
 
  default:
    $url="http://HdhCmsTestfelix021测试数据/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>

以上就是php如何实现URL转发代码的详细内容!

查看更多关于php如何实现URL转发代码的详细内容...

  阅读:49次