Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php/mysql] problem z skryptem logowania
Majcok12
post
Post #1





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Mam problem z systemem newsow, tzn. zrobilem link "wiecej" w ktorym bedzie zawarta dalsza czesc newsa i tu jest problem, gdyz gdy klikam wiecej w obojetnie jakim newsie zawsze w stronie, ktora sie otworzy jest dalsza czesc newsa, ale ostatniego, ktory jest pobierany z bazy danych i nie wiem jak sobie z tym poradzic.
ponizej kod skryptu:
  1. <?php
  2. include &#092;"common.php\";
  3.  
  4. global $id_polaczenia;
  5. $id_polaczenia = db_connect();
  6. if(!$id_polaczenia) error_message(sql_error());
  7.  
  8. html_header();
  9. echo &#092;"<TR>n\";
  10. echo &#092;"<TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>News</b></center></TD>n\";
  11. echo &#092;"</TR>n\";
  12. echo &#092;"</table>n\";
  13. echo &#092;"<TABLE BORDER=\"0\" cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1200\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">n\";
  14. echo &#092;" <TR>n\";
  15. echo &#092;"  <TD valign=\"top\" align=\"left\" bgcolor=\"#414141\" colspan=\"3\">n\";
  16. echo &#092;"<br>n\";
  17.  
  18. $query = &#092;"SELECT news_headline, add_ndate, autor, news_contents, more, news_id, edit_
    n
  19. m FROM news ORDER BY news_num DESC LIMIT 0, 6\";
  20. $wynik = mysql_query($query);
  21. if(!$wynik) error_message(sql_error());
  22.  
  23. while ($q_data = mysql_fetch_array($wynik)) {
  24.     $naglowek = $q_data[\"news_headline\"];
  25.     $data = $q_data[\"add_ndate\"];
  26.     $autor = $q_data[\"autor\"];
  27.     $zawartosc_p = $q_data[\"news_contents\"];
  28.     $zawartosc_k = $q_data[\"more\"];
  29.     $id_news = $q_data[\"news_id\"];
  30.     $edit_n = $q_data[\"edit_num\"];
  31.  
  32. echo \"<font style=\"margin-left: 5pt; font-family: Verdana; font-size: 9pt; color: gray;\"><b> $naglowek </b><br>n\";
  33. echo \"<font style=\"margin-left: 5pt; font-family: Verdana; font-size: 9px; color: darkgray;\"> $data <br>n\";
  34.  
  35. echo \" <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"480\">n\";
  36. echo \" <tr>n\";
  37. echo \" <td align=\"center\" width=\"480\">n\";
  38. echo \"   <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"450\">n\";
  39. echo \"    <tr>n\";
  40. echo \"     <td align=\"center\" width=\"450\">n\";
  41. echo \"      <DIV ALIGN=\"justify\">n\";
  42. echo \"<font style=\"font-family: Verdana; font-size: 10px; color: gray;\">n\";
  43. echo \"$zawartosc_p n\";
  44. echo \"            </div>n\";
  45. echo \"          </td>n\";
  46. echo \"        </tr>n\";
  47. echo \"     </table>n\";
  48. echo \" </td>n\";
  49. echo \" </tr>n\";
  50. echo \" <tr>n\";
  51. echo \" <td align=\"left\" with\"480\">n\";
  52. echo \" &nbsp;<a target=\"blank\" href=\"index.php?action=view_r&id_news=$id_news\"><font style=\"font-family: Verdana; font-size: 9px;\"><i>Wiecej</i></a><br>n\";
  53. if(!$edit_n == 0) {
  54. echo \" &nbsp;&nbsp;&nbsp;<font style=\"font-family: Verdana; font-size: 9px;\"><i>Edytowano $edit_n razy</i><br>n\";
  55. }
  56. echo \" </td>n\";
  57. echo \" </tr>n\";
  58. echo \" </table>n\";
  59.  
  60. echo \"<center>n\";
  61. echo \"<img src=\"layout/l.jpg\">n\";
  62. echo \"</center>n\";
  63. echo \"<br>n\";
  64. }
  65. echo \"</td>n\";
  66. echo \"</TR>n\";
  67. echo \"</TABLE>n\";
  68. html_footer();
  69.  
  70. function view_r() {
  71.     global $id_news;
  72.     $query = \"SELECT news_headline, add_ndate, autor, news_contents, more, edit_num FROM n
  73. ws WHERE news_id = '$id_news'\";
  74.     $wynik = mysql_query($query);
  75.     if(!$wynik) error_message(sql_error());
  76.     $q_data = mysql_fetch_array($wynik);
  77.  
  78.     $naglowek = $q_data[\"news_headline\"];
  79.     $data = $q_data[\"add_ndate\"];
  80.     $autor = $q_data[\"autor\"];
  81.     $zawartosc_p = $q_data[\"news_contents\"];
  82.     $zawartosc_k = $q_data[\"more\"];
  83.     $edit_n = $q_data[\"edit_num\"];
  84.  
  85.     html_header();
  86. echo \"<TR>n\";
  87. echo \"<TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>News</b></center></TD>n\";
  88. echo \"</TR>n\";
  89. echo \"</table>n\";
  90. echo \"<TABLE BORDER=\"0\" cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1200\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">n\";
  91. echo \" <TR>n\";
  92. echo \"  <TD valign=\"top\" align=\"left\" bgcolor=\"#414141\" colspan=\"3\">n\";
  93. echo \"<br>n\";
  94.  
  95. echo \"<font style=\"margin-left: 5pt; font-family: Verdana; font-size: 9pt; color: gray;\"><b> $naglowek </b><br>n\";
  96. echo \"<font style=\"margin-left: 5pt; font-family: Verdana; font-size: 9px; color: darkgray;\"> $data <br>n\";
  97.  
  98. echo \" <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"480\">n\";
  99. echo \" <tr>n\";
  100. echo \" <td align=\"center\" width=\"480\">n\";
  101. echo \"   <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"450\">n\";
  102. echo \"    <tr>n\";
  103. echo \"     <td align=\"center\" width=\"450\">n\";
  104. echo \"      <DIV ALIGN=\"justify\">n\";
  105. echo \"<font style=\"font-family: Verdana; font-size: 10px; color: gray;\">n\";
  106. echo \"$zawartosc_p  <br><br>n\";
  107. echo \"$zawartosc_k n\";
  108. echo \"            </div>n\";
  109. echo \"          </td>n\";
  110. echo \"        </tr>n\";
  111. echo \"     </table>n\";
  112. echo \" </td>n\";
  113. echo \" </tr>n\";
  114. if(!$edit_n == 0) {
  115. echo \" <tr>n\";
  116. echo \" <td align=\"left\" with\"480\">n\";
  117. echo \" &nbsp;&nbsp;&nbsp;<font style=\"font-family: Verdana; font-size: 9px;\"><i>Edytowano $edit_n razy</i><br>n\";
  118. echo \" </td>n\";
  119. echo \" </tr>n\";
  120. }
  121. echo \" </table>n\";
  122.  
  123. echo \"<center>n\";
  124. echo \"<img src=\"layout/l.jpg\">n\";
  125. echo \"</center>n\";
  126. echo \"<br>n\";
  127. echo \"</td>n\";
  128. echo \"</TR>n\";
  129. echo \"</TABLE>n\";
  130. html_footer();
  131.  
  132.  
  133.  
  134. }
  135.  
  136. switch($action) {
  137.     case \"view_r\";
  138.     view_r();
  139.     break;
  140. }
  141.  
  142. ?>



Prosze o pomoc.

Pzdr

Ten post edytował Majcok12 20.10.2004, 18:13:40
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 17)
ARJ
post
Post #2





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

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


więc tak zaczne od drobnej porady:
po co utrudniasz sobie prace pisząc
  1. <?php
  2.  
  3. echo &#092;"<TR>n\";
  4. echo &#092;"<TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>News</b></center></TD>n\";
  5. echo &#092;"</TR>n\";
  6. echo &#092;"</table>n\";
  7.  
  8. ?>

itd.
niełatwiej napisać
  1. <?
  2. //skrypt php
  3. ?>
  4. kod html jak potrzeba to <?echo $wartosc;?>
  5. <?
  6. //dalsza część skryptu php
  7. ?>

dzięki temu kod jest czytelniejszy i łatwiej do czego kolwiek dojść. jeszcze jednym plusem jest szybkość napisania takiego skryptu.

co do problemu to taki jest algorytm:
- lista newsów, po kliknięciu na temat wysyłasz id newsa
- wyprowadzasz z bazy newsa o przesłanym id i wyświetlasz go

a co do twojego skryptu niedoszukałem się niczego (IMG:http://forum.php.pl/style_emoticons/default/dry.gif)

Ten post edytował ARJ 16.10.2004, 21:41:26
Go to the top of the page
+Quote Post
Majcok12
post
Post #3





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Lista newsow. A jak by to wygladalo, gdy na stronie wystwietlaja mi sie newsy (np. 6 na strone - czyli tak jak teraz) i po kliknieciu w link do funkcji view_r wysylany jest news_id odpowiedniego newsa i pobierana dalsza czesc newsa o tym id.
Jak odpowiednie fragmenty mojego skryptu wygladalyby, zeby to dzialalo poprawnie.
Go to the top of the page
+Quote Post
ARJ
post
Post #4





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

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


jak pokazujesz newsa to dajesz np. w jego tytule link
  1. <A HREF="news.php?id=<?echo $id_news;?>"><?echo $temat;?></A>

i pokazywanie wybranego newsa
  1. <?
  2. if(isset($_GET[&#092;"id\"])){
  3. $result1 = mysql_query(&#092;"SELECT * FROM news WHERE news_id='$_GET[id]'\");
  4. $myrow1=mysql_fetch_array($result1);
  5. ?>
  6. tabelka pokazująca newsa
  7. <?
  8. }
  9. ?>

niestety niezbyt mi się chce przeglądać cały twój mało czytelny skrypt i podać ci gotowe rozwiązanie

Ten post edytował ARJ 16.10.2004, 22:20:50
Go to the top of the page
+Quote Post
Majcok12
post
Post #5





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Nie wiem, czy dobrze zrozumialem, Zrobilem to tak:
  1. <?php
  2. if (empty($wynik)) {
  3. $query = &#092;"SELECT news_headline, add_ndate, autor, news_contents, more, news_id, edit_
    n
  4. m FROM news ORDER BY news_num DESC LIMIT 0, 6\";
  5. $wynik = mysql_query($query);
  6. if(!$wynik) error_message(sql_error());
  7.  
  8. while ($q_data = mysql_fetch_array($wynik)) {
  9. $naglowek = $q_data[\"news_headline\"];
  10. $data = $q_data[\"add_ndate\"];
  11. $autor = $q_data[\"autor\"];
  12. $zawartosc_p = $q_data[\"news_contents\"];
  13. $zawartosc_k = $q_data[\"more\"];
  14. $id_news = $q_data[\"news_id\"];
  15. $edit_n = $q_data[\"edit_num\"];
  16. ?>


  1. <?php
  2.  &nbsp;<a target=&#092;"blank\" href=\"index.php?id=$id_news&action=v_r\"><font style=\"font-family: Verdana; font-size: 9px;\"><i>Wiecej</i></a><br>
  3. ?>


  1. <?php
  2. function v_r() {
  3. if(isset($_GET[&#092;"id\"])){
  4. $wwynik = mysql_query(&#092;"SELECT news_headline, add_ndate, autor, news_contents, more, edit_num FROM 
    n
  5. ws WHERE news_id='$_GET[id]'\");
  6. if(!$wwynik) error_message(sql_error());
  7. $q_data = mysql_fetch_array($wwynik);
  8.  
  9. $naglowek = $q_data[\"news_headline\"];
  10. $data = $q_data[\"add_ndate\"];
  11. $autor = $q_data[\"autor\"];
  12. $zawartosc_p = $q_data[\"news_contents\"];
  13. $zawartosc_k = $q_data[\"more\"];
  14. $edit_n = $q_data[\"edit_num\"];
  15. ?>


I prawie wszystko dziala [tzn. w newsach od 2-6 (kolejnosc pobierania z bazy) po kliknieciu "wiecej" wyswietla sie odpowiednia zawartosc newsa, a tylko w tym, ktory jest jako pierwszy pobierany z bazy, gdy kliknie sie wiecej wyswietlana jest zawatosc ostatniego pobranego z bazy.

pzdr
Go to the top of the page
+Quote Post
Fibolg
post
Post #6





Grupa: Zarejestrowani
Postów: 123
Pomógł: 0
Dołączył: 1.12.2003
Skąd: Chełmno

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


Prawdopodobnie masz akurat ustawioną zmienną ID na ostatni news (może od czasu wyświetlania skróconych wersji), a z każdym następnym dopiero wysyłasz od nowa zapytanie o $id. Przejrzyj to bo ja jakoś dziś nie mam głowy (IMG:http://forum.php.pl/style_emoticons/default/tiredsmiley.gif)
Go to the top of the page
+Quote Post
ARJ
post
Post #7





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

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


skrypt dałeś niepełny ale chyba wiem o co chodzi. w środkowym kawałku kodu zaprezentowałeś link, link ten powinien być wstawiony w funkcje while z pierwszego kawałka. bo jeśli niejest to może dlatego jest taki błąd.
  1. <?
  2. if (empty($wynik)) {
  3. $query = &#092;"SELECT news_headline, add_ndate, autor, news_contents, more, news_id, edit_
    n
  4. m FROM news ORDER BY news_num DESC LIMIT 0, 6\";
  5. $wynik = mysql_query($query);
  6. if(!$wynik) error_message(sql_error());
  7.  
  8. while ($q_data = mysql_fetch_array($wynik)) {
  9. $naglowek = $q_data[\"news_headline\"];
  10. $data = $q_data[\"add_ndate\"];
  11. $autor = $q_data[\"autor\"];
  12. $zawartosc_p = $q_data[\"news_contents\"];
  13. $zawartosc_k = $q_data[\"more\"];
  14. $id_news = $q_data[\"news_id\"];
  15. $edit_n = $q_data[\"edit_num\"];
  16. ?>
  17. &nbsp;<a target=\"blank\" href=\"index.php?id=$id_news&action=v_r\"><font style=\"font-family: Verdana; font-size: 9px;\"><i>Wiecej</i></a><br>
  18. <?
  19. }
  20. ?>

mam nadzieję że o to chodzi.
Go to the top of the page
+Quote Post
Majcok12
post
Post #8





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Cytat(ARJ @ 2004-10-19 13:19:45)
skrypt dałeś niepełny ale chyba wiem o co chodzi. w środkowym kawałku kodu zaprezentowałeś link, link ten powinien być wstawiony w funkcje while z pierwszego kawałka. bo jeśli niejest to może dlatego jest taki błąd.
mam nadzieję że o to chodzi.


EH, sorry za zamieszanie. Dzieki postowi Fibolg'a sprawdzilem w bazie czy czasem id tego ostatniego newsa i pierwszego nie sa takie same i okazalo sie ze byly:P (ale juz takiej sytuacji nie bedzie, gdyz pole to ustawilem na UNIQUE).

Dzieki za wszystko.

------------------------------
Przy okzji zamiast robic nowy temat napisze tu to. Juz kiedys na forum webhelp.pl o tym pisalem ale rozwiazania prolemu nie otrzymalem. Otoz problem jest z skryptem logowania. Wpisuje dane, ktore zgadzaja sie z tymi ktore sa w bazie i mimo to skrypt generuje komunikat, ze "logowanie nie powiedlo sie ..."

pozniej kod skryptu:
  1. <?
  2. include(&#092;"common.php\");
  3. if(!session_is_registered($user_nick)) {
  4.     log_form();
  5.     exit;
  6. }
  7. else {
  8.     session_register(&#092;"user_nick\", \"user_password\");
  9.     $usernick = auth_u($user_nick, $user_password);
  10.     if(!$usernick) {
  11.         session_unregister(&#092;"user_nick\");
  12.         session_unregister(&#092;"user_password\");
  13.         echo &#092;"Logowanie nieudane.\" .
  14.             &#092;"Musisz podać poprawny nick oraz hasło. \" . 
  15.             &#092;"Spróboj jeszcze raz się zalogować. <br>n\";
  16.         echo &#092;"<a href=\"$PHP_SELF\">Logowanie</a><br>\";
  17.         exit;
  18.     }
  19.     else 
  20. global $id_polaczenia;
  21. $id_polaczenia = db_connect();
  22. function in_use($user_nick) {
  23.     global $user_tablename;
  24.  
  25.     $query = &#092;"SELECT user_nick FROM $user_tablename WHERE user_nick = '$user_nick'\";
  26.     $wynik = mysql_query($query);
  27.     if(!mysql_num_rows($wynik)) return 0;
  28.     else return 1;
  29. }
  30.  
  31. function reg_form() {
  32.  
  33. html_header();
  34. ?>
  35.  </TR>
  36.  <TR>
  37.   <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Dodaj nowego użytkownika</b></center></TD>
  38.  
  39.  </TR>
  40. </table>
  41. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  42.  <TR>
  43.   <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  44. <br>
  45. <form method=\"post\" enctype=\"multipart/form-data\" action=\"<?php echo $PHP_SELF ?>\">
  46. <input type=\"hidden\" name=\"action\" value=\"register\">
  47.  
  48.   <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"95%\" height=\"70%\" align=\"center\" valign=\"top\">
  49.    <tr>
  50.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Nick:</th>
  51.     <td width=\"70%\">&nbsp; <input type=\"text\" size=\"20\" maxlength=\"20\" name=\"nick\" class=\"pollItem\"></td>
  52.    </tr> 
  53.    <tr>
  54.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Wybrane hasło:</th>
  55.     <td width=\"70%\">&nbsp; <input type=\"password\" name=\"userpassword\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  56.    </tr>
  57.    <tr>
  58.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Powtórz hasło:</th>
  59.     <td width=\"70%\">&nbsp; <input type=\"password\" name=\"userpassword2\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  60.    </tr>
  61.    <tr>
  62.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Email:</th>
  63.     <td width=\"70%\">&nbsp; <input type=\"text\" name=\"usermail\" size=\"20\" maxlenght=\"40\" class=\"pollItem\"></td>
  64.    </tr>
  65.    <tr>
  66.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">O sobie:</th>
  67.     <td width=\"70%\">&nbsp;<textarea rows=\"5\" cols=\"40\" name=\"userprofile\" class=\"pollItem\"></textarea></td>
  68.    </tr>
  69.    <tr>
  70.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Sprzęt:</th>
  71.     <td width=\"70%\">&nbsp; <input type=\"text\" name=\"userhardware\" size=\"20\" maxlenght=\"40\" class=\"pollItem\"></td>
  72.    </tr>
  73.    <tr>
  74.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Admin:</th>
  75.     <td width=\"70%\">&nbsp; <select name=\"admin\" size=1 class=\"pollItem\">
  76.     <option selected value=\"NIE\">NIE</option>
  77.     <option value=\"TAK\">TAK</option>
  78.     </select>
  79.     </td>
  80.    </tr>
  81.    <tr>
  82.     <th width=\"30%\" colspan=\"2\" NOWRAP>
  83.     <input type=\"submit\" class=\"pollButton\" value=\"Rejestruj\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\">
  84.     <input type=\"reset\" class=\"pollButton\" value=\"Wyczysc\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\"></th>
  85.    </tr>
  86.   </table>
  87. </table>
  88.  </form>
  89. <?php
  90.     html_footer();
  91. }
  92.  
  93. function register_user() {
  94.     global $id_polaczenia;
  95.     global $nick, $userpassword, $userpassword2, $usermail, $userprofile, $userhardware, $admin;
  96.     global $default_db, $user_tablename;
  97.     $awatar = &#092;"obrazki/users/none.jpg\";
  98.  
  99.     mailcheck($usermail);
  100.     if(empty($userprofile)) error_message(&#092;"Brak komentarza!\");
  101.     if(empty($usermail)) error_message(&#092;"Brak adresu email!\");
  102.     if(empty($nick)) error_message(&#092;"Brak nicku!\");
  103.     if(empty($userpassword)) error_message(&#092;"Brak hasla!\");
  104.     if(empty($userpassword2)) error_message(&#092;"Musisz powtórzyć hasło!\");
  105.     if($userpassword!=$userpassword2)
  106.         error_message(&#092;"Podane hasła nie są identyczne\");
  107.  
  108.     if(in_use($nick)) 
  109.         error_message(&#092;"Wybrany nick jest już zajęty, proszę wybrać inny\");
  110.  
  111.     $query = &#092;"INSERT INTO users VALUES(NULL, '$nick', password('$userpassword'), '$usermail', '$userprofile', curdate(), NULL, '$userhardware', '$awatar', '$admin')\";
  112.  
  113.     $wynik = mysql_query($query);
  114.     if(!$wynik) error_message(sql_error());
  115.  
  116.     html_header();
  117. ?>
  118.  <TR>
  119.   <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Dodaj nowego użytkownika</b></center></TD>
  120.  
  121.  </TR>
  122. </table>
  123. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  124.  <TR>
  125.   <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  126. <br>
  127. <font style=\"font-family: Verdana; font-size: 9pt; color: gray;\"><b>Użytkownik <?php echo $nick ?> został zarejestrowany</b><br>
  128.  
  129.  </tr>
  130. </table>
  131. <?php 
  132.      html_footer();
  133. }
  134.  
  135. switch($action) {
  136.     case &#092;"register\":
  137.         register_user();
  138.     break;
  139.     default:
  140.         reg_form();
  141.     break;
  142. }
  143. }
  144.  
  145. function auth_u($user_nick, $user_password) {
  146.     global $id_polaczenia;
  147.     $id_polaczenia = db_connect();
  148.     $query = &#092;"SELECT user_nick FROM users WHERE user_nick = '$user_nick' AND user_pass = '$user_password' AND admin = 'TAK'\";
  149.  
  150.     $wynik = mysql_query($query);
  151.         if(!mysql_num_rows($wynik)) return 0;
  152.     else {
  153.         $query_data = mysql_fetch_row($wynik);
  154.         return $query_data[1];
  155.     }    
  156. }
  157. ?>



Wersja druga sesji (i gdy uruchamiam skrypt w wersji ponizej, juz nie pisze ze logowanie nie powiodlo sie, tylko zawsze ponownie wyswietla mi formularz logowania):
  1. <?
  2. include(&#092;"common.php\");
  3. if(!$_SESSION['user_nick']) { 
  4. log_form(); 
  5. exit; 
  6. }
  7. else {
  8. $_SESSION['user_nick\"\"user_password'];
  9. $usernick = auth_u($user_nick, $user_password);
  10. if(!$usernick) {
  11. unset($_SESSION['user_nick']);
  12. unset($_SESSION['user_password']);
  13. echo &#092;"Logowanie nieudane.\" .
  14. &#092;"Musisz podać poprawny nick oraz hasło. \" . 
  15. &#092;"Spróboj jeszcze raz się zalogować. <br>n\";
  16. echo &#092;"<a href=\"$PHP_SELF\">Logowanie</a><br>\";
  17. }
  18. else 
  19. ....
  20. ?>


Ten post edytował Majcok12 19.10.2004, 16:14:38
Go to the top of the page
+Quote Post
ARJ
post
Post #9





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

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


zaglądnij w ten topic http://forum.php.pl/index.php?showtopic=21975
jest tam też mój skrypt logowania. tak jak tam napisałem cudo techniki to to niejest lecz działa.
opis działania:
loguj.php
Kod
forumlarz, jesli login i hasło zostały podane zostają zapisane do sesji. jeśli zgadzają się z informacjami z bazy użytkownik odsyłany jest do strony admin.php

admin.php i każda inna
Kod
na początku i końcu login i hasło z sesji porównywane są z tymi w bazie danych.
skrypt ten opisany jest w topicu do którego podałem link.

mam nadzieję że coś z tego ci się przyda (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował ARJ 19.10.2004, 22:41:44
Go to the top of the page
+Quote Post
Majcok12
post
Post #10





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Wykorzystalem twoj pomysl, ale pewnie cos zle zrobielm, bo nie dziala.
kod funkcji log_form() (wyswietla formularz logowania)
  1. <?
  2. function log_form() {
  3. html_header();
  4. ?>
  5.  </TR>
  6.  <TR>
  7. <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Logowanie</b></center></TD>
  8.  
  9.  </TR>
  10. </table>
  11. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  12.  <TR>
  13. <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  14. <br>
  15. <form method=\"post\" action=\"<?php echo $PHP_SELF ?>\">
  16. <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"95%\" height=\"10%\" align=\"center\" valign=\"top\">
  17.  <tr>
  18. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Nick:</th>
  19. <td width=\"70%\"><input type=\"text\" name=\"user_nick\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  20.  </tr> 
  21.  <tr>
  22. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Hasło:</th>
  23. <td width=\"70%\"><input type=\"text\" name=\"user_password\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  24.  </tr> 
  25.  <tr>
  26. <th width=\"30%\" colspan=\"2\" NOWRAP>
  27. <input type=\"submit\" class=\"pollButton\" value=\"Zaloguj\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\">
  28. </tr>
  29.  </table>
  30. </table>
  31.  </form>
  32.  <?php
  33. html_footer();
  34.  
  35. $_SESSION['user_nick\"\"user_password'];
  36. }
  37. ?>


A tu pliku register.php
  1. <?
  2. include(&#092;"common.php\");
  3. global $id_polaczenia;
  4. $id_polaczenia = db_connect();
  5.  
  6. log_form();
  7.  
  8. $zapytanie=mysql_query(&#092;"SELECT user_nick, user_pass FROM users WHERE user_nick ='$_SESSION[user_nick]' AND user_pass ='$_SESSION[user_password]'\");
  9. $user=mysql_fetch_array($zapytanie);
  10. if($_SESSION[&#092;"user_nick\"] == strtolower($user[\"user_nick\"]) && $_SESSION[\"user_password\"] == $user[\"user_pass\"]){
  11.  
  12. global $id_polaczenia;
  13. $id_polaczenia = db_connect();
  14. function in_use($user_nick) {
  15. global $user_tablename;
  16.  
  17. $query = &#092;"SELECT user_nick FROM $user_tablename WHERE user_nick = '$user_nick'\";
  18. $wynik = mysql_query($query);
  19. if(!mysql_num_rows($wynik)) return 0;
  20. else return 1;
  21. }
  22.  
  23. function reg_form() {
  24.  
  25. html_header();
  26. ?>
  27.  </TR>
  28.  <TR>
  29. <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Dodaj nowego użytkownika</b></center></TD>
  30.  
  31.  </TR>
  32. </table>
  33. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  34.  <TR>
  35. <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  36. <br>
  37. <form method=\"post\" enctype=\"multipart/form-data\" action=\"<?php echo $PHP_SELF ?>\">
  38. <input type=\"hidden\" name=\"action\" value=\"register\">
  39.  
  40. <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"95%\" height=\"70%\" align=\"center\" valign=\"top\">
  41.  <tr>
  42. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Nick:</th>
  43. <td width=\"70%\">&nbsp; <input type=\"text\" size=\"20\" maxlength=\"20\" name=\"nick\" class=\"pollItem\"></td>
  44.  </tr> 
  45.  <tr>
  46. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Wybrane hasło:</th>
  47. <td width=\"70%\">&nbsp; <input type=\"password\" name=\"userpassword\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  48.  </tr>
  49.  <tr>
  50. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Powtórz hasło:</th>
  51. <td width=\"70%\">&nbsp; <input type=\"password\" name=\"userpassword2\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  52.  </tr>
  53.  <tr>
  54. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Email:</th>
  55. <td width=\"70%\">&nbsp; <input type=\"text\" name=\"usermail\" size=\"20\" maxlenght=\"40\" class=\"pollItem\"></td>
  56.  </tr>
  57.  <tr>
  58. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">O sobie:</th>
  59. <td width=\"70%\">&nbsp;<textarea rows=\"5\" cols=\"40\" name=\"userprofile\" class=\"pollItem\"></textarea></td>
  60.  </tr>
  61.  <tr>
  62. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Sprzęt:</th>
  63. <td width=\"70%\">&nbsp; <input type=\"text\" name=\"userhardware\" size=\"20\" maxlenght=\"40\" class=\"pollItem\"></td>
  64.  </tr>
  65.  <tr>
  66. <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Admin:</th>
  67. <td width=\"70%\">&nbsp; <select name=\"admin\" size=1 class=\"pollItem\">
  68. <option selected value=\"NIE\">NIE</option>
  69. <option value=\"TAK\">TAK</option>
  70. </select>
  71. </td>
  72.  </tr>
  73.  <tr>
  74. <th width=\"30%\" colspan=\"2\" NOWRAP>
  75. <input type=\"submit\" class=\"pollButton\" value=\"Rejestruj\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\">
  76. <input type=\"reset\" class=\"pollButton\" value=\"Wyczysc\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\"></th>
  77.  </tr>
  78. </table>
  79. </table>
  80.  </form>
  81. <?php
  82. html_footer();
  83. }
  84.  
  85. function register_user() {
  86. global $id_polaczenia;
  87. global $nick, $userpassword, $userpassword2, $usermail, $userprofile, $userhardware, $admin;
  88. global $default_db, $user_tablename;
  89. $awatar = &#092;"obrazki/users/none.jpg\";
  90.  
  91. mailcheck($usermail);
  92. if(empty($userprofile)) error_message(&#092;"Brak komentarza!\");
  93. if(empty($usermail)) error_message(&#092;"Brak adresu email!\");
  94. if(empty($nick)) error_message(&#092;"Brak nicku!\");
  95. if(empty($userpassword)) error_message(&#092;"Brak hasla!\");
  96. if(empty($userpassword2)) error_message(&#092;"Musisz powtórzyć hasło!\");
  97. if($userpassword!=$userpassword2)
  98. error_message(&#092;"Podane hasła nie są identyczne\");
  99.  
  100. if(in_use($nick)) 
  101. error_message(&#092;"Wybrany nick jest już zajęty, proszę wybrać inny\");
  102.  
  103. $query = &#092;"INSERT INTO users VALUES(NULL, '$nick', '$userpassword', '$usermail', '$userprofile', curdate(), NULL, '$userhardware', '$awatar', '$admin')\";
  104.  
  105. $wynik = mysql_query($query);
  106. if(!$wynik) error_message(sql_error());
  107.  
  108. html_header();
  109. ?>
  110.  <TR>
  111. <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Dodaj nowego użytkownika</b></center></TD>
  112.  
  113.  </TR>
  114. </table>
  115. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  116.  <TR>
  117. <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  118. <br>
  119. <font style=\"font-family: Verdana; font-size: 9pt; color: gray;\"><b>Użytkownik <?php echo $nick ?> został zarejestrowany</b><br>
  120.  
  121.  </tr>
  122. </table>
  123. <?php 
  124.  html_footer();
  125. }
  126.  
  127. switch($action) {
  128. case &#092;"register\":
  129. register_user();
  130. break;
  131. default:
  132. reg_form();
  133. break;
  134. }
  135. }
  136.  
  137. else{
  138. header(&#092;"Location: $PHP_SELF?msg=Zły login lub hasło\"); exit;
  139. }
  140.  
  141. ?>


PZdr
Go to the top of the page
+Quote Post
ARJ
post
Post #11





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

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


twój kod jest bardziej zaawansowany niż mój. po dłuższym studiowaniu twojego kodu nic nie wymyśliłem. załanczam mój skrypt logowania do panelu administracyjnego:
  1. <?
  2. include(&#092;"connect.php\");
  3. if(isset($_POST['login']) && isset($_POST['haslo'])){
  4. $_SESSION[&#092;"login\"] = strtolower(trim($_POST['login']));
  5. $_SESSION[&#092;"haslo\"] = md5(trim($_POST['haslo']));
  6. $users=mysql_query(&#092;"SELECT * FROM users WHERE login='$_SESSION[login]'\");
  7. $user=mysql_fetch_array($users);
  8. if($_SESSION[&#092;"haslo\"] == $user[\"haslo\"] && $_SESSION[\"login\"] == strtolower($user[\"login\"]) && $user[\"poziom\"] == \"3\"){
  9. header(&#092;"Location: frame.php\"); exit;
  10. }else{
  11. $_GET[&#092;"msg\"] = \"Zły login lub hasło\";
  12. }
  13. }
  14. ?>
  15. <HTML>
  16. <HEAD>
  17. <META HTTP-EQUIV=\"Content-type\" CONTENT=\"text/html; charset=iso-8859-2\">
  18. <TITLE>Logowanie | Panel administracyjny</TITLE>
  19. </HEAD><BODY>
  20. <BR><BR><BR><BR><BR><BR><BR><BR>
  21. <CENTER><TABLE BORDER=\"0\" WIDTH=\"300\">
  22. <TR><TD COLSPAN=\"2\">Logowanie</TD></TR>
  23. <TR><TD COLSPAN=\"2\">&nbsp;</TD></TR>
  24. <FORM ACTION=\"loguj.php\" METHOD=\"POST\">
  25. <TR><TD>Login:</TD><TD><INPUT TYPE=\"TEXT\" NAME=\"login\" STYLE=\"width: 150\"></TD></TR>
  26. <TR><TD>Haslo:</TD><TD><INPUT TYPE=\"PASSWORD\" NAME=\"haslo\" STYLE=\"width: 150\"></TD></TR>
  27. <TR><TD COLSPAN=\"2\" ALIGN=\"CENTER\"><INPUT TYPE=\"SUBMIT\" VALUE=\"Loguj\"></TD></TR>
  28. <TR><TD COLSPAN=\"2\" ALIGN=\"CENTER\"><?echo @$_GET[&#092;"msg\"];?></TD></TR>
  29. </TABLE></CENTER>
  30. </BODY>
  31. </HTML>

plik frame.php i każdy następny w panelu
  1. <?
  2. include(&#092;"connect.php\");
  3. $users=mysql_query(&#092;"SELECT * FROM users WHERE login='$_SESSION[login]'\");
  4. $user=mysql_fetch_array($users);
  5. if($_SESSION[&#092;"login\"] == strtolower($user[\"login\"]) && $_SESSION[\"haslo\"] == $user[\"haslo\"] && $user[\"poziom\"] == \"3\"){
  6. ?>
  7. <html>
  8. <head>
  9. <title>Panel administracyjny | Index</title>
  10. <meta http-equiv=\"Content-Type\" content=\"text/html;\">
  11. </head>
  12.  
  13.  
  14. <frameset cols=\"170,*\" rows=\"*\" border=\"2\" framespacing=\"0\" frameborder=\"yes\"> 
  15. <frame src=\"menu.php\" name=\"nav\" marginwidth=\"3\" marginheight=\"3\" scrolling=\"auto\">
  16. <frame src=\"main.php\" name=\"main\" marginwidth=\"10\" marginheight=\"10\" scrolling=\"auto\">
  17. <FRAME NORESIZE>
  18. </frameset>
  19.  
  20. <noframes>
  21. <body bgcolor=\"#FFFFFF\" text=\"#000000\">
  22. <p>Niestety, twoja przeglądarka nieobsługuje ramek</p><BR>
  23. <p>Sorry, your browser doesn't seem to support frames</p>
  24. </body>
  25. </noframes>
  26. </html>
  27. <?
  28. }else{
  29. header(&#092;"Location: loguj.php?msg=Zły login lub hasło\"); exit;
  30. }?>

może to ci w jakiś sposób pomoże. nie jestem zbyt zaawansowany w php dlatego ten skrypt jest bardzo prosty i mały, jednak w pełni sam go wymyśliłem i u mnie działa bez problemu.
Go to the top of the page
+Quote Post
Majcok12
post
Post #12





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Zmienilem skrypt uzywajac kodu twojego skryptu.
Teraz skrypt wyglada tak:
  1. <?
  2. include(&#092;"common.php\");
  3. global $id_polaczenia;
  4. $id_polaczenia = db_connect();
  5.  
  6. if(!isset($_POST[&#092;"user_nick\"]) && !isset($_POST[\"user_password\"]) && !$_SESSION[\"usernick\"] && !$_SESSION[\"userpassword\"]){
  7.         html_header();
  8. ?>
  9.  </TR>
  10.  <TR>
  11.   <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Logowanie</b></center></TD>
  12.  
  13.  </TR>
  14. </table>
  15. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  16.  <TR>
  17.   <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  18. <br>
  19. <form method=\"post\" action=\"<?php echo $PHP_SELF ?>\">
  20.   <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"95%\" height=\"10%\" align=\"center\" valign=\"top\">
  21.    <tr>
  22.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Nick:</th>
  23.     <td width=\"70%\"><input type=\"text\" name=\"user_nick\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  24.    </tr> 
  25.    <tr>
  26.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Hasło:</th>
  27.     <td width=\"70%\"><input type=\"text\" name=\"user_password\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  28.    </tr> 
  29.    <tr>
  30.     <th width=\"30%\" colspan=\"2\" NOWRAP>
  31.     <input type=\"submit\" class=\"pollButton\" value=\"Zaloguj\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\">
  32.     </tr>
  33.    </table>
  34.   </table>
  35.    </form>
  36.    <?php
  37.     html_footer();
  38.  
  39. $_SESSION[&#092;"usernick\"] = strtolower(trim($_POST['user_nick']));
  40. $_SESSION[&#092;"userpassword\"] = md5(trim($_POST['user_password']));
  41.  
  42.     }
  43.     else 
  44.  
  45. $zapytanie=mysql_query(&#092;"SELECT user_nick, user_pass FROM users WHERE user_nick ='$_SESSION[usernick]'\");
  46. $user=mysql_fetch_array($zapytanie);
  47. if($_SESSION[&#092;"usernick\"] == strtolower($user[\"user_nick\"]) && $_SESSION[\"userpassword\"] == $user[\"user_pass\"] && $user[\"admin\"] == \"TAK\"){
  48.  
  49. global $id_polaczenia;
  50. $id_polaczenia = db_connect();
  51. function in_use($user_nick) {
  52.     global $user_tablename;
  53.  
  54.     $query = &#092;"SELECT user_nick FROM $user_tablename WHERE user_nick = '$user_nick'\";
  55.     $wynik = mysql_query($query);
  56.     if(!mysql_num_rows($wynik)) return 0;
  57.     else return 1;
  58. }
  59.  
  60. function reg_form() {
  61.  
  62. html_header();
  63. ?>
  64.  </TR>
  65.  <TR>
  66.   <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Dodaj nowego użytkownika</b></center></TD>
  67.  
  68.  </TR>
  69. </table>
  70. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  71.  <TR>
  72.   <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  73. <br>
  74. <form method=\"post\" enctype=\"multipart/form-data\" action=\"<?php echo $PHP_SELF ?>\">
  75. <input type=\"hidden\" name=\"action\" value=\"register\">
  76.  
  77.   <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"95%\" height=\"70%\" align=\"center\" valign=\"top\">
  78.    <tr>
  79.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Nick:</th>
  80.     <td width=\"70%\">&nbsp; <input type=\"text\" size=\"20\" maxlength=\"20\" name=\"nick\" class=\"pollItem\"></td>
  81.    </tr> 
  82.    <tr>
  83.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Wybrane hasło:</th>
  84.     <td width=\"70%\">&nbsp; <input type=\"password\" name=\"userpassword\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  85.    </tr>
  86.    <tr>
  87.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Powtórz hasło:</th>
  88.     <td width=\"70%\">&nbsp; <input type=\"password\" name=\"userpassword2\" size=\"20\" maxlenght=\"20\" class=\"pollItem\"></td>
  89.    </tr>
  90.    <tr>
  91.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Email:</th>
  92.     <td width=\"70%\">&nbsp; <input type=\"text\" name=\"usermail\" size=\"20\" maxlenght=\"40\" class=\"pollItem\"></td>
  93.    </tr>
  94.    <tr>
  95.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">O sobie:</th>
  96.     <td width=\"70%\">&nbsp;<textarea rows=\"5\" cols=\"40\" name=\"userprofile\" class=\"pollItem\"></textarea></td>
  97.    </tr>
  98.    <tr>
  99.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Sprzęt:</th>
  100.     <td width=\"70%\">&nbsp; <input type=\"text\" name=\"userhardware\" size=\"20\" maxlenght=\"40\" class=\"pollItem\"></td>
  101.    </tr>
  102.    <tr>
  103.     <th width=\"30%\" NOWRAP><font style=\"font-family: Verdana; font-size: 10px; color: gray;\">Admin:</th>
  104.     <td width=\"70%\">&nbsp; <select name=\"admin\" size=1 class=\"pollItem\">
  105.     <option selected value=\"NIE\">NIE</option>
  106.     <option value=\"TAK\">TAK</option>
  107.     </select>
  108.     </td>
  109.    </tr>
  110.    <tr>
  111.     <th width=\"30%\" colspan=\"2\" NOWRAP>
  112.     <input type=\"submit\" class=\"pollButton\" value=\"Rejestruj\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\">
  113.     <input type=\"reset\" class=\"pollButton\" value=\"Wyczysc\" onmouseover=\"this.className='pollButton-over'\" onmouseout=\"this.className='pollButton'\"></th>
  114.    </tr>
  115.   </table>
  116. </table>
  117.  </form>
  118. <?php
  119.     html_footer();
  120. }
  121.  
  122. function register_user() {
  123.     global $id_polaczenia;
  124.     global $nick, $userpassword, $userpassword2, $usermail, $userprofile, $userhardware, $admin;
  125.     global $default_db, $user_tablename;
  126.     $awatar = &#092;"obrazki/users/none.jpg\";
  127.  
  128.     mailcheck($usermail);
  129.     if(empty($userprofile)) error_message(&#092;"Brak komentarza!\");
  130.     if(empty($usermail)) error_message(&#092;"Brak adresu email!\");
  131.     if(empty($nick)) error_message(&#092;"Brak nicku!\");
  132.     if(empty($userpassword)) error_message(&#092;"Brak hasla!\");
  133.     if(empty($userpassword2)) error_message(&#092;"Musisz powtórzyć hasło!\");
  134.     if($userpassword!=$userpassword2)
  135.         error_message(&#092;"Podane hasła nie są identyczne\");
  136.  
  137.     if(in_use($nick)) 
  138.         error_message(&#092;"Wybrany nick jest już zajęty, proszę wybrać inny\");
  139.  
  140.     $query = &#092;"INSERT INTO users VALUES(NULL, '$nick', '$userpassword', '$usermail', '$userprofile', curdate(), NULL, '$userhardware', '$awatar', '$admin')\";
  141.  
  142.     $wynik = mysql_query($query);
  143.     if(!$wynik) error_message(sql_error());
  144.  
  145.     html_header();
  146. ?>
  147.  <TR>
  148.   <TD WIDTH=\"100%\" HEIGHT=\"16\" background=\"layout/belka2.gif\" style=\"border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black;\"><center><font style=\"font-family: Times New Roman; font-size: 8pt;\"><b>Dodaj nowego użytkownika</b></center></TD>
  149.  
  150.  </TR>
  151. </table>
  152. <TABLE cellpadding=\"1\" cellspacing=\"0\" WIDTH=\"100%\" HEIGHT=\"1000\" BGCOLOR=\"#000000\" style=\"border-left: solid; border-left-width: 1px; border-left-color: black; border-bottom: solid; border-bottom-width: 1px; border-bottom-color: black; border-right: solid; border-right-width: 1px; border-right-color: black;\">
  153.  <TR>
  154.   <TD valign=\"top\" align=\"center\" bgcolor=\"#414141\" colspan=\"3\">
  155. <br>
  156. <font style=\"font-family: Verdana; font-size: 9pt; color: gray;\"><b>Użytkownik <?php echo $nick ?> został zarejestrowany</b><br>
  157.  
  158.  </tr>
  159. </table>
  160. <?php 
  161.      html_footer();
  162. }
  163.  
  164. switch($action) {
  165.     case &#092;"register\":
  166.         register_user();
  167.     break;
  168.     default:
  169.         reg_form();
  170.     break;
  171. }
  172. }
  173. else
  174. session_unregister(&#092;"usernick\");
  175. session_unregister(&#092;"userpassword\");
  176. echo &#092;"zly login lub haslo\";
  177. echo &#092;"<a href=\"$PHP_SELF\">Logowanie</a><br>\";
  178.  
  179. ?>


Mimo tego iz podaje dobre dane (www.majcok.republika.pl/d_screenn.JPG) i w rekordzie ktory pobiera (narazie jest tylko jeden wpis) pole 'admin' ma wartosc 'TAK' na ekranie pojawia mi sie komunikat o blednym loginie lub hasle.

Chociaz juz jakis postep (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował Majcok12 20.10.2004, 18:12:10
Go to the top of the page
+Quote Post
ARJ
post
Post #13





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

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


Cytat(Majcok12 @ 2004-10-20 18:58:05)
57
  1. <?php
  2. $_SESSION[&#092;"userpassword\"] = md5(trim($_POST['user_password']));
  3. ?>

w tym miejscu jest błąd a raczej rozbieżność danych. ja mam hasło kodowane w bazie przy użyciu md5. hasło podane przez usera przy logowaniu jest kodowane przez md5. później jest funkcja trim która obcina spacje z początka i końca wpisywanego hasła. masz dwie możliwości. zakodować hasło w bazie md5 lub wpisać w linie 57
  1. <?php
  2. $_SESSION[&#092;"userpassword\"] = trim($_POST['user_password']);
  3. ?>

lepiej jest kodować hasła jest bezpieczniej. jeszcze mam jedną radę w formularzu podaje się login i hasło, lepiej jak pole hasło jest typu hidden a nie text.
Go to the top of the page
+Quote Post
Majcok12
post
Post #14





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Zmienilem skrypt tak jak napisales i to samo.
Probwalem tez tak:
  1. <?
  2.  
  3. $_SESSION[&#092;"usernick\"] = $_POST['user_nick'];
  4. $_SESSION[&#092;"userpassword\"] = $_POST['user_password'];
  5.  
  6.     }
  7.     else 
  8. $zapytanie = mysql_query(&#092;"SELECT user_nick, user_pass, admin FROM users WHERE user_nick ='$_SESSION[usernick]'\");
  9. $user = mysql_fetch_array($zapytanie);
  10. if($_SESSION[&#092;"usernick\"] == $user[\"user_nick\"] && $_SESSION[\"userpassword\"] == $user[\"user_pass\"] && $user[\"admin\"] == \"TAK\"){
  11.  
  12. ?>

I to samo.

pzdr

Ten post edytował Majcok12 20.10.2004, 20:22:30
Go to the top of the page
+Quote Post
ARJ
post
Post #15





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

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


a jeśli dasz
  1. <?
  2.  
  3. }
  4. else 
  5.  
  6. $_SESSION[&#092;"usernick\"] = $_POST['user_nick'];
  7. $_SESSION[&#092;"userpassword\"] = $_POST['user_password'];
  8.  
  9. $zapytanie = mysql_query(&#092;"SELECT user_nick, user_pass, admin FROM users WHERE user_nick ='$_SESSION[usernick]'\");
  10. $user = mysql_fetch_array($zapytanie);
  11. if($_SESSION[&#092;"usernick\"] == $user[\"user_nick\"] && $_SESSION[\"userpassword\"] == $user[\"user_pass\"] && $user[\"admin\"] == \"TAK\"){
  12.  
  13. ?>

(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) bo już sam niewiem gdzie może być błąd.
Go to the top of the page
+Quote Post
Majcok12
post
Post #16





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Cytat(ARJ @ 2004-10-20 22:24:21)
a jeśli dasz
  1. <?
  2.  
  3.     }
  4.     else 
  5.  
  6. $_SESSION[&#092;"usernick\"] = $_POST['user_nick'];
  7. $_SESSION[&#092;"userpassword\"] = $_POST['user_password'];
  8.  
  9. $zapytanie = mysql_query(&#092;"SELECT user_nick, user_pass, admin FROM users WHERE user_nick ='$_SESSION[usernick]'\");
  10. $user = mysql_fetch_array($zapytanie);
  11. if($_SESSION[&#092;"usernick\"] == $user[\"user_nick\"] && $_SESSION[\"userpassword\"] == $user[\"user_pass\"] && $user[\"admin\"] == \"TAK\"){
  12.  
  13. ?>

(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) bo już sam niewiem gdzie może być błąd.

(IMG:http://forum.php.pl/style_emoticons/default/ohmy.gif) DZIALA!:) (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Heh, spox.

Thx ARJ (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Edit. Tzn. dziala pod tym wzgledem, ze jak sie poda poprawne dane to sie otowrzy odpowiednia strona, w przecwinym wypadku bedzie pusta biala strona i info o blednym loginie lub hasle. Jednak mimo tego, ze mnie loguje i dane sa zapisywane do sesji, po powonym wejsci na strone register.php od razu wyskakuje komunikat ze bledny login lub hasli i ponownie trzeba sie logowac.

Ten post edytował Majcok12 21.10.2004, 20:39:43
Go to the top of the page
+Quote Post
ARJ
post
Post #17





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

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


tylko po co wracać na tą stronę? ona loguje tylko
Kod
logowanie -> strona gł.panelu administracyjnego -> podstrony -> wylogowanie
         ^<---------------------------<^-----------------<^ niezalogowany

trzeba by skrypt troche przerobić na wypadek gdy user jest zalogowany. najlepiej tę strone zrobić jako logującą.
Go to the top of the page
+Quote Post
Majcok12
post
Post #18





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 20.02.2004

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


Zapomnialem napisac. Chociaz po podaniu poprawnych danych skrypt mnie loguje na strone rejestrujaca to gdy wypelnie dane dot. usera i wysle formularz pojawia sie komunikat o blednym loginie lub hasle.
Go to the top of the page
+Quote Post

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: 23.08.2025 - 16:03