URL***的實例解釋

URL***:顧名思義,就是利用URL來進行***,***方式就是更改地址欄中的$_GET的參數,另外進行一些必要的猜想,好比如下面的URL爲例:php

http://www.myfreax.com/category.php?category=mysql3

***者能夠了更改後面的參數mysql3的數值,進行猜想,或者結合一些其它的手段,我所知道有兩個個Linux發行版專作***工具的,和測試的,很是強大,都是基於ubuntu製做的,html

BackTrack  #這個曾經在我學習Linux是安裝過,專門用來***和***
blackbox Linux  #這個就沒有使用過了

下面就是實例了,:
mysql

<?php
    /**
     * 
     *  @author Freax
     *  @2014-3-24
     *  @contact  huangyanxiong2013@gmail.com
     * 
     */
    define('FREAX', true);
    require_once 'include/init.php';
    'http://www.myfreax.com/category.php?category=PHP5';//正常url是這樣的 
    class category{
        /**
         * 數據庫      對象
         * @var Object
         */
        public $db;
        /**
         * smarty 對象
         * @var Object
         */
        public $smarty;
        /**
         * 地址  指向須要顯示的頁面
         * @var String
         */
        public $action;
        /**
         * 分頁類
         * @var Object
         */
        public $Page;
        /**
         * 緩存id
         * @var string
         */
        public $cacheid;
        /**
         * 初始化
         * @var String
         */
        public function __construct($db,$smarty,$page){  //作完這個函數就是將頁面顯示出來
            $this->db=$db;
            $this->smarty=$smarty;
            $this->Page=$page;
            $this->getAtion();
            $this->getData();
            $this->display();
        }
        /**
         * 獲取地址    這個是很是關鍵的這裏作的不得好也是***的機會
         * 在在這個函數中,因爲我只想獲取到的是一個數字其它都是不要的,因此要將其它過濾
         */
        public function getAtion(){
            $bool=preg_match_all('/\d+/', $_SERVER['QUERY_STRING'],$match);
            /* 若是按照我正常些的url來執行的話,根本就不要這個判斷,也能夠正常執行,
             * 可是有意的人就會嘗試更改這些參數 ,這裏我須要獲取到數據庫分類的id,
             * 而且使用這個id查詢數據,不免不會受到sql***的,因此有這個判斷*/
            if (!$bool) {
                header("HTTP/1.1 301 Moved Permanently");   //***者更改參數後你將重定向404,或者其它相對安全的頁面,不過建議仍是重定向404靜態頁面,
                                                            //我這裏是首頁,由於我首頁是不接受任何參數的
                header("location:http://".WEB);
                exit();   //記得要退出否則重定向後仍是會執行的,由於php解釋器沒有看到結束標籤\?\>
            }else {
                $this->action=$match[0][0];
            }
        }
        /**
         * 獲取緩存id
         * @return string
         */
        public function getcacheid(){
            $this->cacheid=(isset($_GET['category'])?$_GET['category']:'').@(isset($_GET['page'])?$_GET['page']:'');
            return $this->cacheid;
        }
        /**
         * 根據地址 獲取對應的數據
         * 根據地址判斷smarty是否有緩存
         * 沒有緩存區數據庫獲取
         * 賦值給模板
         */
        public function getData(){
            /* 這裏根據cacheid判斷是否存在緩存,若是沒有緩存則從數據庫中獲取數據 ,因爲cacheid在客戶端也是能夠更改的,
             * http://www.myfreax.com/category.php?category=PHP2&page=23 這個url就是很形的了,一個是分類,一個是頁數,
             * 客戶端能夠隨意更改頁數,cacheid永遠不一樣,生成的緩存,也會增多,只要來個循環,就生成N的文件緩存
             * 爲何我這裏能夠隨意更改$_GET參數都不會參數,均可以執行,由於$article=$this->db->selectArrs。。。。。。。。。。。。這個語句來講,即便沒有從數據庫中獲取到數據也會返回空數組*/
            if (!$this->smarty->isCached('index.html',$this->getcacheid())){
                $nav=$this->db->selectArrs('select * from '.PREFIX.'class');
                $this->Page->getTotalPageClass($this->db,PREFIX.'article','typeid',$this->action);
                $this->Page->getcurrPage();
                $this->Page->getStartPage();
                $article=$this->db->selectArrs('select  '.PREFIX.'article.*,'.PREFIX.'class.name from '.PREFIX.'article left join blog_class  on ('.PREFIX.'article.typeid='.PREFIX.'class.id)   where typeid= '.$this->action.' order by  id desc  limit '.$this->Page->startPage .','. $this->Page->paging);
                /* 因此這裏就加上一個斷
                 *  */
                if (!$article) {
                    header("HTTP/1.1 301 Moved Permanently");
                    header("location:http://".WEB);
                    exit();
                }
                $this->Page->getLinkPage('category.php');
                $this->Page->getClassPage($article[0]['name'].$article[0]['typeid']);
                $pagelink=$this->Page->createPageLinks();
                $navAtcion=@$article[0]['name'];
                $this->smarty->assign('articles',$article);
                $this->smarty->assign('navs',$nav);
                $this->smarty->assign('navAction',$navAtcion);
                $this->smarty->assign('pagelink',$pagelink);
                }
            }
        /**
         *  返回給前能夠對模板進行一些操做
         *  將數據返回給用戶
         */
        public function display(){
            $this->smarty->display('index.html',$this->getcacheid());
        }
    }
    /**
     * 實例化category類
     */
    new category($db,$smarty,$page);
?>
相關文章
相關標籤/搜索