[eluser]luca89pe[/eluser]
Hi, i'm new in codeigniter (i started last week using this really nice framework for a simplce project).
First of all, thank you for this usefull framework!
Then my problem is:
i want to make a simple authentication script (i don't need many users, only 1 user that can be add news and somethings, so i thought code a simple library that i can use in every page i need my authentication system.
I created my Login.php with this code:
Code:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Login{
private $user = "username";
private $pass = "password";
public function login() {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm=\"Effettua il Login!\"");
Header("HTTP/1.0 401 Unauthorized");
exit;
}
#Verifichiamo se il Login è corretto...
else if (($this->input->server('PHP_AUTH_USER') == "prova") && (hash("sha256", $this->input->server('PHP_AUTH_PW')) == "prova"))
return 1;
#Se il Login non è corretto...
else
return 0;
}
}
?>
Now in the controller where i need authentication, i wrote this (for debugging):
Code:
function index() {
if($this->login->login())
echo "OK!";
else
echo "KO!";
}
but it doesn't work: when i call the page, authentication dialog appears, i compile it with user and psw, and then i get this error:
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$input
Filename: libraries/Login.php
Line Number: 18
i saw that it appears in controllers when u don't set the parent::construct() (because input isn't initialized), but how is for libraries?
Thank you and sorry for my bad english!