Segui il video qui sotto per vedere come installare il nostro sito come web app sulla tua schermata principale.
Nota: Questa funzionalità potrebbe non essere disponibile in alcuni browser.
Pubblicità
ciao ho provato addirittura settando la register, e addirittura prendendo una demo già fatta
ma io da phpstorm non riesco a debuggare e vedere le variabili cosa contengono
ti posto la funzione register da me creata e la login
register
PHP:public function register($date, $username, $password, $email){ $sql = $this->_pdo->prepare('SELECT * FROM users WHERE username = :username or email= :username'); $sql->bindParam(':username', $username); $sql->execute(); $res = $sql->fetchAll(PDO::FETCH_ASSOC); if ($sql->rowCount() === 1) { $res = "Username or email registred yet"; return $res; }else { $sql = $this->_pdo->prepare('Insert Into users (date_of_birth, username, password,email) VALUES ($date,$username,$password,$email)'); $sql->bindParam(':username', $username); $sql->bindParam(':date_of_birth', $date); $sql->bindParam(':password', $password); $sql->bindParam(':email', $email); $sql->execute(); $res = $sql->fetchAll(PDO::FETCH_ASSOC); $res = "Successfully Registrated"; return $res; header("location: index.php"); } }
poi la login
PHP:public function login($username, $password) { $sql = $this->_pdo->prepare('SELECT * FROM users WHERE username = :username'); $sql->bindParam(':username', $username); $sql->execute(); $res = $sql->fetchAll(PDO::FETCH_ASSOC); if ($sql->rowCount() === 1) { if (password_verify($password, $res[0]['password'])) { $_SESSION['login_user'] = $username; header("location: loggedin.php");//A posto del redirect puoi anche ritornare TRUE/FALSE o $res } else { $res = "Your Password is invalid"; return $res; } } else { $res = "Your Login Name is invalid"; return $res; } }
poi nella pagina register ho fatto questi
PHP:ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require_once 'main/main.php'; $db = new dbconnect; $main = new main; $dbwork = ""; $main->sec_session_start(); var_dump($_POST); $username = ""; $password = ""; $email = ""; $date = ""; //if(!empty($_POST)) { if($_SERVER["REQUEST_METHOD"] == "POST"){ if(isset($_POST['username'])) { // check if the username has been set $username = $_POST['username']; echo main::sanitize($_POST['username'], 'string'); } if(isset($_POST['password'])) { $password = $_POST['password']; echo main::sanitize($_POST['password'], 'string'); //echo '<script> hide_login(); </script>'; } if(isset($_POST['email'])){ $email = $_POST['email']; echo main::sanitize($_POST['email'], 'string'); } $date = "1991-10-13 : 00:00:00"; $register = $db->register($date,$username,$password,$email); echo $register;
nella pagina di login(cioè la mia index)
PHP:$username = ""; $password = ""; $message = ""; $_SESSION['login_user'] = ""; var_dump($_POST); /*login mandatomi dal tizio*/ //if(!empty($_POST)) { if($_SERVER["REQUEST_METHOD"] == "POST"){ if(isset($_POST['username'])) { // check if the username has been set $username = $_POST['username']; echo main::sanitize($_POST['username'], 'string'); } if(isset($_POST['password'])) { $password = $_POST['password']; echo main::sanitize($_POST['password'], 'string'); //echo '<script> hide_login(); </script>'; } $login = $db->login($username,$password); echo $login; }
allora su register mi stampa user successfully registrated e fa la redirect ma nel db non fa nulla.
poi
su login invece stampa l'errore che lo username non è corretto.
terzo ho seguito la guida di debugging di php storm ma a me non va
ho scaricato la dll che serviva, poi io usando xampp il file php.ini ce l'ho sotto la directory C:/xampp/php l'ho inserito li e ho seguito il documento ma niente io non riesco a seguire i breakpoint che metto
public function register($date, $username, $password, $email){
//Nella prepare, meglio avere nomi diversi per le variabili da confrontare
$sql = $this->_pdo->prepare('SELECT * FROM users WHERE username = :username OR email= :email');
$sql->bindParam(':username', $username);
$sql->bindParam(':email', $username);
$sql->execute();
/*In alternativa puoi utilizzare un'array nella funzione execute
$sql = $this->_pdo->prepare('SELECT * FROM users WHERE username = ? or email= ?');
$sql->execute(array($username, $username));
*/
$res = $sql->fetchAll(PDO::FETCH_ASSOC);
if ($sql->rowCount() === 1) {
$res = "Username or email registred yet";
return $res;
}else {
//La password non può essere in plain text ma le devi criptare (anche perchè nella fase di login vefichi gli hash)
$pass = password_hash($password, PASSWORD_DEFAULT);
//Quando fai l'insert non puoi inserire le variabili direttamente nella prepare
$sql = $this->_pdo->prepare('Insert Into users (date_of_birth, username, password,email) VALUES (:date,:username,:password,:email)');
$sql->bindParam(':username', $username);
$sql->bindParam(':date_of_birth', $date);
$sql->bindParam(':password', $pass);
$sql->bindParam(':email', $email);
$sql->execute();
$res = $sql->fetchAll(PDO::FETCH_ASSOC);
$res = "Successfully Registrated";
return $res;
header("location: index.php");
}
}
main::sanitize($_POST['email'], 'email');
Se vuoi ti mando lo script di prova del mio db così puoi fare tutte le prove direttamente coi miei dati
create database if not exists guesswho;
use guesswho;
Create Table if not exists Users(
id_user Integer auto_increment not null,
first_name nvarchar(255) default null,
last_name nvarchar(255) default null,
date_of_birth datetime not null,
username nvarchar(255) not null,
password nvarchar(255) not null,
email nvarchar(255) not null,
trofei integer(255) default null,
gems integer(255) default null,
gold integer(255) default null,
position nvarchar(20) default null,
captcha nvarchar(10) default null,
primary key(id_user, email),
index indice_nome(username),
index posizioni(position),
index gemme(gems),
index gold(gold),
index trofei(trofei)
);
create table if not exists User_Access(
id_access Integer auto_increment not null,
id_user Integer(255) not null,
data_accesso datetime not null,
data_sconnessione datetime not null,
primary key(id_access),
foreign key(id_user) references Users(id_user) on delete cascade on update cascade
);
create table if not exists License(
id_licence Integer auto_increment not null,
id_user Integer(255) not null,
activated boolean default false not null,
activation_code nvarchar(255) not null,
primary key(id_licence),
foreign key(id_user) references Users(id_user) on delete cascade on update cascade
);
Create Table if not exists Trophy(
id_trophy integer auto_increment not null,
name_trophy nvarchar(255) not null,
primary key(id_trophy)
);
insert into Trophy (id_trophy, name_trophy) values(1, 'Give 50 gift cards');
insert into Trophy (id_trophy, name_trophy) values(2, 'Give 250 gift cards');
insert into Trophy (id_trophy, name_trophy) values(3, 'Give 2000 gift cards');
insert into Trophy (id_trophy, name_trophy) values(4, 'Give 5000 gift cards');
insert into Trophy (id_trophy, name_trophy) values(5, 'Give 10000 gift cards');
insert into Trophy (id_trophy, name_trophy) values(6, 'Give 25000 gift cards');
insert into Trophy (id_trophy, name_trophy) values(7, 'Collect 25 cards');
insert into Trophy (id_trophy, name_trophy) values(8, 'Collect 100 cards');
insert into Trophy (id_trophy, name_trophy) values(9, 'Collect 350 cards');
insert into Trophy (id_trophy, name_trophy) values(10, 'Collect 1000 cards');
insert into Trophy (id_trophy, name_trophy) values(11, 'Collect 2500 cards');
insert into Trophy (id_trophy, name_trophy) values(12, 'Collect 5000 cards');
insert into Trophy (id_trophy, name_trophy) values(13, 'Win 5 friendship battles');
insert into Trophy (id_trophy, name_trophy) values(14, 'Win 20 friendship battles');
insert into Trophy (id_trophy, name_trophy) values(15, 'Win 50 friendship battles');
insert into Trophy (id_trophy, name_trophy) values(16, 'Win 5 times in a stadium');
insert into Trophy (id_trophy, name_trophy) values(17, 'Win 8 times in a stadium');
insert into Trophy (id_trophy, name_trophy) values(18, 'Win 12 times in a stadium');
insert into Trophy (id_trophy, name_trophy) values(19, 'Go to platform 2');
insert into Trophy (id_trophy, name_trophy) values(20, 'Go to platform 4');
insert into Trophy (id_trophy, name_trophy) values(21, 'Go to platform 6');
insert into Trophy (id_trophy, name_trophy) values(22, 'Start a game');
Create Table if not exists Clan(
id_clan integer auto_increment not null,
clan_name nvarchar(255) not null,
stemma integer(2) default null,
descrizione nvarchar(255) default null,
min_trofei integer(255) default null,
position nvarchar(20) default null,
trofei_total integer(255) default null,
tipo nvarchar(50) default null,
maxUsers integer(50) default null,
minUsers integer(1) default null,
primary key(id_clan, clan_name),
index nome_clan(clan_name)
)
insert into Users(first_name, last_name, date_of_birth, username, password, email, trofei,gems,gold, position) values
('pippo', 'disney', 1980-10-13 :00:00:00, 'pippo1', '123456', 'pippo@mail.it', 1000, 100, 100, 'italy');
insert into Users(first_name, last_name, date_of_birth, username, password, email, trofei,gems,gold, position) values
('paperino', 'disney', 1980-10-13 :00:00:00, 'paperino1', '123456', 'pippo@mail.it', 2000,100, 1000 ,'italy');
insert into Users(first_name, last_name, date_of_birth, username, password, email, trofei,gems,gold, position) values
('pluto', 'disney', 1980-10-13 :00:00:00, 'pluto1', '123456', 'pippo@mail.it', 3000, 100, 3000, 'germany');
insert into Users(first_name, last_name, date_of_birth, username, password, email, trofei,gems,gold, position) values
('minnie', 'disney', 1980-10-13 :00:00:00, 'minnie1', '123456', 'pippo@mail.it', 100, 100, 0, 'france');
insert into Users(first_name, last_name, date_of_birth, username, password, email, trofei,gems,gold, position) values
('paperone', 'disney', 1980-10-13 :00:00:00, 'paperone1', '123456', 'pippo@mail.it', 269, 100, 100000, 'spain');
insert into Users(first_name, last_name, date_of_birth, username, password, email, trofei,gems,gold, position) values
('amelia', 'disney', 1980-10-13 :00:00:00, 'amelia1', '123456', 'pippo@mail.it', 45, 100, 1, 'italy');
insert into Clan(clan_name, stemma, min_trofei, descrizione, position, trofei_total, tipo, maxUsers,minUsers)
values
('disney', 12, 1500, 'clan disney con tutti i personaggi dei fumetti ', 'internazionale', 20000, 'Public', 20, 1)
ALTER TABLE Clan
ADD exp_clan integer(255) default null;
ALTER TABLE Clan
ADD level_clan integer(255) default null;
ALTER TABLE Users
ADD exp_user integer(255) default null;
ALTER TABLE Users
ADD level_user integer(255) default null;
create table Chat_general(
id integer auto_increment not null,
id_user integer(255) not null,
id_clan integer(255) not null,
message nvarchar(255) not null,
datamex datetime not null,
primary key(id),
FOREIGN KEY (id_user)
REFERENCES `guesswho`.`users` (id_user),
FOREIGN KEY (id_clan)
REFERENCES `guesswho`.`clan` (id_clan)
);
Create Table Clan_users(
ID integer auto_increment not null,
id_clan INTEGER(255) not null,
id_user INTEGER(255) not null,
ruolo NVARCHAR(255) not null,
Primary key(ID),
Foreign key (id_clan) REFERENCES `guesswho`.`clan` (id_clan),
Foreign key (id_user) REFERENCES `guesswho`.`users` (id_user)
);
insert into clan_users(id_clan, id_user, ruolo) values (1,1, "CAPO");
insert into clan_users(id_clan, id_user, ruolo) values (1,2, "CO_CAPO");
insert into clan_users(id_clan, id_user, ruolo) values (1,3, "ANZIANO");
insert into clan_users(id_clan, id_user, ruolo) values (1,4, "RECLUTA");
insert into clan_users(id_clan, id_user, ruolo) values (1,5, "RECLUTA");
insert into clan_users(id_clan, id_user, ruolo) values (1,6, "ANZIANO");
public function register($dates, $username, $password, $email){
//Nella prepare, meglio avere nomi diversi per le variabili da confrontare
$sql = $this->_pdo->prepare('SELECT * FROM users WHERE username = :username OR email= :email');
$sql->bindParam(':username', $username);
$sql->bindParam(':email', $username);
$sql->execute();
$res = $sql->fetchAll(PDO::FETCH_ASSOC);
if ($sql->rowCount() === 1) {
$res = "Username or email registred yet";
return $res;
}else {
//La password non può essere in plain text ma le devi criptare (anche perchè nella fase di login vefichi gli hash)
//$pass = password_hash($password, PASSWORD_DEFAULT);
//$pass = password_hash($password, PASSWORD_BCRYPT);
$pass = hash('sha256', $password);
$dates = $dates;
$username = $username;
$password = $pass;
$email = $email;
$trophy = 0;
$gems = 100;
$gold = 0;
//Quando fai l'insert non puoi inserire le variabili direttamente nella prepare
$stmt = $this->_pdo->prepare("INSERT INTO users (date_of_birth, username, password, email, trofei, gems, gold)
VALUES (:dates, :username, :password, :email, :trophy, :gems, :gold)");
$stmt->bindParam(':dates', $dates);
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':trophy', $trophy);
$stmt->bindParam(':gems', $gems);
$stmt->bindParam(':gold', $gold);
$stmt->execute();
$res = $sql->fetchAll(PDO::FETCH_ASSOC);
$res = "Successfully Registrated";
return $res;
header("location: index.php");
}
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST['username'])) {
// check if the username has been set
$username = $_POST['username'];
echo main::sanitize($_POST['username'], 'string');
}
if(isset($_POST['password'])) {
$password = $_POST['password'];
// echo main::sanitize($_POST['password'], 'string');
//echo '<script> hide_login(); </script>';
}
if(isset($_POST['email'])){
$email = $_POST['email'];
echo main::sanitize($_POST['email'], 'string');
}
if (isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
}
else
{
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
}
$dates = "1991-10-13 : 00:00:00";
$register = $db->register($dates,$username,$password,$email);
echo $register;
}
$pass = hash('sha256', $password);
echo main::sanitize($_POST['email'], 'string');
if (isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
}
else
{
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
}