-
Notifications
You must be signed in to change notification settings - Fork 1
/
Login.php
48 lines (39 loc) · 1.46 KB
/
Login.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
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once('config.php');
if (!empty($_POST)) {
$errors = array();
$email = trim($_POST["email1"]);
$password = trim($_POST["pwd1"]);
//Perform some validation
if ($email == "") {
$errors[] = "enter email";
}
if ($password == "") {
$errors[] = "enter password";
}
if (count($errors) == 0) {
//retrieve the records of the user who is trying to login
$userdetails = fetchUserDetails($email);
if ($password != $userdetails["password"]) {
echo "<script type='text/javascript'>alert('Oops!!Incorrect Password');</script>";
header("Location: index.php");
}
else {
//Passwords match! we're good to go'
//Transfer some db data to the session object
$loggedInUser = new loggedInUser();
$loggedInUser->id = $userdetails["id"];
$loggedInUser->name = $userdetails["name"];
$loggedInUser->email = $userdetails["email"];
$loggedInUser->phone = $userdetails["phone"];
$loggedInUser->pwd = $userdetails["password"];
$_SESSION["ThisUser"] = $loggedInUser;
$usershoppingcart = new usershoppingcart();
$_SESSION["shoppingcart"] = $usershoppingcart->items;
//now that a session for this user is created
//Redirect to this users account page
header("Location: myAccount.php");
die();
}
}
}