Basically init iguess?
This commit is contained in:
parent
3188f21ee2
commit
f6233a0cbf
9
.gitignore
vendored
9
.gitignore
vendored
@ -18,3 +18,12 @@
|
|||||||
*.sass.map
|
*.sass.map
|
||||||
*.scss.map
|
*.scss.map
|
||||||
|
|
||||||
|
secrets
|
||||||
|
secrets/
|
||||||
|
secrets/mysql.php
|
||||||
|
/secrets
|
||||||
|
/secrets/
|
||||||
|
/secrets/mysql.php
|
||||||
|
|
||||||
|
LICENSE.md
|
||||||
|
LICENSE
|
||||||
|
3
config.php
Normal file
3
config.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'secrets/mysql.php';
|
||||||
|
?>
|
24
login.php
Normal file
24
login.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'config.php';
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
// Handle login form submission
|
||||||
|
$username = $_POST['username'];
|
||||||
|
$password = $_POST['password'];
|
||||||
|
|
||||||
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
|
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$hashed_password'";
|
||||||
|
$result = mysqli_query($mysqli, $query);
|
||||||
|
|
||||||
|
if (mysqli_num_rows($result) == 1) {
|
||||||
|
$user = mysqli_fetch_assoc($result);
|
||||||
|
$_SESSION['user_id'] = $user['id'];
|
||||||
|
header('Location: main.php');
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
echo "Invalid username or password.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_destroy();
|
||||||
|
header('Location: login.html');
|
||||||
|
exit();
|
||||||
|
?>
|
18
main.php
Normal file
18
main.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'config.php';
|
||||||
|
|
||||||
|
// Check if user is logged in
|
||||||
|
if (!isset($_SESSION['user_id'])) {
|
||||||
|
include 'pages/login.html';
|
||||||
|
} else {
|
||||||
|
// Fetch user details
|
||||||
|
$user_id = $_SESSION['user_id'];
|
||||||
|
$query = "SELECT * FROM users WHERE id = $user_id";
|
||||||
|
$result = mysqli_query($mysqli, $query);
|
||||||
|
$user = mysqli_fetch_assoc($result);
|
||||||
|
|
||||||
|
// Include the index page with user information
|
||||||
|
include 'pages/index.html';
|
||||||
|
}
|
||||||
|
?>
|
0
pages/index.html
Normal file
0
pages/index.html
Normal file
0
pages/login.html
Normal file
0
pages/login.html
Normal file
0
pages/register.html
Normal file
0
pages/register.html
Normal file
24
register.php
Normal file
24
register.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'config.php';
|
||||||
|
|
||||||
|
// Handle registration form submission
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$username = $_POST['username'];
|
||||||
|
$email = $_POST['email'];
|
||||||
|
$password = $_POST['password'];
|
||||||
|
|
||||||
|
// Hash the password
|
||||||
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
|
// Insert user into the database
|
||||||
|
$query = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$hashed_password')";
|
||||||
|
$result = mysqli_query($mysqli, $query);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
echo "Registration successful. <a href='login.html'>Login here</a>.";
|
||||||
|
} else {
|
||||||
|
echo "Error: " . mysqli_error($mysqli);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
0
styles/index.css
Normal file
0
styles/index.css
Normal file
0
styles/login.css
Normal file
0
styles/login.css
Normal file
0
styles/register.css
Normal file
0
styles/register.css
Normal file
21
styles/style.css
Normal file
21
styles/style.css
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* Common styles for all pages */
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
max-width: 300px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
display: block;
|
||||||
|
margin-top: 10px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user