PHP Session et Cookies: Créer un Système de connexion à l’aide des Cookies

Author:
 
<?php
session_start ();
$GLOBALS ['user'] = "test";
$GLOBALS ['pass'] = "test";
 
function login($username, $password) {
  if (strcmp ( $username, $GLOBALS ['user'] ) == 0 && strcmp ( $password, $GLOBALS ['pass'] ) == 0) {
    $_SESSION ['user'] = $username;
    $_SESSION ['pass'] = md5 ( $password );
    return true;
  
  } else {
    return false;
  }
}
function logout() {
  unset ( $_SESSION ['user'] );
  unset ( $_SESSION ['pass'] );
  session_destroy ();
 
}
if (login ( "test", "test" )) {
  echo "Successfully logged in with user: " . $_SESSION ['user'] . " and pass: " . $_SESSION ['pass'];
} else {
  echo "Could not login.";
}
logout ();
if (isset ( $_SESSION ['user'] )) {
  echo $_SESSION ['user']; //Outputs nothing. 
}
?>
  
  

Leave a Reply

Your email address will not be published. Required fields are marked *


3 + = eight