Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Przeróbka logowania na cookies
hzl_91
post 2.01.2007, 14:53:14
Post #1





Grupa: Zarejestrowani
Postów: 70
Pomógł: 0
Dołączył: 28.03.2006
Skąd: Częstochowa

Ostrzeżenie: (10%)
X----


Witam. Napisałem sobie logowanie najpierw na sesjach, a potem chciałem to przerobic na cookies. I tu mam problem umiem dodać ciasteczka. Ale jak mam je wczytać w logowanie i jak ustawić je, żeby były wieczne?


Narazie zrobiłem coś takiego:

Plik logujący:
  1. <?php
  2.  
  3. switch($load) {
  4. default :
  5. #### LOGOWANIE ####
  6. //Formularz logowania
  7. echo'<form method="POST" action="index.php?mode=login&load=log_me">
  8. <p><input type="text" name="user" size="20" value="login"></p>
  9. <p><input type="password" name="pass" size="20" value="pass"><input type="submit" value="Zaloguj sie" name="B1"></p>
  10. <a href="logowanie.php?co=dodaj">Rejestracja</a>
  11. </form>';
  12. break;
  13.  
  14. case 'log_me':
  15. //dodaj sesje
  16. $_SESSION['user']=$_POST[user];
  17. $_SESSION['pass']=md5($_POST[pass]);
  18. setcookie('user', $_POST['user'], time() + 60 * 60 * 24 * 30);
  19. setcookie('pass', $_POST['pass'], time() + 60 * 60 * 24 * 30);
  20.  
  21. //Loguje do systemu
  22. if(login_ok()) {
  23. $stat = user_info();
  24. header("Location: massange.php?value=true1&top=$lang[39]&text=$lang[40]&url=index.php");
  25. } else {
  26. header("Location: massange.php?value=false&top=$lang[41]&text=$lang[42]&url=index.php?mode=login");
  27. }
  28. break;
  29. }
  30.  
  31. ?>


Plik sprawdzający czy zalogowany:
  1. <?php
  2.  
  3. function login_ok() {
  4. global $inf, $stat;
  5.  
  6. $user = $_SESSION['user'];
  7. $pass = $_SESSION['pass'];
  8.  
  9. $zapytanie = mysql_query("SELECT * FROM ".$db_prefix."users WHERE users_login ='$user' AND users_password ='$pass' AND users_status ='1';");
  10. $yes = mysql_num_rows($zapytanie);if($yes==0) { $ret=FALSE; } else { $ret=TRUE; }return $ret;
  11. }
  12.  
  13. function user_info() {
  14. $user = $_SESSION['user'];
  15. $pass = $_SESSION['pass'];
  16.  
  17. $query = mysql_query("SELECT * FROM ".$db_prefix."users WHERE users_login ='$user' AND users_password ='$pass';");
  18. $r = mysql_fetch_array($query);
  19.  
  20. $inf[1] = $r['users_id'];
  21. $inf[2] = $r['users_login'];
  22. $inf[3] = $r['users_password'];
  23. $inf[4] = $r['users_email'];
  24. return $inf;
  25. }
  26.  
  27. ?>


Ten post edytował hzl_91 2.01.2007, 15:03:36


--------------------
Projektowanie stron internetowych | Need For Speed NFS
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 04:57