Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php // login.php :: Fonctions pour se loger et quitter.
  2. header('P3P: CP="NON ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
  3.  
  4. define('PS', PATH_SEPARATOR);
  5. define('DS', DIRECTORY_SEPARATOR);
  6. define('ROOT_PATH', dirname(__FILE__) . DS);
  7.  
  8.  
  9. switch($_GET['do']){
  10.     case 'login':
  11.         include('lib.php');
  12.         $dbsettings = getConfig(); 
  13.         $tableprefix = $dbsettings['prefix'];
  14.         $pdo = openpdo();
  15.         $link = opendb(); //COMPATIBILITÉ VIA EXT/MYSQL
  16.    
  17.         if (isset($_POST["submit_x"])) {
  18.             $LOGIN = $pdo->prepare('SELECT * FROM '.$tableprefix.'_users WHERE username= :username AND password = :password LIMIT 1');
  19.             $LOGIN->execute(array('username' => $pdo->quote($_POST['username'], PDO::PARAM_STR), 'password' => $pdo->quote(md5($_POST['password']), PDO::PARAM_STR)));
  20.             $LOGIN->setFetchMode(PDO::FETCH_COLUMN);
  21.        
  22.             $login_results = $LOGIN->rowCount();
  23.            
  24.             if($login_results != 1){
  25.                 die("ID ou PW invalide, veuillez vous reloger avec vos bon identifiants.");
  26.             }
  27.            
  28.             $row = $LOGIN->fetch();
  29.            
  30.             if (isset($_POST['rememberme'])) {
  31.                 $expiretime = time()+31536000;
  32.                 $rememberme = 1;
  33.             } else {
  34.                 $expiretime = 0;
  35.                 $rememberme = 0;
  36.             }
  37.             $cookie = $row['id'] . ' ' . $row['username'] . ' ' . md5($row['password'] . '--' . $dbsettings['secretword']) . ' ' . $rememberme;
  38.             setcookie('dkgame', $cookie, $expiretime, '/', '', 0);
  39.             header('Location: index.php');
  40.             die();
  41.        
  42.         }
  43.        
  44.         $page = gettemplate('login');
  45.         $title = 'Bienvenue sur RPG illusion';
  46.         display($page, $title, false, true, false);
  47.        
  48.     break;
  49.     case 'logout':
  50.         setcookie("dkgame", "", time()-100000, "/", "", 0);
  51.         header("Location: login.php?do=login");
  52.         exit;
  53.     break;
  54.    
  55.     default:
  56.         header('Location: login?do=login');
  57.         exit;
  58.     break; 
  59.    
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement