Hej alle. Jeg har tilføjet et admin panel til min side.. Men når jeg skriver det brugernavn og kode der står i DB logger den ikke ind..
Login.php
- <!DOCTYPE html>
- <head>
- <title>Log ind til administrator panelet</title>
- <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
- <link rel="stylesheet" type="text/css" href="css/index.css">
- </head>
- <body>
- <form action="login-action.php" method="post">
- <fieldset>
- <legend>Udfyld følgende:</legend>
- <p>
- <label for="username">Brugernavn: </label>
- <input type="text" name="username" id="username" value="" />
- </p>
- <p>
- <label for="password">Adgangskode: </label>
- <input type="password" name="password" id="password" value="" />
- </p>
- <p>
- <label for="remember">
- <input type="checkbox" name="remember" id="remember" value="1" /> Husk mig
- </label>
- </p>
- </fieldset>
- <p>
- <input type="submit" value="Godkend" /> <input type="reset" value="Nulstil" />
- </p>
- </form>
- </body>
- </html>
index.php
- <?php
- include_once 'admin-class.php';
- $admin = new itg_admin();
- $admin->_authenticate();
- ?>
- <!DOCTYPE html>
- <head>
- <title>Administrator side</title>
- <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
- <link rel="stylesheet" type="text/css" href="css/index.css">
- </head>
- <body>
- <fieldset>
- <legend>Velkommen <?php echo $admin->get_nicename(); ?></legend>
- <p>
- Her er basis information:
- </p>
- <p>
- Brugernavn: <?php echo $_SESSION['admin_login']; ?>
- </p>
- <p>
- Email: <?php echo $admin->get_email(); ?>
- </p>
- </fieldset>
- <p>
- <input type="button" onclick="javascript:window.location.href='logout.php'" value="logout" />
- </p>
- </body>
- </html>
login-action.php
- <?php
- include_once 'admin-class.php';
- $admin = new itg_admin();
- $admin->_login_action();
admin-class.php
- <?php
-
- include_once '../db/db.php';
-
-
-
-
-
- class itg_admin {
-
-
- static $abs_path;
-
-
- var $post = array();
-
-
- var $get = array();
-
-
- public function __construct() {
- session_start();
-
-
- self::$abs_path = dirname(dirname(__FILE__));
-
-
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->post = $_POST;
- if(get_magic_quotes_gpc ()) {
-
- array_walk_recursive($this->post, array($this, 'stripslash_gpc'));
- }
- }
-
-
- $this->get = $_GET;
-
- array_walk_recursive($this->get, array($this, 'urldecode'));
- }
-
-
- public function get_nicename() {
- $username = $_SESSION['admin_login'];
- global $db;
- $info = $db->get_row("SELECT `nicename` FROM `user` WHERE `username` = '" . $db->escape($username) . "'");
- if(is_object($info))
- return $info->nicename;
- else
- return '';
- }
-
-
- public function get_email() {
- $username = $_SESSION['admin_login'];
- global $db;
- $info = $db->get_row("SELECT `email` FROM `user` WHERE `username` = '" . $db->escape($username) . "'");
- if(is_object($info))
- return $info->email;
- else
- return '';
- }
-
-
- public function _authenticate() {
-
- if(!isset($_SESSION['admin_login'])) {
-
- if(isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
-
- if($this->_check_db($_COOKIE['username'], $_COOKIE['password'])) {
- $_SESSION['admin_login'] = $_COOKIE['username'];
- header("location: index.php");
- die();
- }
- else {
- header("location: login.php");
- die();
- }
- }
- else {
- header("location: login.php");
- die();
- }
- }
- }
-
-
-
- public function _login_action() {
-
-
- if(!isset($this->post['username']) || $this->post['username'] == '' || !isset($this->post['password']) || $this->post['password'] == '') {
- header ("location: login.php");
- }
-
-
- $username = $this->post['username'];
- $password = md5(sha1($this->post['password']));
-
-
- if($this->_check_db($username, $password)) {
-
- $_SESSION['admin_login'] = $username;
-
-
- if(isset($this->post['remember'])) {
-
- setcookie('username', $username, time() + 1*24*60*60);
- setcookie('password', $password, time() + 1*24*60*60);
- } else {
-
- setcookie('username', '', time() - 1*24*60*60);
- setcookie('password', '', time() - 1*24*60*60);
- }
-
- header("location: index.php");
- }
- else {
- header ("location: login.php");
- }
-
- die();
- }
-
-
-
-
- private function _check_db($username, $password) {
- global $db;
- $user_row = $db->get_row("SELECT * FROM `user` WHERE `username`='" . $db->escape($username) . "'");
-
-
- if(is_object($user_row) && md5($user_row->password) == $password)
- return true;
- else
- return false;
- }
-
-
- private function stripslash_gpc(&$value) {
- $value = stripslashes($value);
- }
-
-
- private function htmlspecialcarfy(&$value) {
- $value = htmlspecialchars($value);
- }
-
-
- protected function urldecode(&$value) {
- $value = urldecode($value);
- }
- }
Kan virkeligt ikke finde fejlen! Så håber der er en venlig sjæl der vil kigge det igennem! :-)
Tak på forhånd.