Projecte M07, botiga en php.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.5 KiB

<?php
include_once('parameters.php');
$username = $_POST['username'];
$userpass = $_POST['userpass'];
//========================================================================================================================================================
// Guardem les dades de lusuari a la bdd
if (loginCheck($username, $userpass, $con)) {
session_start();
$userData = userDetails($username, $con);
$_SESSION['userid']=$userData['bp_user_id'];
$_SESSION['username']=$userData['bp_user_name'];
$_SESSION['useradddate']=$userData['bp_user_addDate'];
header("Location: ./my-products.php");
} else {
header("Location: ./login-page.php?succes=0");
}
function loginCheck($username, $userpass, $con) {
$sql = $con->prepare("SELECT bp_user_pass FROM bp_users WHERE bp_user_name = ?");
$sql->bind_param("s", $username);
$sql->execute();
$sql->bind_result($encryptedUserpass);
$sql->fetch();
return password_verify($userpass, $encryptedUserpass);
}
function userDetails($username, $con) {
$sql = $con->prepare("SELECT bp_user_id, bp_user_name, bp_user_addDate FROM bp_users WHERE bp_user_name = ?");
$sql->bind_param("s", $username);
$sql->execute();
$sql->bind_result($bp_user_id, $bp_user_name, $bp_user_addDate);
$sql->fetch();
return (array("bp_user_id"=>$bp_user_id, "bp_user_name"=>$bp_user_name, "bp_user_addDate"=>$bp_user_addDate));
}
?>