Which one is the better way to handle login in PHP?
#1 PHP.net
$email = $_POST['email'];
$password = $_POST['password'];
if($user->connection($email,$password)){ // user logging validation
session_start(); //start the session
$_SESSION['user_logged'] = true; // user logged in
header('location : control_panel.php'); // go to control panel
}
else { // go back to logging page
header('location : logging.php?' . $user->error_string);
}
#2 Me after Paul Dixon's improvements and Sebasgo's improvements
if (isset($_REQUEST['email'])) {
$result = pg_prepare($dbconn, "query22", "SELECT passhash_md5 FROM users
WHERE email=$1;");
$passhash_md5 = pg_execute($dbconn, "query22", array($_REQUEST['email']));
session_start();
$_SESSION['logged_in'] = false;
if ($passhash_md5 == $_REQUEST['passhash_md5']) {
$_SESSION['logged_in'] = true;
}
header('Location: index.php');
Kodu # 2 Ben hala işe almak için çalışıyorum, çünkü $_REQUEST
komutları bulunur.