Skip to content

Instantly share code, notes, and snippets.

@maxixo
Created January 23, 2026 21:50
Show Gist options
  • Select an option

  • Save maxixo/32de1ffedc7152012576dfbe2a70a538 to your computer and use it in GitHub Desktop.

Select an option

Save maxixo/32de1ffedc7152012576dfbe2a70a538 to your computer and use it in GitHub Desktop.
sign in with session
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login system</title>
</head>
<body>
<form action="login.php" method="POST">
<input type="emaiil" name="email" placeholder="email" required>
<input type="password" name="password" placeholder="password" required>
<button type="submit" name="">Login</button>
</form>
</body>
</html>
<?php
session_start();
$conn = new mysqli("localhost", "root", "", "user_system");
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE email = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result ->num_rows ===1) {
$user = $result->fetch_assoc();
if(password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
echo "Login successful!";
} else {
echo "Invalid credentials";
}
} else {
echo "User not found";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment