PHP Domain name Forwarding program

Source: Internet
Author: User
Tags addchild button type

PHP Domain name forwarding program is I see from other places, through XML and PHP Exchange implementation, let's take a look at the source file.

<?xml version= "1.0" encoding= "Utf-8"?>
<urls>
<num>1</num>
<url id= "1" >
<domain>test.domain.com</domain>
<to>http://www.111cn.net/to>
</url>
</urls>

index.php files.

<?php
/*
Domain name pseudo jump scheme
by ivershuo.cn
*/
Header ("content-type:text/html; Charset=utf-8 ");
$xml = simplexml_load_file ("Url.xml"); XML file path
$to = ' http://www.111cn.net '; Default Jump Address
foreach ($xml as $key => $value) {
if ($value->domain = = $_server[' server_name ']) {
$to = $value->to;
Break
}
}
Header (' Location: '. $to);
?>

Working with files

<?php
/*
Domain name pseudo jump scheme, domain name jump configuration script
# # #注意: No authentication configurable, please modify the file name and XML filename when using!!!
by ivershuo.cn
*/
$xmlFile = ' url.xml '; Path to XML file

$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[']);
$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 ' <?xml version= ' 1.0 ' encoding= ' utf-8 '?> '. n ";
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Domain Add </title>
<meta name= "Author" content= "a Restaurant | Ivershuo.cn "/>
<style type= "Text/css" >
Label {display:block;margin:10px 0;}
input {width:300px;}
Label span {color: #666;}
</style>
<script type= "Text/javascript" src= "" ></script>
<body>
<div>
<form action= "<?=$_server [' php_self ']?>" method= "POST" >
<fieldset>
<legend> Domain Add </legend>
<label for= "Domain" >
Domain name:
Http://<input type= "text" name= "domain" id= "domain"/>
<span> do not add "http://" </span>
</label>
<label for= "to" >
Turn:
<input type= "text" Name= "to" id= "to" value= "http://"/>
<span> before adding "http://" or "https://" </span>
</label>
<button type= "Submit" > Submit </button>
</fieldset>
</form>
</div>
<div>
<ul id= "listed" >
<?php
$i = 0;
foreach ($xml as $key => $value) {
if ($key = = ' url ') {
Echo ' <li><em>http://'. $value->domain. ' </em> Jump to <a href= "'. $value->to. '" > '. $value->to. ' </a>&nbsp;<a href= "'. $_server [' php_self ']. Del= '. $xml->url[$i] [' ID ']. ' " >&gt; delete &lt;</a></li> ';
$i + +;
}
}
?>
<script type= "Text/javascript" >
var Li=document.getelementbyid (' listed '). getElementsByTagName (' Li ');
for (var i=0,l=li.length;i<l; i++) {
Li[i].getelementsbytagname (' a ') [1].onclick=function () {
var u = this.parentNode.getElementsByTagName (' em ') [0].innerhtml;
if (Confirm (' OK to delete ' +u+ ')) {
return true;
} else {
return false;
}
}
}
</script>
</ul>
</div>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.