Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php]Logowanie Sesje
Mlodycompany
post
Post #1





Grupa: Zarejestrowani
Postów: 910
Pomógł: 44
Dołączył: 20.02.2008
Skąd: Łódź

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


Elo. Napisałem JUŻ własny skrypcik logowania ale kurcze nie dziala tak jak powinien. Daje kod:
  1. <?php
  2. $login = $_POST['login'];
  3. $haslo = $_POST['haslo'];
  4. $md5 = md5($haslo);
  5. $baza = mysql_query("SELECT * FROM users WHERE `login` = '".$login."' AND `haslo` = '".$md5."'");
  6. if($baza){
  7.  
  8.  
  9. $dane=mysql_fetch_array($baza);
  10. if($login == $dane[2] && $md5 == $dane[3]){
  11. $_SESSION['zalogowany'] = true;
  12. $_SESSION['login'] = $dane[2];
  13. $slogin = $_SESSION['login'];
  14. header("Location: index.php");
  15.  
  16. Bo po dluzszym mysleniu doszedlem do faktu ze musza byc wyslane jakies cookie do przegladarki i w niej powinny byc dane z sesji, ale nie wiem czy dobrze mysle i czy wogole sie cos takiego da :D
  17.  
  18.  
  19.  
  20. }
  21. }
  22.  
  23. if($_GET['action'] == "logout"){
  24.  
  25. }
  26. ?>

Na tej stronie co odbylo sie logowanie nazwa uzytkownika ($slogin) wyswietla sie normalnie ale gdy jest przekierowanie na index juz to nie dziala. W czym jest bład?(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ?

Ten post edytował Cienki1980 3.04.2008, 19:11:38
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Mlodycompany
post
Post #2





Grupa: Zarejestrowani
Postów: 910
Pomógł: 44
Dołączył: 20.02.2008
Skąd: Łódź

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


  1. <?
  2.  
  3. include('../mysql.php');
  4. include('include/functions.php');
  5.  
  6. include('include/mysql.php');
  7.  
  8. ?>
  9. <html>
  10. <head>
  11. <meta http-equiv="Content-type" content="text/html; charset=iso-8859-2">
  12. <link rel="stylesheet" href="../style.css" type="text/css">
  13.  
  14. </head>
  15. <table width="800" cellpadding="1" cellspacing="1" align="center" class="tabela2" border="0"> 
  16. <?
  17. include('include/header.php');
  18. ?>
  19. <tr>
  20. <th><a href="index.php">Forum</a></th>
  21. </tr>
  22.  
  23. <tr>
  24. <th colspan="8" class="cat3">Town Of Laugh</th>
  25. </tr>
  26. <tr class="post">
  27. <th colspan="2">Kategoria</th>
  28. <th>Tematów</th>
  29. <th>Postów</th>
  30. <th>Ostatni Post</th>
  31. </tr>
  32. <?
  33. while($kategoria = mysql_fetch_array($kategorie)){
  34. $posty_temat = mysql_query ("SELECT * FROM forum_posty WHERE `cat` = '".$kategoria[0]."' ORDER BY `ID` DESC") or die (mysql_error());
  35. $post_temat = mysql_fetch_array($posty_temat);
  36. $post_ilosc = mysql_num_rows($posty_temat);
  37. $ilosc_temat = mysql_query ("SELECT * FROM forum_tematy WHERE `id_kat` = '".$kategoria[0]."'") or die (mysql_error());
  38. $temat_ilosc = mysql_num_rows($ilosc_temat);
  39. <tr class=post>
  40. <th width=46><img src="images/folder_new_big.gif"></th>
  41. <th width=50%><a href=topic.php?cat='.$kategoria[0].'>'.$kategoria[1].'</a></th>
  42. <th>'.$temat_ilosc.'</th>
  43. <th>'.$post_ilosc.'</th>
  44. <th><a href=post.php?cat='.$post_temat[5].'&topic='.$post_temat[6].'>'.$post_temat[1].' | '.$post_temat[4].' | '.$post_temat[3].'</a></th>
  45. </tr>
  46. ');
  47. }
  48. ?>
  49. </table>
  50. <table width="800" cellpadding="1" cellspacing="1" align="center" border="0" bgcolor="#000000"> 
  51. <?
  52. $kategorii = mysql_num_rows($kategorie);
  53. $tematow = mysql_num_rows($tematy);
  54. $postow = mysql_num_rows($posty);
  55.  
  56. <tr>
  57. <th><img src="images/whosonline.gif"></th>
  58. <th>Kategorii: '.$kategorii.'<br>Tematów: '.$tematow.'<br>Postów: '.$postow.'</th>
  59. </tr>'
  60. );
  61. ?>
  62.  
  63. <tr>
  64. <th colspan="3">Legenda</th>
  65. </tr>
  66. <tr>
  67. <th><img src="images/folder_new_big.gif"></th>
  68. <th><img src="images/folder_locked_big.gif" ></th>
  69. <th><img src="images/folder_sticky.gif" ></th>
  70. </tr>
  71. <tr>
  72. <th>Forum Otwarte</th>
  73. <th>Forum Zablokowane</th>
  74. <th>Ważna Informacja</th>
  75. </tr>
  76. </table>
  77. </html>
  78. <?
  79. echo('Zalogowany jako');
  80. echo $slogin;
  81. ?>

skrypt jest troche nackany roznymi informacjami ale najwazniejsze ze dziala.
plik functions.php
  1. <?
  2. $login = $_POST['login'];
  3. $haslo = $_POST['haslo'];
  4. $md5 = md5($haslo);
  5. $baza = mysql_query("SELECT * FROM users WHERE `login` = '".$login."' AND `haslo` = '".$md5."'");
  6. if($baza){
  7.  
  8.  
  9. $dane=mysql_fetch_array($baza);
  10. if($login == $dane[2] && $md5 == $dane[3]){
  11. $_SESSION['zalogowany'] = true;
  12. $_SESSION['login'] = $dane[2];
  13. $slogin = $_SESSION['login'];
  14. header("Location: index.php");
  15.  
  16.  
  17.  
  18. }
  19. }
  20.  
  21. if($_GET['action'] == "logout"){
  22. header("Location: index.php");
  23. }
  24. ?>


a tak na marginesie to jeszcze jest jedna bardzo smieszna rzecz. $_SESSION['zalogowany'] działa bo mi sie menu zmienia na stronie bo mam oddzielne dla zalogowanych i nie zalogowanych (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 14.10.2025 - 18:20