博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP一个失败的类,解析。。。。
阅读量:4488 次
发布时间:2019-06-08

本文共 1460 字,大约阅读时间需要 4 分钟。

写了几个小时,最终只是一个失败的类,伤心啊!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();
?>

转载于:https://www.cnblogs.com/yiliner/archive/2012/12/11/2812936.html

你可能感兴趣的文章
Spark项目之电商用户行为分析大数据平台之(七)数据调研--基本数据结构介绍...
查看>>
原来fb可以在一个工程里面输出多个swf模块
查看>>
Codeforces Round #271 (Div. 2) E. Pillars 线段树优化dp
查看>>
Codeforces Round #FF (Div. 2) D. DZY Loves Modification 优先队列
查看>>
【学习】logger
查看>>
Delphi APP 開發入門(十)REST Client 開發
查看>>
elk
查看>>
.net 模糊匹配路径
查看>>
用包来组织模型
查看>>
ORA-29857: 表空间中存在域索引和/或次级对象
查看>>
LeetCode58 Length of Last Word
查看>>
Python基础语法 系统学习
查看>>
推荐15款好用的JS开发工具
查看>>
ios开发之数据的持久化存储机制
查看>>
mongodb基本操作
查看>>
poj 3264
查看>>
图标跟着摄像机(Camera)orthographicSize的值改变大小
查看>>
LeetCode 386——字典序排数
查看>>
Learn day1 变量/数据类型
查看>>
go安装和开发工具安装
查看>>