-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
51 lines (42 loc) · 1.7 KB
/
Copy pathadmin.php
File metadata and controls
51 lines (42 loc) · 1.7 KB
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
<?php
$host = "sql206.infinityfree.com";
$user = "if0_41907840";
$pass = "1PwMWAiitxQv8y"; // Your FTP/Account password
$db = "if0_41907840_fasion";
$conn = mysqli_connect($host, $user, $pass, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// 2. PHP LOGIC FOR LOGIN & SIGNUP
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action'])) {
$action = $_POST['action'];
// --- SIGN UP LOGIC ---
if ($action == "signin") {
$u = $_POST['reg_user'];
$e = $_POST['reg_email'];
$p = $_POST['reg_psw'];
$sql = "INSERT INTO users (username, email, password) VALUES ('$u', '$e', '$p')";
if ($conn->query($sql)) {
echo "<script>alert('Welcome $u!'); window.location.href='home.php';</script>";
} else {
echo "<script>alert('Error: Username might already exist');</script>";
}
}
// --- LOGIN LOGIC ---
if ($action == "login") {
$login_input = trim($_POST['login_user'] ?? '');
$p = $_POST['login_psw'] ?? '';
$login_input = mysqli_real_escape_string($conn, $login_input);
$p = mysqli_real_escape_string($conn, $p);
$sql = "SELECT * FROM users WHERE (username='$login_input' OR email='$login_input') AND password='$p'";
$result = $conn->query($sql);
if ($result && $result->num_rows > 0) {
$user = $result->fetch_assoc();
$_SESSION['user'] = $user['username'];
echo "<script>alert('Welcome " . addslashes($user['username']) . "!'); window.location.href='home.php';</script>";
} else {
echo "<script>alert('Invalid Username or Password');</script>";
}
}
}
?>