forked from davprs/BigliettOne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthen_signup.php
37 lines (32 loc) · 1.39 KB
/
authen_signup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require('db/db_connect.php');
if(isset($_POST['username']) and isset($_POST['password'])){
//assignign post values to variables
$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['nome'];
$surname = $_POST['cognome'];
$birthday = $_POST['nascita'];
$cookie_name = "user";
$cookie_value = $username;
if($dbh->isThereUsername($username)){
$result = $dbh->checkLogin($username, $password);
$count = mysqli_num_rows($result);
if($count >= 1){
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
setcookie('alert', 'Ben Tornato '.$username.'!', time() + 5);
header("Location: ./account.php");
}else{
setcookie('alert', 'username già in uso !', time() + 5);
header("Location: ./signup.php");
}
} else{
$result = $dbh->createCart();
echo $result;
$result = $dbh->signUp($username, $password, $name, $surname, $birthday, $result);
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
setcookie('alert', 'Benvenuto a bordo '.$username.'!', time() + 5);
header("Location: ./account.php");
}
}
?>