Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Skrypt logowania (w szablonie)
Lirdoner
post
Post #1





Grupa: Zarejestrowani
Postów: 500
Pomógł: 1
Dołączył: 29.09.2009

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


Witam, problem mam taki

Skrypt logowania
  1. <form method="post" action="<? echo $PHP_SELF;?>" enctype="multipart/form-data">
  2. <b>Login:<b><br />
  3. <input type="text" name="login" maxlength="20" /><br />
  4. <b>Hasło:</b><br />
  5. <input type="password" name="haslo" maxlength="25"/><br /><br />
  6. <input type="submit" class="button" value="Zaloguj" style="font-size: 10pt; font-family: Tahoma; font-weight: bold" /><br /><br />
  7. </form>

  1. <?php
  2. // 1 linijka sprawdza czy jest login i haslo (jesli tego by nie bylo wyskakiwalo by nie ma takiego loginu)
  3. if (isset($_POST['login']) && isset($_POST['haslo'])){
  4. $login = mysql_real_escape_string(trim($_POST['login'])); // z loginu usuwamy spacje
  5. $haslo = md5($_POST['haslo']); //hasło kodujemy w MD5
  6. $loguj = mysql_query ("select Nick,Haslo from nauczyciele where Nick='$login' and Haslo='$haslo'");//pobranie z bazy loginu i hasła wpisanego w formularzu
  7. if(mysql_num_rows($loguj)==0)// sprawdzenie czy dany użytkownik istnieje w bazie
  8. {
  9. echo'<center> Podany login i haslo jest błędne</center>'; // jeżeli nie istnieje taki użytkownik to wyświetla błšd
  10. }
  11. else
  12. {
  13. $_SESSION['zalogowany'] = $_POST['login']; // jeżeli istnieje taki użytkownik w bazie
  14. echo "elo";
  15. }}
  16. ?>


Wszystko fajnie tylko że instukcja po zalogowaniu wykonuje się pod logowaniem, da się zrobić tak żeby po zalogowaniu usunąć formularz?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
Blame
post
Post #2





Grupa: Zarejestrowani
Postów: 678
Pomógł: 124
Dołączył: 26.09.2009

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


