ho creato un login con delle classi pero mi da un errore
( ! ) Fatal error: Uncaught Error: Call to undefined method UserController::checkLogin() in C:\xampp\htdocs\progettoPersonale\controllers\UserController.php on line 17
( ! ) Error: Call to undefined method UserController::checkLogin() in C:\xampp\htdocs\progettoPersonale\controllers\UserController.php on line 17
Call Stack
# Time Memory Function Location
1 0.0010 360312 {main}( ) ...\login.php:0
2 0.0030 384208 UserController->__construct( ) ...\login.php:7
le due classi sono :
( ! ) Fatal error: Uncaught Error: Call to undefined method UserController::checkLogin() in C:\xampp\htdocs\progettoPersonale\controllers\UserController.php on line 17
( ! ) Error: Call to undefined method UserController::checkLogin() in C:\xampp\htdocs\progettoPersonale\controllers\UserController.php on line 17
Call Stack
# Time Memory Function Location
1 0.0010 360312 {main}( ) ...\login.php:0
2 0.0030 384208 UserController->__construct( ) ...\login.php:7
le due classi sono :
PHP:
class UserController
{
public $username = '';
private $logged = false;
private $usermodel = '';
public function __construct()
{ $this->usermodel = new UserModel();
session_start();
if ($_SERVER['REQUEST_METHOD']=='POST' && isset($_GET['action'])&& $_GET['action']== 'login' ){
$username = (isset($_POST['username']))? $_POST['username'] :false ;
$password = (isset($_POST['password']))? $_POST['password'] :false ;
var_dump($password,$username);
if ($username !=false && $password !=false && $this->usermodel->checkLogin( $username, $password )){
$this->username =$username ;
$this->logged = true ;
$_SESSION['username']= $username ;
$_SESSION['logged']= true ;
$_SESSION[ 'message' ] = 'Login effettuato correttamente';
}else{
$_SESSION[ 'message' ] = 'Errore con il login; riprovare!';
}
}
elseif (isset($_GET['action'])&& $_GET['action']== 'logout'){
unset($_SESSION['username']);
unset($_SESSION['logged']);
$_SESSION[ 'message' ] = 'Logout effettuato correttamente';
}
elseif (isset($_SESSION['username'])&& isset($_SESSION['logged'])){
$this->username = $_SESSION['username'] ;
$this->logged = true ;
}
$this->redirectToProperArea();
}
class UserModel
{
private $dbconn = null ;
public function __construct()
{
$this->dbconn = new DbConnector();
}
public function checkLogin($username, $password ){
$newpassword =password_hash($password, PASSWORD_DEFAULT);
$res=$this->dbconn->select(
array('id_utente'),
'iscritti',
'nome_utente='.$username.'&& password='.$newpassword
);
$num_rows=$this->dbconn->num_rows($res);
if ($num_rows ==1){
return true ;
}else {
return false ;
}
}
}
Ultima modifica di un moderatore: