Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Logowanie na sesjach
Ardziej
post 8.07.2009, 22:15:22
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 1
Dołączył: 5.05.2009

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


index.php

  1. <?php session_start(); ?>
  2. <html>
  3. <head>
  4. <title>Proste Logowanie</title>
  5. <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  6. </head>
  7. <body>
  8. <?php
  9. if(isSet($_SESSION['user']))
  10. {
  11.  echo "<b>Witaj: </b>".$_SESSION['user'];
  12.  echo "<a href=\"logout.php\">Wyloguj się</a>";
  13. }
  14. else{
  15. ?>
  16. <form method='POST' action='sprawdz.php'>
  17. <table>
  18. <tr><th align="right">Login:</th><td align="left"><input type='text' name='login'></td></tr>
  19. <tr><th align="right">Hasło:</th><td align="left"><input type='password' name='haslo'></td></tr>
  20. <tr><td align="center" colspan="2"><input type='submit' value='Wyślij' name='logowanie'></td></tr>
  21. </table>
  22. </form>
  23. <?php
  24. }
  25. ?>
  26. </body>
  27. </html>


sprawdz.php

  1. <?php session_start(); include("config.php"); ?>
  2. <html>
  3. <head>
  4. <title>Proste Logowanie</title>
  5. <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  6. </head>
  7. <body>
  8. <?php
  9. if($_POST['logowanie']){
  10.  $wys_login = htmlspecialchars($_POST['login']);
  11.  $wys_pass = htmlspecialchars($_POST['haslo']);
  12.  if($wys_login == $login && $wys_pass == $pass){
  13.    $_SESSION['user'] = $login;
  14.    header("Location:index.php");
  15.  }
  16.  else{
  17.    header("Location:index.php");
  18.  }
  19. }
  20. else{
  21.  header("Location:index.php");
  22. }
  23. ?>
  24. </body>
  25. </html>


logout.php
  1. <?php session_start(); ?>
  2. <html>
  3. <head>
  4. <title>Proste Logowanie</title>
  5. <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  6. </head>
  7. <body>
  8. <?php
  9. if(isSet($_SESSION['user']))
  10. {
  11.  echo "Wylogowano Poprawnie<br>";
  12.  echo "<a href=\"index.php\">Strona Główna</a>";
  13. }
  14. else{
  15.  header("Location:index.php");
  16. }
  17. ?>
  18. </body>
  19. </html>


  1. <?php
  2. $login = "login";
  3. $pass = "pass";
  4. ?>


Coś nie trybi, sciana.gif może ktoś coś pomoże biggrin.gif
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 - 05:20