Formularz logowania umieszczasz w else dla tego if'a:
  1. if (isset($_POST['login']) && isset($_POST['haslo'])){
Go to the top of the page
+Quote Post
Lirdoner
post
Post #3





Grupa: Zarejestrowani
Postów: 500
Pomógł: 1
Dołączył: 29.09.2009

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


Dzięki + leci, teraz mam jeszcze jeden problem
Otóż skrypt nie pamięta, że user jest zalogowany przez co przy odświeżeniu strony znowu pokazuje się formularz, jak temu zaradzić?
Go to the top of the page
+Quote Post
Wicepsik
post
Post #4





Grupa: Zarejestrowani
Postów: 1 575
Pomógł: 299
Dołączył: 26.03.2009

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


Najlepiej zrób tak

  1. if (isset($_POST['login']) && isset($_POST['haslo'])){
  2. // twój kod z 1 posta
  3. }
  4.  
  5. if(isset($_SESSION['zalogowany']))
  6. {
  7. // formularz logowania
  8. }


Jak trzymasz formularz w pierwszej instrukcji warunkowej to po wpisaniu złych danych i wysłaniu formularza on zniknie, a pojawi się dopiero po odświeżeniu strony.



Ten post edytował Wicepsik 20.11.2009, 17:08:30
Go to the top of the page
+Quote Post
korey
post
Post #5





Grupa: Zarejestrowani
Postów: 122
Pomógł: 2
Dołączył: 14.08.2009
Skąd: Łódź

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


tez miałem z tym problem.. (IMG:style_emoticons/default/smile.gif) w pliku php ktory laduje grafike dałem na początek
  1. <?php
  2. $log = $_SESSION['login'];
  3. $pass = $_SESSION['haslo'];
  4. ?>


W skrypcie który mnie loguje ustawiłem ze gdy jestem zalogowany powstaje mi sesja.. ;p
np:
w miejscu gdzie masz "echo 'elo'; "

dopisałbym:
nylko musiałbyś dopasować sobie zmienne:
  1. $_SESSION['login'] = $log;
  2. $_SESSION['haslo'] = $pass;
Go to the top of the page
+Quote Post
Lirdoner
post
Post #6





Grupa: Zarejestrowani
Postów: 500
Pomógł: 1
Dołączył: 29.09.2009

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


Hmm... mógłby ktoś zedytować kod? Plusy rozdam po rozwiązaniu problemu (IMG:style_emoticons/default/winksmiley.jpg)
  1. <?php
  2. if (isset($_POST['login']) && isset($_POST['haslo'])){
  3. $login = mysql_real_escape_string(trim($_POST['login']));
  4. $haslo = md5($_POST['haslo']);
  5. $loguj = mysql_query ("select Nick,Haslo from nauczyciele where Nick='$login' and Haslo='$haslo'");
  6. if(mysql_num_rows($loguj)==0)
  7. {
  8. echo'<center> Podany login i haslo jest błędne<br><a href="index.php">Powrot</a></center>';
  9. }
  10. else
  11. {
  12. $_SESSION['zalogowany'] = $_POST['login'];
  13. echo "elo";
  14. }}
  15. else {
  16. echo "<form method='post' action='$PHP_SELF' enctype='multipart/form-data'>";
  17. echo "<center>";
  18. echo "<b>Login:<b><br />";
  19. echo "<input type='text' name='login' maxlength='20' /><br />";
  20. echo "<b>Hasło:</b><br />";
  21. echo "<input type='password' name='haslo' maxlength='25' /><br /><br />";
  22. echo "<input type='submit' class='button' value='Zaloguj' style='font-size: 10pt; font-family: Tahoma; font-weight: bold' />";
  23. echo "</center></form>";
  24. }
  25. ?>

Byłbym bardzo wdzięczny (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Wicepsik
post
Post #7





Grupa: Zarejestrowani
Postów: 1 575
Pomógł: 299
Dołączył: 26.03.2009

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


  1. if (isset($_POST['login']) && isset($_POST['haslo'])){
  2. $login = mysql_real_escape_string(trim($_POST['login']));
  3. $haslo = md5($_POST['haslo']);
  4. $loguj = mysql_query ("select Nick,Haslo from nauczyciele where Nick='$login' and Haslo='$haslo'");
  5. if(mysql_num_rows($loguj)==0)
  6. {
  7. echo'<center> Podany login i haslo jest błędne<br><a href="index.php">Powrot</a></center>';
  8. }
  9. else
  10. {
  11. $_SESSION['zalogowany'] = $_POST['login'];
  12. echo "elo";
  13. }
  14. }
  15.  
  16. if(isset($_SESSION['zalogowany'])){
  17.  
  18. echo '<form method="post" action="'.$_SERVER['$PHP_SELF'].'" enctype="multipart/form-data">
  19. <center>
  20. <b>Login:<b><br />
  21. <input type="text" name="login" maxlength="20" /><br />
  22. <b>Hasło:</b><br />
  23. <input type="password" name="haslo" maxlength="25" /><br /><br />
  24. <input type="submit" class="button" value="Zaloguj" style="font-size: 10pt; font-family: Tahoma; font-weight: bold" />
  25. </center></form>';
  26.  
  27. }


Ten post edytował Wicepsik 20.11.2009, 17:45:52
Go to the top of the page
+Quote Post
Lirdoner
post
Post #8





Grupa: Zarejestrowani
Postów: 500
Pomógł: 1
Dołączył: 29.09.2009

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


Wyskakuje błąd
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\PHP\zapisy.php:9) in C:\xampp\htdocs\PHP\Includes\logowanie.php on line 2
Go to the top of the page
+Quote Post
Blame
post
Post #9





Grupa: Zarejestrowani
Postów: 678
Pomógł: 124
Dołączył: 26.09.2009

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


http://phpedia.pl/wiki/Cannot_add_header_i...rs_already_sent
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: 15.09.2025 - 12:42