Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]logowanie jako admin
gregov0
post 11.02.2011, 23:37:51
Post #1





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 14.01.2011
Skąd: Kalisz

Ostrzeżenie: (0%)
-----


mam taki kod
  1. <?php
  2. session_start(); // rozpoczęcie sesji
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  6. <head>
  7.  
  8. <meta name="Description" content="Witryna e-learningowa" />
  9. <meta name="Keywords" content="," />
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8; "/>
  11. <meta http-equiv="content-language" content="pl">
  12. <meta name="Distribution" content="Global" />
  13. <meta name="Author" content="grzegorzw" />
  14. <meta name="Robots" content="index,follow" />
  15. <script type="text/javascript" language="JavaScript" src="overlib.js"></script>
  16. <link rel="stylesheet" href="images/style.css" type="text/css" />
  17.  
  18. <title>logowanie</title>
  19. <!--<script language="javascript" type="text/javascript">
  20. function popup()
  21. {
  22. popupwindow=window.open('szkolenie/kurs.htm', 'Mójkurs','height=600,width=800,menubar=no,scrollbars=no,resizable=no,status=no,location=no');
  23. popupwindow.moveTo(0,0);
  24. }
  25. </script>-->
  26. </head>
  27.  
  28. <body>
  29. <?php include('header.php'); ?>
  30. <div id="glokno">
  31.  
  32. <a name="stronainfo"></a>
  33. <h1>Zaloguj się</h1>
  34. <div class="content">
  35.  
  36. <?php
  37.  
  38.  
  39. if (!isset($_SESSION['login'])) { // dostęp dla niezalogowanego użytkownika
  40.  
  41. if ($_POST['wyslane']) {
  42.  
  43. include 'db.php';
  44. $tabela = 'uzytkownik';
  45.  
  46. $login = $_POST["login"];
  47. $haslo = $_POST["haslo"];
  48.  
  49. $haslo = md5($haslo);
  50.  
  51. // użytkownik się loguje
  52. $wynik=mysql_query("SELECT * FROM $tabela WHERE login='$login' and haslo='$haslo'");
  53.  
  54. if (mysql_num_rows($wynik) == 1) {
  55.  
  56. $informacja = mysql_fetch_array($wynik);
  57. $_SESSION["login"] = $informacja["login"];
  58. header('Location: index.php ');
  59. } else {
  60. echo '<p>Zostały wprowadzone nieprawidłowe dane</p>';
  61. }
  62. mysql_close($polaczenie);
  63. }
  64.  
  65. // tworzenie formularza HTML
  66. echo <<< KONIEC
  67.  
  68.   <form class="form" action="logowanie.php" method="post">
  69.   <input type="hidden" name="wyslane" value="TRUE" />
  70.  
  71.   <p>
  72. <div class="label"><label for="login">Login</label></div>
  73. <input type="text" name="login" id="login" />
  74. </p>
  75.  
  76. <p>
  77. <div class="label"><label for="haslo">Hasło</label></div>
  78. <input type="password" name="haslo" id="haslo" />
  79. </p>
  80.  
  81.   <p class="submit2">
  82.   <input type="submit" value="Zaloguj mnie" />
  83.   </p>
  84.  
  85. <p class="przypomnij">
  86. <a href="przypomnienie.php">Nie pamiętasz hasła?</a>
  87. </p>
  88.  
  89.   </form>
  90. KONIEC;
  91.  
  92. } else {
  93. header('Location: index.php');
  94. }
  95.  
  96. if ($_GET["wylogowanie"] == "tak") {
  97. // niszczenie sesji
  98. header('Location: index.php');
  99. }
  100.  
  101. ?>
  102.  
  103. </div>
  104. </div>
  105. <?php include("footer.php");?>

Chciałbym żeby po wpisaniu jako loginu np słowa admin otwierała sie inna stronka niż dla pozostałych użytkowników. Ma ktoś jakiś pomysł?
Go to the top of the page
+Quote Post
emajl22
post 11.02.2011, 23:42:32
Post #2





Grupa: Zarejestrowani
Postów: 273
Pomógł: 21
Dołączył: 28.11.2010

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


musisz pobrać grupę użytkownika (bo zakładam, że masz takie pole w bazie), albo login == admin czy coś i zamiast:
  1. if (mysql_num_rows($wynik) == 1) {
  2.  
  3. $informacja = mysql_fetch_array($wynik);
  4. $_SESSION["login"] = $informacja["login"];
  5. header('Location: index.php ');
  6. }

dajesz:
  1. if (mysql_num_rows($wynik) == 1) {
  2.  
  3. $informacja = mysql_fetch_array($wynik);
  4. $_SESSION["login"] = $informacja["login"];
  5. if ($informacja['login']=="admin")
  6. header('dla admina')
  7. else
  8. header('Location: index.php ');
  9. }


--------------------
Go to the top of the page
+Quote Post
AdIoS_Neo
post 12.02.2011, 00:08:57
Post #3





Grupa: Zarejestrowani
Postów: 159
Pomógł: 43
Dołączył: 8.03.2009

Ostrzeżenie: (0%)
-----


  1. header('Location: index.php')
brakuje
Kod
;
wink.gif
Go to the top of the page
+Quote Post
gregov0
post 12.02.2011, 00:26:40
Post #4





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 14.01.2011
Skąd: Kalisz

Ostrzeżenie: (0%)
-----


wielkie dzieki działa banalne to bylo:)
Go to the top of the page
+Quote Post

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: 26.04.2025 - 01:29