create login system php code example
Example 1: login PHP
<?php
session_start();
include("db_con.php");
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
$query = mysql_query("SELECT * FROM users WHERE username='".$_POST["username"]."' AND password ='".$_POST["password"]."'")
or DIE('query non riuscita'.mysql_error());
if(mysql_num_rows($query)>0){
$row = mysql_fetch_assoc($query);
$_SESSION["logged"] =true;
header("location:prova.php");
}else{
echo "non ti sei registrato con successo";
}
?>
Example 2: login php
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<form action="" method="POST">
<input type="password" name="password">
<button type="submit" name="submit">Login</button>
</form>
<?php
if(isset($_POST['submit'])){
if(password_verify($_POST['password'], '$2y$10$sejeRNYZGaoPh1EwfcuO1.hxl/uepQOh9SITWWgeej86vnMt26KIa')){
$_SESSION['login'] = true;
header("Location: http://localhost");
}
}
?>
</body>
</html>