Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php]logowanie + admin
Forum PHP.pl > Forum > Przedszkole
jjarkus
potrzebuje pomocy ze skryptem logowania.
oto moje pliki:
plik users.dat
  1. <?php
  2.  
  3. DATA
  4. Admin,0033455f990e921b286b9e56698b0fb0,admin
  5. test1,5a105e8b9d40e1329780d62ea2265d8a,user
  6. abc,900150983cd24fb0d6963f7d28e17f72,user
  7. def,4ed9407630eb1000c0f6b63842defa7d
  8. jarek,c63a5cfce0a1819ebbe4a19e074356b6
  9. zzz,f3abb86bd34cf4d52698f14c0da1dc60
  10. ccc,9df62e693988eb4e1e1444ece0578579
  11.  
  12. ?>

index.php
  1. <?
  2. include "session.php";
  3. ?>
  4. <html>
  5. <head>
  6. <title>Farmazon Site</title>
  7. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
  8. <link href="style.css" type="text/css" rel="stylesheet">
  9. </style>
  10. </head>
  11. <body topmargin="40">
  12. <p>&nbsp;</p>
  13. <!-- lewa strona -->
  14. <tr>
  15. <?
  16. include "left.php";
  17. ?>
  18. </body>
  19. </html>

left.php
  1. <center><table width="706" border="0" cellpadding="0" cellspacing="0" height="175">
  2. <tr>
  3. <td height="1" colspan="6" valign="top" width="713"><img src="images/flh.gif" width="713" height="159"></td>
  4. </tr>
  5. <tr>
  6. <td height="17" colspan="6" valign="top" width="713"><img src="images/flh_05.gif" width="713" height="17"></td>
  7. </tr>
  8. </table>
  9. <table width="706" border="0" cellpadding="0" cellspacing="0" height="175">
  10. <tr>
  11. <td width="15" height="144" valign="top" background="images/flh_09.gif"></td>
  12. <td width="167" valign="top" background="images/cgb.gif" bgcolor="363636">
  13. <p align="left" style="margin-top: 0; margin-bottom: 0">  
  14. <p align="left" style="margin-top: 0; margin-bottom: 0">
  15. <?
  16. if(!auth())
  17. {
  18. include "login.frm";
  19. print "<br><br>&raquo; <a href="index.php?page=registration&".SESID."">Nowe konto</a>n";
  20. }
  21. else
  22. {
  23. print "&raquo; <a href="index.php?page=logout&".SESID."">Wyloguj " . $_SESSION["USER_LOGIN"] . "</a>";
  24. print "<br>&raquo; Jestes " .$_SESSION["USER_LEVEL"] ." em</a>";
  25. print_r($_SESSION);";
  26. }
  27. ?>
  28. <p align="left" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
  29. <p align="left" style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#697C9C">
  30. &raquo;<b>&nbsp;Menu:</b></font><br>
  31. &nbsp;</p>
  32. <p align="left" style="margin-top: 0; margin-bottom: 0">
  33. - <a href="index.php?page=download">Download</a><br>
  34. <img src="images/flh_42.gif" width="140" height="3"><br>
  35. - <a href="index.php?page=tut">Tutoriale</a><br>
  36. <img src="images/flh_42.gif" width="140" height="3"><br>
  37. - <a href="index.php?page=skrypty">Skrypty</a><br>
  38. <img src="images/flh_42.gif" width="140" height="3"><br>
  39. - <a href="index.php?page=linki">Linki</a><br>
  40. <img src="images/flh_42.gif" width="140" height="3"><br>
  41. - <a href="index.php?page=arty">Atykuly</a><br>
  42. <img src="images/flh_42.gif" width="140" height="3"><br>
  43. - <a href="#">Cos</a></p>
  44. <p align="left" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
  45. </td>
  46. <td width="4" valign="top" background="images/flh_11.gif" height="144">&nbsp;</td>
  47. <td width="1" valign="top" background="images/flh_18.gif" height="144"><img src="images/flh_18.gif" width="2" height="130"></td>
  48. <td width="512" valign="top" background="images/cgb.gif" bgcolor="363636" height="144">
  49. <p align="left" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
  50. <p align="left" style="margin-top: 0; margin-bottom: 0"> <?
  51. if($page=="") $page="link1";
  52. if(!file_exists($page.".php"))
  53. {
  54.  include "default.php";
  55. }
  56. else
  57. {
  58. include_once $page.".php";
  59. }
  60.  
  61. ?></td>
  62. <td width="17" valign="top" background="images/flh_14.gif" height="144"></td>
  63. </tr>
  64. <tr>
  65. <td height="15" colspan="6" valign="top" width="715"><IMG SRC="images/flh_51.gif" WIDTH=713 HEIGHT=15 ALT=""></td>
  66. </tr>
  67. </table>
  68. </center>
  69. </body>
  70. </html>

