问题要求:根据来路分别跳转|根据输入域名跳转不同页面
PS:前提是不使用域名解析中的 URL转发!
实例: 某人注册了abc.com 和 123.com,但是只有一个主机,向实现如下操作:
访客输入:www.abc.com 访问根目录下 index.html
访客输入:www.123.com 访问根目录下 main.html
可在原默认主页代码前加上如下判断语句【语言PHP,我就是在Wordpress的首页文件index.php最前面直接加的】
<?php
//echo ‘http://’.$_SERVER['SERVER_NAME'].’:’.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
$sUrl = $_SERVER['SERVER_NAME'];
if ($sUrl=="www.abc.com")
{
echo ‘<meta http-equiv="refresh" content="0; url=http://www.abc.com/index.html">’;
}
if ($sUrl=="www.123.com")
{
echo ‘<meta http-equiv="refresh" content="0; url=http://www.abc.com/main.html">’;
}
?>
可根据自己实际要求来灵活变化语句!
要求2 根据IP访问某一目录再首页跳转到指定域名
XML/HTML代码
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title></title>
</head>
<body>
<div style="width: 800px;">
<div style="float: left;width: 300px;">
<form action="cr.php" name="form" method="post">
<input type="text" name="fold" />
<input type="hidden" name="hid" value="1"/>
<input type="submit" name="submit" value="创建"/>
</form>
</div>
<div style="float: right; width: 500px">
<?php
$d = dir(getcwd());
echo "当前存在的目录:<br/>";
while (false !== ($e = $d->read())) {
if (!is_file($e) and $e!=='.' and$e!='..') {
echo "<a href=$e target=_blank >$e</a><br>";
}
}
$d->close();
?>
</div>
</div>
<div>
<?php
if ($_POST['hid'] == 1) {
$fileName = $_POST['fold'];
if (file_exists($fileName)) {
echo '目录已存在!';
} else {
mkdir($fileName);
if (xCopy("o", $fileName, 1)) {
echo '目录创建成功!<br/>现在可以跳转到屏蔽设置页面<a href=http://'.$_SERVER['SERVER_NAME'].'/'.$fileName.'/xxabc.php >'.$fileName.'</a>';
}
}
}
function xCopy($source, $destination, $child) {
//用法:
// xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录
// xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录
if (!is_dir($source)) {
echo("Error:the $source is not a direction!");
return 0;
}
if (!is_dir($destination)) {
mkdir($destination, 0777);
}
$handle = dir($source);
while ($entry = $handle->read()) {
if (($entry != ".") && ($entry != "..")) {
if (is_dir($source . "/" . $entry)) {
if ($child)
xCopy($source . "/" . $entry, $destination . "/" . $entry, $child);
}else {
copy($source . "/" . $entry, $destination . "/" . $entry);
}
}
}
return true;
}
?>
</div>
</body>
</html>
创建的目录的首页index.php
PHP代码
<?php
header("Content-type: text/html; charset=gb2312");
//php获取ip的算法
$Clientip = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$Clientip = ($Clientip) ? $Clientip : $_SERVER["REMOTE_ADDR"];
echo $Clientip;
$url="http://whois.pconline.com.cn/jsAlert.jsp?ip=".$Clientip;
$ClientCity = file_get_contents($url);
$clientcity=substr($ClientCity, 9,(strlen($ClientCity)-14));
include 'pb.php';
?>
需要屏蔽的城市xxabc.php:
XML/HTML代码
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title></title>
</head>
<body>
<table width="1000" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="519">
<form id="form2" name="form2" method="post" action="xxabc.php">
<input type="hidden" name="oprate" value="1"/>
<b>改变首页跳转到的网址</b>
<input name="dianc" type="text" id="dianc" value="index.htm" size="30" />
<label>
<br />
<br />
</label>
<p>
<input name="checkbox[]" type="checkbox" id="npb" value="不屏蔽" checked="checked" />
不屏蔽 </p>
<p><strong>华北地区</strong><br />
<br />
<input name="checkbox[]" type="checkbox" id="bj" value="北京市" />
北京市
<input name="checkbox[]" type="checkbox" id="tj" value="天津市" />
天津市
<input name="checkbox[]" type="checkbox" id="hb" value="河北省" />
河北省
<input name="checkbox[]" type="checkbox" id="sx" value="山西省" />
山西省
<input name="checkbox[]" type="checkbox" id="nmg" value="内蒙古" />
内蒙古自治区 </p>
<p><strong>东北地区</strong><br />
<input name="checkbox[]" type="checkbox" id="ln" value="辽宁省" />
辽宁省
<input name="checkbox[]" type="checkbox" id="jl" value="吉林省" />
吉林省
<input name="checkbox[]" type="checkbox" id="hlj" value="黑龙江省" />
黑龙江省 </p>
<p><strong>华东地区</strong><br />
<input name="checkbox[]" type="checkbox" id="sh" value="上海市" />
上海市
<input name="checkbox[]" type="checkbox" id="sd" value="山东省" />
山东省
<input name="checkbox[]" type="checkbox" id="js" value="江苏省" />
江苏省
<input name="checkbox[]" type="checkbox" id="zj" value="浙江省" />
浙江省
<input name="checkbox[]" type="checkbox" id="ah" value="安徽省" />
安徽省
<input name="checkbox[]" type="checkbox" id="jx" value="江西省" />
江西省 </p>
<p><strong>华南地区</strong><br />
<input name="checkbox[]" type="checkbox" id="gz" value="广东省" />
广东省
<input name="checkbox[]" type="checkbox" id="tw" value="台湾省" />
台湾省
<input name="checkbox[]" type="checkbox" id="hk" value="香港" />
香港
<input name="checkbox[]" type="checkbox" id="am" value="澳门" />
澳门
<input name="checkbox[]" type="checkbox" id="fj" value="福建省" />
福建省
<input name="checkbox[]" type="checkbox" id="hn" value="海南省" />
海南省</p>
<p><strong>西北地区</strong><br />
<input name="checkbox[]" type="checkbox" id="sax" value="陕西省" />
陕西省
<input name="checkbox[]" type="checkbox" id="nx" value="宁夏" />
宁夏回族自治区
<input name="checkbox[]" type="checkbox" id="gs" value="甘肃省" />
甘肃省
<input name="checkbox[]" type="checkbox" id="qh" value="青海省" />
青海省
<input name="checkbox[]" type="checkbox" id="xj" value="新疆" />
新疆维吾尔自治区 </p>
<p><strong>华中地区</strong><br />
<input name="checkbox[]" type="checkbox" id="hen" value="河南省" />
河南省
<input name="checkbox[]" type="checkbox" id="hub" value="湖北省" />
湖北省
<input name="checkbox[]" type="checkbox" id="hun" value="湖南省" />
湖南省 </p>
<p><strong>西南地区</strong><br />
<input name="checkbox[]" type="checkbox" id="gx" value="广西" />
广西壮族自治区
<input name="checkbox[]" type="checkbox" id="sc" value="四川省" />
四川省
<input name="checkbox[]" type="checkbox" id="guz" value="贵州省" />
贵州省
<input name="checkbox[]" type="checkbox" id="yn" value="云南省" />
云南省
<input name="checkbox[]" type="checkbox" id="cq" value="重庆市" />
重庆市
<input name="checkbox[]" type="checkbox" id="xz" value="西藏" />
西藏自治区<br />
</p>
<p><br />
屏蔽时看到的页面
<input name="pby" type="text" value="http://<?php echo $_SERVER['SERVER_NAME']; ?>/" size="30" />
<input type="submit" value="设定" />
跳转
<input name="ttt" type="radio" value="tj" checked="checked" />
嵌入<input name="ttt" type="radio" id="tj" value="qr" /><br />
<br />
一般是本站的域名<br />
</p>
<p>
<input name="action" type="hidden" id="action" value="cdian" />
跳回原主页就输入主页网址 注意加 http://</p>
</form> </td>
<td width="461" valign="top"><br />
<a href="histery.txt" target="_blank" style="color:#FF0000">跳转历史查看</a></td>
</tr>
</table>
<?php
if($_POST['oprate']==1){
$array =$_POST['checkbox'];
$tzUrl=$_POST['pby'];
$dianc=$_POST['dianc'];
$date="";
// $clientcity="广州";
for($i=0;$i<count($array);$i++){
// echo $array[$i];
$date.="if (strpos('\''.\$clientcity.'\'','".$array[$i]."')){header('Location:".$tzUrl."');}else{ header('Location:".$dianc."');}\n \r";
}
if(!file_exists("pb.php")){
fwrite("pb.php","");
}
$file=fopen("pb.php","w+");
fwrite($file,"<?".$date."?>");
$histeryTime=date("Y-m-d H:i:s");
echo $histeryTime;
if(!file_exists("histery.txt")){
fwrite("histery.txt","");
}
$histery= fopen("histery.txt", "a+");
fwrite($histery, $histeryTime.$date);
fclose($file);
fclose($histery);
}
?>
</body>
</html>
执行后会生成两个文件:pb.php和histery.txt
公司需要的东西,一般人可能用不上。这也是我自学PHP的第一个作品!纪念下
以上内容均来自互联网, 本次内容有 铜鼓网 酒店预订 宾馆预订 整理
文档下载:https://blog.tonggu.org/upload/2012/10/php根据来路或ip判断跳转某域名.doc

已有 676 位网友参与,快来吐槽:
发表评论