| Autor | Zpráva | ||
|---|---|---|---|
| Jiří Ráb Profil |
#1 · Zasláno: 16. 1. 2019, 19:55:22
Ahoj delám příhlášení uživatele a php mi hlásí chybu
viz niže Parse error: syntax error, unexpected 'username' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in C:\wamp64\www\Maturitni_projekt\prihlaseni.class.php on line 5 posílám kod niže <?php
require_once('connect.php');
class Prihlaseni{
public username;
public heslo;
public pravo;
public id_adresa;
public id_uzivatele;
public function __construct($username,$heslo){
$this->username=$username;
$this->heslo=$heslo;
}
public function existUser(){
try {
$select="SELECT count(*) as pocet FROM uzivatele WHERE username=:username";
$select_user=DB::connect()->prepare($select);
$select_user->bindParam(":username", $this->username);
$select_user->execute();
$vysledek=$select_user->fetch(PDO::FETCH_ASSOC);
if(vysledek['pocet']>0){
return true;
}else{
return false;
}
} catch (PDOException $e) {
echo $e->getMessage();
die();
}
}
public function porovnaniHesla(){
try {
$select="SELECT heslo as hash FROM uzivatele WHERE username=:username";
$select_hash=DB::connect()->prepare($select);
$select_hash->bindParam(":username", $this->username);
$select_hash->execute();
$vysledek=$select_hash->fetch(PDO::FETCH_ASSOC);
if(password_verify($this->heslo,$vysledek['hash'])){
return true;
}else{
return false;
}
} catch (PDOException $e) {
echo $e->getMessage();
die();
}
}
public function updateLogin(){
try {
$update="UPDATE uzivatele
SET lastlogin=NOW()
WHERE username=:username";
$up=DB::connect()->prepare($update);
$up->bindParam(':username', $this->username);
$stav=$up->execute();
if($stav){
return true;
}else{
return false;
}
} catch (PDOException $e) {
echo $e->getMessage();
die();
}
}
public getInformation(){
try {
$select="SELECT id_uzivatele,pravo,id_adresa FROM uzivatele WHERE username=:username";
$select_info=DB::connect()->prepare($select);
$select_info->bindParam(":username", $username);
$select_info->execute();
$info=$select_info->fetch(PDO::FETCH_ASSOC);
$this->pravo=$info['pravo'];
$this->id_adresa=$info['id_adresa'];
$this->id_uzivatele=$info['id_uzivatele'];
} catch (PDOException $e) {
echo $e->getMessage();
die();
}
}
}
?><?php
require_once('prihlaseni.class.php');
require_once('uzivatel.class.php');
$username=$_POST['username'];
$password=$_POST['password'];
$user=new Prihlaseni($username,$password);
if($user->existUser()){
$errors_message='Daný uživatel nebyl nalezen, prosím zaregistrujte se';
header("Location:prihlaseni.php?errors=$errors_message");
}else{
if($user->porovnaniHesla()){
if($user->updateLogin() && $user->porovnaniHesla()){
session_start();
$user->getInformation();
$uzivatel = new Uzivatel($user->id_uzivatele, $user->username, $user->pravo, $user->id_adresa);
$_SESSION['uzivatel']=$uzivatel;
header("Location:my_profile.php");
}
}else{
$errors_message='Heslo není správné';
header("Location:prihlaseni.php?errors=$errors_message&username=$user->username");
}
}
?> |
||
| RastyAmateur Profil |
#2 · Zasláno: 16. 1. 2019, 19:58:29
Jiří Ráb:
zkusil bych public $username; public $heslo; public $pravo; public $id_adresa; public $id_uzivatele; getInformation ti chybí function
|
||
| Jiří Ráb Profil |
#3 · Zasláno: 16. 1. 2019, 20:06:19
dík moc
|
||
|
Časová prodleva: 7 let
|
|||
0