to mi sie pojawia
  1. <?php
  2. Array ( [USER_AUTH] => 1 [USER_LOGIN] => def [USER_LEVEL] => )
  3.  
  4. ?>

z funkcji
php:
  1. <?php
  2. print_r($_SESSION);
  3. ?>

to jest plik odpowiedzialny za logowanie func.php
  1. <?
  2. #definicje stalych
  3. define("DATA", "users.dat");
  4. define("SESID", SESSION_NAME() . "=" . SESSION_ID());
  5.  
  6. # zaloguj user-a
  7. function login($login, $passwd)
  8. {
  9. $line = file(DATA);
  10. foreach($line as $temp)
  11. {
  12. $str = explode(",", $temp);
  13. if(chop($str[0])==$login && chop($str[1])==$passwd)
  14. {
  15. $_SESSION["USER_AUTH"] = True;
  16. $_SESSION["USER_LOGIN"] = $_POST["login"];
  17. return True;
  18. }
  19. }
  20. $login = htmlentities($login);
  21. return False;
  22. }
  23.  
  24. # wyloguj user-a
  25. function logout()
  26. {
  27. $_SESSION["USER_AUTH"] = False;
  28. $_SESSION["USER_LOGIN"] = Null;
  29. }
  30.  
  31. # czy użytkownik istnieje
  32. function user_exists($login)
  33. {
  34. $line = file(DATA);
  35. foreach($line as $temp)
  36. {
  37. $str = explode(",", $temp);
  38. if(chop($str[0])==$login) return True;
  39. }
  40. return False;
  41. }
  42.  
  43. # dodaje nowego użytkownika
  44. function add_user($login, $passwd)
  45. {
  46. $files = fopen(DATA, "a");
  47. flock($files, 2);
  48. fputs($files, $login . "," . $passwd . "n");
  49. flock($files, 3);
  50. fclose($files);
  51. }
  52.  
  53. # sprawdza czy zalogowany
  54. function auth()
  55. {
  56. return ($_SESSION["USER_AUTH"] == True);
  57. }
  58.  
  59. ?>


i ostatni session.php
  1. <?
  2. # start sesji
  3.  
  4. # biblioteka z funkcjiami
  5. include "func.php";
  6.  
  7. # logowanie, wylogowanie itp
  8. switch ($page)
  9. {
  10. case "login" :
  11. $login = htmlentities(substr($_POST["login"], 0, 255));
  12. $passwd = htmlentities(substr($_POST["passwd"], 0, 255));
  13. login($login, md5($passwd));
  14. break;
  15.  
  16. case "logout" : logout();
  17. break;
  18. }
  19. ?>

i mam problem nie wyswietla mi USER_LEVEL
powinno mi odczytac czy jestem admin czy user z fuckcji:
  1. <?php
  2.  
  3. print "<br>&raquo; Jestes " . $_SESSION["USER_LEVEL"] . "em</a>";
  4.  
  5. ?>

jednak nie wyswietal, ze jest adminem lub userem
w czym moze byc problem? sesje?
kamikaze_
Właściwie to gdzie ustawiasz $_SESSION["USER_LEVEL"] ? Jakoś tego nie widze.
dr_bonzo
W Przedszkolu nalezy uzywac [tagow ] w tytule topiku, tym razem poprawiam
Gość
Yes. Very good site! worth to visit!"
Gość
Nice job! Visit my sites too:
http://xoomer.alice.it/dropshipper/extagen/index.html
Gość
hello, your site is best
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.