Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> logowanie
-Vanx-
post
Post #1





Goście







Mam problem z logowaniem, wygląda to tak:
  1. <?php
  2. require_once(&#092;"config.php\");
  3. require('libs/Smarty.class.php');
  4. if (!$_POST['user'] || !$_POST['pass']) {
  5. $smarty -> assign (&#092;"Error\", \"Musisz wypełnić wszystkie pola!.\");
  6. $smarty -> display ('error.tpl');
  7.  
  8. }
  9. $log = mysql_num_rows(mysql_query(&#092;"select logins, user, pass from players where user='$_POST[user]' and pass='$_POST[pass]'\"));
  10. if ($log <= 0) {
  11. print &#092;"niejesteś zarejestrowany\";
  12. } else {
  13. mysql_query(&#092;"update players set logins=logins+1 where user='$_POST[user]'\");
  14. $smarty -> display ('index.tpl');
  15.  
  16. }
  17. ?>

ale to niedział(IMG:http://forum.php.pl/style_emoticons/default/exclamation.gif) a chciałbym aby przy każdym logowaniu rekord "logins" zwiększał się o 1 i po kliknięciu na zaloguj pojawiła się strona index.tpl. Jak mam to zrobić?? Używam smarty.
Go to the top of the page
+Quote Post
2 Stron V   1 2 >  
Start new topic
Odpowiedzi (1 - 19)
MagnuM
post
Post #2





Grupa: Zarejestrowani
Postów: 108
Pomógł: 0
Dołączył: 7.05.2004
Skąd: Jelenia Góra

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


  1. <?php
  2. require_once(&#092;"config.php\");
  3. require('libs/Smarty.class.php');
  4. if (!$_POST['user'] || !$_POST['pass']) {
  5. $smarty -> assign (&#092;"Error\", \"Musisz wypełnić wszystkie pola!.\");
  6. $smarty -> display ('error.tpl');
  7.  
  8. }
  9. $user = $_POST['user'];
  10. $pass = $_POST['pass'];
  11. $log = mysql_num_rows(mysql_query(&#092;"select logins, user, pass from players where user='$user' and pass='$pass'\"));
  12. if ($log <= 0) {
  13. print &#092;"niejesteś zarejestrowany\";
  14. } else {
  15. $sqlQuery = mysql_query(&#092;"SELECT logins FROM players WHERE user = '$user'\");
  16. $sqlArray = mysql_fetch_array($sqlQuery);
  17.  
  18. $logins = $sqlArray['logins'] + 1;
  19. mysql_query(&#092;"update players set logins='logins' where user='$user'\");
  20. $smarty -> display ('index.tpl');
  21.  
  22. }
  23. ?>


Spróbuj to. nie sprawdzałem także nie wiem czy jest dobrze.

Z tego co wiem to $_POST['user'] i $_POST[user] to nei to samo. Dodatkowo w funkcjach mysql nie można używać zmiennych globalnych (ja przynajmniej nie używam bo chyba się nie da). trzeba najpierw przypisać zmienną globalną do zwykłej i wtedy umieszczać taką zmienną w bazie. Dodatkowo nie wiem czy 'logins=logins+1' będzie działać dlatego poprawiłem. Ale jestem niestety prawie przekonany że nie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Pozdrawiam.
Go to the top of the page
+Quote Post
-Vanx-
post
Post #3





Goście







Dzięki działa tylko funkacja
  1. <?php
  2.  
  3.  mysql_query(&#092;"update players set logins='logins' where user='$user'\");
  4. $smarty -> display ('index.tpl');
  5.  
  6. ?>

niewyświetla mi po zalogowaniu strony głównej (IMG:http://forum.php.pl/style_emoticons/default/dry.gif) i jak zrobić aby po niewypełnieniu któregoś pola wyskakiwał napis: wypełnij wszystkie pola!. (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
hwao
post
Post #4


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




  1. <?php
  2.  $forms = array();
  3. if( isSet( $_POST['xxx'] ) ) {
  4.  $forms[] = 'Prosze wypelnic pole xxx - 3 do 4 znaki ble ble';
  5. }
  6. if( isSet( $_POST['yyy'] ) ) {
  7.  $forms[] = 'Prosze wypelnic pole yyy';
  8. }
  9.  
  10. ?>

Potem to assignujesz (assign_by_ref - najlepiej) do smarty i wysietlasz...
Go to the top of the page
+Quote Post
-Vanx-
post
Post #5





Goście







Dzięki!, tylko jak zrobić aby po zalogowaniu wyświetlił mi się plik index.tpl??
Go to the top of the page
+Quote Post
hwao
post
Post #6


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




Qrde (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) na to jest 100 sposobow:P
Mozesz np tak

  1. <?php
  2. if( ZALOGOWANY ) { // wstaw tu warunek sprawdzajacy zalogowanie 
  3. // jakas sessja cookie czy co tam kolwiek masz
  4.  
  5.  $smarty -> display ('zalogowany.tpl');
  6. }
  7. else {
  8.  $smarty -> display ('gosc.tpl');
  9. }
  10. ?>
Go to the top of the page
+Quote Post
-Vanx-
post
Post #7





Goście







Tak się składa że ja mam taki warunek (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)
  1. <?php
  2.  
  3. if ($log <= 0) {
  4. print &#092;"niejesteś zarejestrowany\";
  5. } else {
  6. $sqlQuery = mysql_query(&#092;"SELECT logins FROM players WHERE user = '$user'\");
  7. $sqlArray = mysql_fetch_array($sqlQuery);
  8.  
  9. $logins = $sqlArray['logins'] + 1;
  10. mysql_query(&#092;"update players set logins='logins' where user='$user'\");
  11.  
  12. $smarty -> display ('index.tpl');
  13. }
  14. ?>

tylko ten plik index.tpl się nie pojawia (IMG:http://forum.php.pl/style_emoticons/default/angrysmiley.gif)
Go to the top of the page
+Quote Post
Vanx
post
Post #8





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 3.07.2005

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


Już to zrobiłem napisałem tak
  1. <?php
  2. require_once(&#092;"config.php\");
  3. require(&#092;"plik.html\");
  4. require('libs/Smarty.class.php');
  5.  
  6. $user = $_POST['user'];
  7. $pass = $_POST['pass'];
  8. $log = mysql_num_rows(mysql_query(&#092;"select logins, user, pass from players where user='$user' and pass='$pass'\"));
  9.  
  10. if(!$_POST['user'] || !$_POST['pass']){
  11. print &#092;"<center>Prosze wypełnić wszystkie pola!.</center>\";
  12. }
  13.  
  14. if ($log <= 0) {
  15.  print '<table align=\"bottom\">Podałeś złe dane lub nie jesteś zarejestrowany!.</table>';
  16. } else {
  17.  
  18. $sqlQuery = mysql_query(&#092;"SELECT logins FROM players WHERE user = '$user'\");
  19. $sqlArray = mysql_fetch_array($sqlQuery);
  20.  
  21. $logins = $sqlArray['logins'] + 1;
  22. mysql_query(&#092;"update players set logins='logins' where user='$user'\");
  23. print '<table align=\"center\">
  24. <tr>
  25. <td>
  26. Zostałeś zalogowany kliknij <a href=\"index.tpl\">TUTAJ</a>.
  27. </td>
  28. </tr>
  29. </table>';
  30.  }
  31.  
  32. ?>

tylko że nawet jak się niezaloguje to i tak można wejsć do index.tpl (wpisując adres do przegladarki) a jak można zrobić aby nie zalogowany wogóle nie mógł wejść na stronę??
Go to the top of the page
+Quote Post
hwao
post
Post #9


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




  1. Zostałeś zalogowany kliknij <a href="index.tpl">TUTAJ</a>.

Ke?

Chyba masz maly zonk.
Nie wiem na jakim jestes etapie w naucze php ale mysle ze powineines przemyslec to co piszesz.
Jak mozna cos takiego zrobic znacyz ze program nie jest w ogole przemyslany.

Swoja droga co to za dziwny link...

Zrobo sobie osobny plik (tak bedize najprosciej) do ktorego ma wstep tylko zarjesterowany i w nim bedzie to co ma zarejestrowany... (na poczatku sprawdzacz czy gosc jest zarejestrowany, jak nie to odlysza go do pliku oblugujacego zywklego goscia.)
Go to the top of the page
+Quote Post
Vanx
post
Post #10





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 3.07.2005

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


Właśnie w tym problem że nie wiem jak (IMG:http://forum.php.pl/style_emoticons/default/dry.gif) a gdybym użył cookies?(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) gdy się loguje wysyła ciasteczko do komputera logującego, następnie na stronie sprawdzał by czy ciasteczko jest w komputerze. Bezpieczne jest używanie ciasteczek??
Go to the top of the page
+Quote Post
hwao
post
Post #11


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




Cytat(Vanx @ 2005-07-03 16:41:23)
Właśnie w tym problem że nie wiem jak (IMG:http://forum.php.pl/style_emoticons/default/dry.gif) a gdybym użył cookies?(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) gdy się loguje wysyła ciasteczko do komputera logującego, następnie na stronie sprawdzał by czy ciasteczko jest w komputerze. Bezpieczne jest używanie ciasteczek??

zle zabezpieczenie, ciasteczko moge sobie dodac sam, juz lepiej sessje.
Go to the top of the page
+Quote Post
Vanx
post
Post #12





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 3.07.2005

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


Nie znam się za bardzo na sesjach (IMG:http://forum.php.pl/style_emoticons/default/blink.gif) mógłby mi ktoś napisac jagby takie logowanie na sesjach miało by wyglądać??
Go to the top of the page
+Quote Post
NuLL
post
Post #13





Grupa: Zarejestrowani
Postów: 2 262
Pomógł: 21
Dołączył: 3.05.2004
Skąd: Sopot, Krakow, W-wa

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


session" title="Zobacz w manualu PHP" target="_manual <- tam jest sporo o sesjach.

Ten post edytował NuLL 3.07.2005, 18:57:33
Go to the top of the page
+Quote Post
Vanx
post
Post #14





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 3.07.2005

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


Zrobiłem tak:
plik login.php:
  1. <?php
  2.  
  3. require_once(&#092;"config.php\");
  4. require('libs/Smarty.class.php');
  5.  
  6. $user = $_POST['user'];
  7. $pass = $_POST['pass'];
  8. $log = mysql_num_rows(mysql_query(&#092;"select logins, user, pass from players where user='$user' and pass='$pass'\"));
  9.  
  10. if(!$_POST['user'] || !$_POST['pass']){
  11. print &#092;"<center>Prosze wypełnić wszystkie pola!.</center>\";
  12. }
  13.  
  14. if ($log <= 0) {
  15.  print '<table align=\"bottom\">Podałeś złe dane lub nie jesteś zarejestrowany!.</table>';
  16. } else {
  17.  
  18. $_SESSION['user'] = $user;
  19. $_SESSION['pass'] = $pass;
  20.  
  21.  
  22. $sqlQuery = mysql_query(&#092;"SELECT logins FROM players WHERE user = '$user'\");
  23. $sqlArray = mysql_fetch_array($sqlQuery);
  24.  
  25. $logins = $sqlArray['logins'] + 1;
  26. mysql_query(&#092;"update players set logins='logins' where user='$user'\");
  27. print '<table align=\"center\">
  28. <tr>
  29. <td>
  30. Zostałeś zalogowany kliknij <a href=\"index.tpl\">TUTAJ</a> 
  31. </td>
  32. </tr>
  33. </table>';
  34.  }
  35.  
  36. ?>

plik index.tpl:
  1. <?php
  2.  
  3. if (empty($_SESSION['user']) || empty($_SESSION['pass'])) {
  4. print 'cos tam';
  5. }
  6.  
  7. ?>

ale nie działa (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) co zrobiłem źle??
Go to the top of the page
+Quote Post
NuLL
post
Post #15





Grupa: Zarejestrowani
Postów: 2 262
Pomógł: 21
Dołączył: 3.05.2004
Skąd: Sopot, Krakow, W-wa

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


A session_start" title="Zobacz w manualu PHP" target="_manual :?:
Go to the top of the page
+Quote Post
Vanx
post
Post #16





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 3.07.2005

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


Dodałem
  1. <?php
  2. require_once(&#092;"config.php\");
  3. require('libs/Smarty.class.php');
  4.  
  5. $user = $_POST['user'];
  6. $pass = $_POST['pass'];
  7. $log = mysql_num_rows(mysql_query(&#092;"select logins, user, pass from players where user='$user' and pass='$pass'\"));
  8.  
  9. if(!$_POST['user'] || !$_POST['pass']){
  10. print &#092;"<center>Prosze wypełnić wszystkie pola!.</center>\";
  11. }
  12.  
  13. if ($log <= 0) {
  14. print '<table align=\"bottom\">Podałeś złe dane lub nie jesteś zarejestrowany!.</table>';
  15. } else {
  16.  
  17. $_SESSION['user'] = $user;
  18. $_SESSION['pass'] = $pass;
  19.  
  20.  
  21. $sqlQuery = mysql_query(&#092;"SELECT logins FROM players WHERE user = '$user'\");
  22. $sqlArray = mysql_fetch_array($sqlQuery);
  23.  
  24. $logins = $sqlArray['logins'] + 1;
  25. mysql_query(&#092;"update players set logins='logins' where user='$user'\");
  26. print '<table align=\"center\">
  27. <tr>
  28. <td>
  29. Zostałeś zalogowany kliknij <a href=\"index.tpl\">TUTAJ</a>
  30. </td>
  31. </tr>
  32. </table>';
  33.  }
  34.  
  35. ?>

ale też nie działa (IMG:http://forum.php.pl/style_emoticons/default/blink.gif)

Ten post edytował Vanx 6.07.2005, 10:34:05
Go to the top of the page
+Quote Post
nospor
post
Post #17





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




po pierwsze: session_start musisz tez do index.tpl wstawic.
po drugie: robisz link do index.tpl. A masz ustawione aby pliki z rozszerzeiem .tpl parsowal ci php? Inaczej to raczej to nie prawa dzialać. Chyba że ja oczymś ni wiem. Daj mu rozszerzenie php i już
Go to the top of the page
+Quote Post
Vanx
post
Post #18





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 3.07.2005

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


a jak zrobić aby po naciśnięciu na zaloguj pojawił się index.php, ale bez smarty??
Go to the top of the page
+Quote Post
nospor
post
Post #19





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




he? Czytżby tak:
  1. <a href="index.php">TUTAJ</a>

a w index.php nie używaj smarty i już
Go to the top of the page
+Quote Post
Vanx
post
Post #20





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 3.07.2005

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


jak tak dam
  1. <a href="index.php">TUTAJ</a>

to po naciśnięcu na zaloguj wyskoczy mi, Zostałeś zalogowany kliknij <a href="index.tpl">TUTAJ</a>. bo użyłem funkcji print, a jak zrobić aby od razu po naciśnięciu na zaloguj (przycisk) wyświetlił się index.php?
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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: 24.12.2025 - 14:41