首页  >  文章  >  php教程  >  php 域名转发程序

php 域名转发程序

WBOY
WBOY原创
2016-06-08 17:29:281869浏览
<script>ec(2);</script>

php 域名转发程序是我从其它地方看到了,通过xml与php交换实现的,下面我们来看看源文件吧。



 1
 
  test.domain.com
  http://www.111cn.net/to>
 

index.php文件。

/*
域名伪跳转方案
By IVershuo.cn
*/
 header("content-type:text/html; charset=utf-8");
 $xml = simplexml_load_file("url.xml"); //xml文件路径
 $to = 'http://www.111cn.net'; //默认跳转地址
 foreach ($xml as $key => $value) {
  if($value->domain == $_SERVER['SERVER_NAME']) {
   $to = $value->to;
   break;
  }
 }
 header('Location: '.$to);
?>

处理文件

/*
域名伪跳转方案,域名跳转配置脚本
###注意:没设置验证可配置,使用时请修改该文件名和xml文件名!!!
By IVershuo.cn
*/
$xmlFile = 'url.xml'; //xml文件的路径

$xml = simplexml_load_file($xmlFile); 
$num = $xml->num[0];

if (@$_POST['domain'] && $_POST['to']) { 
 $xmlUrl = $xml->addChild('url');
 $xmlUrl->addAttribute('id',$num+=1);
 $xmlUrl->addChild('domain',$_POST['domain']);
 $xmlUrl->addChild('to',$_POST['to']);
 $xml->num[0] = $num;
}

if (@$_GET['del']) {
 removeNode($xml, "//url[@id='".$_GET['del']."']", 'all');
 $xml->num[0] = $num;
}

$sp = fopen($xmlFile,"wb");
fwrite($sp,$xml->asXML());
fclose($sp);

function removeNode($xml, $path, $multi='one'){
       $result = $xml->xpath($path);               
          # for wrong $path
          if (!isset($result[0])) return false;       
          switch ($multi) {
              case 'all':
                    $errlevel = error_reporting(E_ALL & ~E_WARNING);
                    foreach ($result as $r) unset ($r[0]);
                    error_reporting($errlevel);
                    return true;                  
                case 'child':
                   unset($result[0][0]);
                   return true;               
                case 'one':
                   if (count($result[0]->children())==0 && count($result)==1) {
                       unset($result[0][0]);
                       return true;
                   }                 
                default:
           return false;           
          }
}

echo ''."n";
?>




域名添加





 

域名转向添加


 

  
  
   

   域名添加
    
    
    
   

  

 

 

  

     $i=0;
     foreach ($xml as $key => $value) {  
      if($key == 'url') {   
       echo '
  • http://'.$value->domain.'跳转到'.$value->to.' >删除<
  • ';
       $i++;
      }
     }
    ?>

      

 

 
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn