在oophp mysqli中登录脚本problrm

时间:2017-04-08 05:34:18

标签: php mysqli doophp

我使用了愚弄代码登录,但它没有登录我的管理员索引页面。有人可以帮助我吗?

  1. Session.php文件

    /**
    * Session class
    */
    
    
    
     class Session{
        public static function init(){
            session_start();
        }
    
        public static function set($key, $val){
            $SESSION['$key'] = $val;
        }
    
        public static function get($key){
            if (isset($_SESSION['$key'])) {
                return $_SESSION['$key'];
            }else{
                return false;
            }
    
        }
    
        public static function checkSession(){
            self::init();
            if (self::get('login') == false) {
                self::destroy();
                header("Location:login.php");
            }
        }
    
        public static function destroy(){
            session_destroy();
            header("Location:login.php");
        }
    
        }
    
  2. Format.php文件

    public function formatDate($date){
        return  date('F j, Y, g:i a', strtotime($date));
    }
    
    public function textShorten( $text , $limit = 400){
        $text = $text . " ";
        $text = substr($text, 0, $limit);
        $text = substr($text, 0, strrpos($text, ' '));
        $text = $text . ".....";
        return $text;
    
    }
    
    public function validation($data){
        $data = trim($data);
        $data = stripcslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    
    }
    
    }
    
  3. database.php中

    public $link;
    public $error;
    
    
    function __construct()
    {
        $this->connectDB();
    }
    
    private function connectDB(){
        $this->link = new mysqli($this->host,
    $this->user,$this->pass,$this->dbname);
        if(!$this->link){
            $this->error = "Connection failed" . $this->link;
    
        }
    
    }
    
    //Insert Data
    public function insert($data){
    $insert_row = $this->link->query($data) or die($this->link->errror.
    __LINE__);
        if($insert_row){
            return $insert_row;
        }else{
            return false;
        }
    }
    
    //Select Data
    public function select($data){
    $result = $this->link->query($data) or die($this->link->errror.
    __LINE__);
        if($result->num_rows >0){
            return $result;
        }else{
            return false;
        }
    
    }
    
    //Delete Data
    public function delete($data){
        $delete_row = $this->link->query($data) or die($this->link->errror.
     __LINE__);
        if($delete_row ){
            return $delete_row;
        }else{
            return false;
        }
    
    }
    
    }
    
    ?>
    
  4. admin index.php的header.php

                                      管理面板       - >       - >     < /脚本> - >               < /脚本> - >     

    <!-- Bootstrap CSS -->
    <!-- <link rel="stylesheet"href=
    "https://maxcdn.bootstrapcdn.com
    /bootstrap/3.3.6 /css/bootstrap.min.css"
        integrity="sha384-1q8mTJOASx8j1Au+a5    WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME 1fgjWPGmkzs7"crossorigin="anonymous"> -->
    
    <link rel="stylesheet"href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <link rel="stylesheet"href="bootstrap-3.3.7-dist/css/bootstrap-theme.min.css">
    <link rel="stylesheet"href="styles/style.css">
    <link rel="stylesheet"href="font-awesome-4.7.0/css/font-awesome.min.css"   
    </head>
    <body>
    <div class="container"><!--1. Container area begins -->
    <div class="row"><!--2 Header area begins -->
    <div class="col-md-12 h_decoration">
      <div class="header">
        <div class="row">
          <div class="col-md-1 heder_logo">
            <img src="images/img/logo.jpg"alt="">
          </div>
          <div class="col-md-8 header_title">
              <h3>Dreanland of Web Development Project</h3>
              <p>www.dreanmland.com. A promising web 
               developer organisation for you all.</p>
          </div>
          <div class="col-md-3 login_logout ">
            <div class="row">
              <div class="col-md-12">
              <?php
                if (isset($_GET['action']) && $_GET['action'] == "logout")
                {Sesssion::destroy();
                }
              ?>
                <div class="logger pull-right">
                  <ul>
                    <li><i class="fa fa-user-circle"aria-hidden="true">
      </i> Hellow Bishwajit &nbsp; ||  &nbsp; </li>
               <li><a href="?action=logout">
      <i class="fa fa-sign-out"aria-hidden="true"></i> Logout </a></li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-md-12">
          <div class=" h_links pull-right">
            <ul>
              <li><a href="">Home</a></li>
              <li><a href="">User</a></li>
              <li><a href="">Change Password</a></li>
              <li><a href="">Logout</a></li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    </div><!-- 2/ Header area ends -->
    

1 个答案:

答案 0 :(得分:-2)

在Session.php文件中需要另一个功能&#34;喜欢&#34;

public static function checkLogin()