-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
58 lines (49 loc) · 2.03 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
49
50
51
52
53
54
55
56
57
58
<?php
session_start();
include('connection.php');
try {
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$mobile = $_POST["mobile"];
$userPassword = $_POST["password"];
$pass_encode = md5($userPassword);
$obj = $conn->prepare("SELECT * FROM RakiFlipkart WHERE MOBILE_NUM = :mobile AND PASS_WORD = :password");
$obj->bindParam(':mobile', $mobile);
$obj->bindParam(':password', $pass_encode);
$obj->execute();
$result = $obj->fetch(PDO::FETCH_ASSOC);
if ($result) {
if (isset($result['ID']) && isset($result['USER_NAME'])) {
$_SESSION['user_id'] = $result['ID'];
$_SESSION['username'] = $result['USER_NAME'];
$stmtUserDetails = $conn->prepare("SELECT * FROM RakiCart WHERE USER_ID = :userId");
$stmtUserDetails->bindParam(':userId', $_SESSION['user_id'], PDO::PARAM_INT);
$stmtUserDetails->execute();
$userDetails = $stmtUserDetails->fetchAll(PDO::FETCH_ASSOC);
if ($userDetails) {
$usemodel = array();
foreach ($userDetails as $user) {
$usemodel[] = $user["MODEL_NAME"];
}
$_SESSION['usemodel'] = $usemodel;
$_SESSION['addid'] = $userDetails[0]['ID'];
echo json_encode(["status" => "success", "userDetails" => $userDetails]);
} else {
echo json_encode(["status" => "success", "userDetails" => []]);
}
} else {
echo json_encode(["status" => "failure"]);
}
} else {
echo json_encode(["status" => "user_not_found"]);
}
} else {
http_response_code(400);
echo "Invalid request method";
}
} catch (PDOException $e) {
error_log('Error during login ' . $e->getMessage());
echo json_encode(["status" => "error", "message" => "Internal Server Error"]);
} finally {
$conn = null;
}
?>