PHP一个失败的类,解析。。。。
写了几个小时,最终只是一个失败的类,伤心啊!BUG众多。。。
<?php
class yi
{
var $stice=array();
var $path;
function __construct()
{
switch($_SERVER['HTTP_HOST'])
{
case "127.0.0.1":
$this->path="a";
break;
}
}
function y301($old,$new)
{
if($_SERVER['HTTP_HOST']==$old)
{
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location: http://'.$new.$_SERVER['REQUEST_URI']);
}
}
function read()
{
$file=$_SERVER['REDIRECT_URL'];
$fi=substr($file,-5);
$f_c=stripos($fi,".");
if($f_c!==false)
{
$var_path="./".$this->path.$file;
if(file_exists($var_path))
{
if(substr($var_path,-4)==".php")
{
include($var_path);
}
else
{
echo file_get_contents($var_path);
}
}
else
{
header('HTTP/1.1 404 Not Found');
header("status: 404 Not Found");
echo "该页面无法找到<a href='/'>点击返回首页</a>";
}
}
else
{
while(1)
{
if(substr($file,-5)=="/" || substr($file,-5)=="\\")
{
$file=substr($file,sizeof($file),sizeof($file)-1);
}
else
{
break;
}
}
$r_b=false;
foreach($this->stice as $k=>$v)
{
if(file_exists("./".$this->path."/".$file."/".$v))
{
if($v=="index.php")
{
include("./".$this->path."/".$file."/".$v);
}
else
{
echo file_get_contents("./".$this->path."/".$file."/".$v);
}
$r_b=true;
break;
}
}
if(!$r_b)
{
header('HTTP/1.1 404 Not Found');
header("status: 404 Not Found");
echo "该页面无法找到<a href='/'>点击返回首页</a>";
}
}
}
}
$host=new yi;
$host->y301("localhost","127.0.0.2");
$host->stice=array("index.html","index.php");
$host->read();
?>
<?php
class yi
{
var $stice=array();
var $path;
function __construct()
{
switch($_SERVER['HTTP_HOST'])
{
case "127.0.0.1":
$this->path="a";
break;
}
}
function y301($old,$new)
{
if($_SERVER['HTTP_HOST']==$old)
{
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location: http://'.$new.$_SERVER['REQUEST_URI']);
}
}
function read()
{
$file=$_SERVER['REDIRECT_URL'];
$fi=substr($file,-5);
$f_c=stripos($fi,".");
if($f_c!==false)
{
$var_path="./".$this->path.$file;
if(file_exists($var_path))
{
if(substr($var_path,-4)==".php")
{
include($var_path);
}
else
{
echo file_get_contents($var_path);
}
}
else
{
header('HTTP/1.1 404 Not Found');
header("status: 404 Not Found");
echo "该页面无法找到<a href='/'>点击返回首页</a>";
}
}
else
{
while(1)
{
if(substr($file,-5)=="/" || substr($file,-5)=="\\")
{
$file=substr($file,sizeof($file),sizeof($file)-1);
}
else
{
break;
}
}
$r_b=false;
foreach($this->stice as $k=>$v)
{
if(file_exists("./".$this->path."/".$file."/".$v))
{
if($v=="index.php")
{
include("./".$this->path."/".$file."/".$v);
}
else
{
echo file_get_contents("./".$this->path."/".$file."/".$v);
}
$r_b=true;
break;
}
}
if(!$r_b)
{
header('HTTP/1.1 404 Not Found');
header("status: 404 Not Found");
echo "该页面无法找到<a href='/'>点击返回首页</a>";
}
}
}
}
$host=new yi;
$host->y301("localhost","127.0.0.2");
$host->stice=array("index.html","index.php");
$host->read();
?>
坐页论道不可谓一,太极之内是为永恒

浙公网安备 33010602011771号