Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MySQL] Problem z panelem logowania
sleedz
post
Post #1





Grupa: Zarejestrowani
Postów: 43
Pomógł: 0
Dołączył: 15.01.2008

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


  1. <?
  2.  
  3. include "config.php";
  4.  
  5.  
  6. $error='';
  7.  
  8. $wynik = mysql_query("SELECT * FROM users WHERE user='$user' ")
  9. or die('Błąd zapytania');
  10. $r = mysql_fetch_assoc($wynik);
  11. echo $r['user'];
  12. echo $r['pass'];
  13.  
  14. if (isset($_GET['logoff'])) {
  15. $_SESSION=array();
  16.  
  17. if (isset($_COOKIE[session_name()])) {
  18. setcookie(session_name(), '', time()-1000, '/');
  19. }
  20.  
  21. }
  22. elseif (isset($_SESSION['valid']) && $_SESSION['valid']) {
  23. header('Location: index.php');
  24. exit();
  25. }
  26.  
  27. elseif (isset($r['user']) || isset($r['pass'])) {
  28. $user = isset($r['user']) ? $r['user'] : '';
  29. $pass = isset($r['pass']) ? $r['pass'] : '';
  30. if ( ($user == $r['user']) && ($pass == $r['pass']) ) {
  31.  
  32. $_SESSION['valid'] = 1;
  33. $_SESSION['user'] = $r['user'];
  34. header('Location: index.php');
  35. exit();
  36. } else {
  37. $error = 'Niepoprawne dane użytkownika lub hasło.';
  38. }
  39. }
  40. ?>
  41.  
  42. <html>
  43. <head>
  44. <title>Logowanie</title>
  45. <style>
  46. form { border: 1px solid black; padding: 10px }
  47. #error { color: #FF0000; font-weight: bold; }
  48. </style>
  49. </head>
  50.  
  51. <body>
  52. <? 
  53. if ($error) { echo "<p id=\"error\">{$error}</p>\n"; }
  54. ?>
  55. <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
  56. <p>Witamy na stronie (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) </p>
  57. <p>Login: <input type="test" name="user" value="<?= @$user ?>"> <br />
  58. Haslo: <input type="password" name="pass" value="<?= @$pass ?>"> </p>
  59. <p><input type="submit" value="Zaloguj" /></p>
  60. </form>
  61. </body>
  62. </html>


1. strona po zalogowaniu nie przełącza się na index.php
2. taki error: Warning: Cannot modify header information - headers already sent by (output started at E:\Programowanie\php\strona\login.php:12) in E:\Programowanie\php\strona\login.php on line 25

Nie wiem co z tym zrobić. Pomocy!
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
greenway
post
Post #2





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 30.06.2008

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


Daj na początku:
  1. <?php
  2. ?>


a na końcu:
  1. <?php
  2. ?>
Go to the top of the page
+Quote Post
TomASS
post
Post #3





Grupa: Zarejestrowani
Postów: 1 660
Pomógł: 13
Dołączył: 9.06.2004
Skąd: Wrocław i okolice

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


Przecież to głupota używać (w tym przypadku ob_start() i ob_end_flush())!

Przed HEADEREM nic nie możesz wysłać do przeglądarki - jaki to ma sens!?!?

Masz tak:
  1. <?php
  2. include "config.php";
  3.  
  4.  
  5.    $error='';
  6.    session_start();
  7.  
  8.    $wynik = mysql_query("SELECT * FROM users WHERE user='$user' ")
  9.    or die('Błąd zapytania');
  10.    $r = mysql_fetch_assoc($wynik);
  11.    echo $r['user'];
  12.    echo $r['pass'];
  13.  
  14.    if (isset($_GET['logoff'])) {
  15.        $_SESSION=array();
  16.  
  17.        if (isset($_COOKIE[session_name()])) {
  18.            setcookie(session_name(), '', time()-1000, '/');
  19.        }
  20.    
  21.        session_destroy();
  22.    }
  23.    elseif (isset($_SESSION['valid']) && $_SESSION['valid']) {
  24.        header('Locatio: index.php');
  25.        exit();
  26.    }
  27. ?>


wyświetlasz:
  1. <?php
  2. echo $r['user'];
  3.    echo $r['pass'];
  4. ?>


a później masz w warunku:
  1. <?php
  2. elseif (isset($_SESSION['valid']) && $_SESSION['valid']) {
  3.        header('Locatio: index.php');
  4.        exit();
  5.    }
  6. ?>


jaki jest sens wyświetlanie tego $r['user'] i późniejsze przełączenie na inną stronę (nawet nie zauważy się tego $r['user'], daj tak, żeby nic nie wyświetlać przed header - a wyświetlasz (linia 12 i 13)
Go to the top of the page
+Quote Post
sleedz
post
Post #4





Grupa: Zarejestrowani
Postów: 43
Pomógł: 0
Dołączył: 15.01.2008

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


  1. <?
  2.  
  3.    include "config.php";
  4.  
  5.  
  6.    $error='';
  7.    session_start();
  8.  
  9.    $wynik = mysql_query("SELECT * FROM users WHERE user='$user' ")
  10.    or die('Błąd zapytania');
  11.    $r = mysql_fetch_assoc($wynik);
  12.  
  13.    if (isset($_GET['logoff'])) {
  14.        $_SESSION=array();
  15.  
  16.        if (isset($_COOKIE[session_name()])) {
  17.            setcookie(session_name(), '', time()-1000, '/');
  18.        }
  19.    
  20.        session_destroy();
  21.    }
  22.    ?>
  23.    <?
  24.    if (isset($_SESSION['valid']) && $_SESSION['valid']) {
  25.        header('Locatio: index.php');
  26.        exit();
  27.    }
  28.    ?>
  29.    <?
  30.  
  31.    if (isset($r['user']) || isset($r['pass'])) {
  32.        $user = isset($r['user']) ? $r['user']&nbsp: '';
  33.        $pass = isset($r['pass']) ? $r['pass']&nbsp: '';
  34.        if  ( ($user == $r['user']) && ($pass == $r['pass']) )  {
  35.  
  36.            $_SESSION['valid'] = 1;
  37.            $_SESSION['user'] = $r['user'];
  38.            header('Locatio: index.php');
  39.            exit();
  40.        } else {
  41.            $error = 'Niepoprawne dane użytkownika lub hasło.';
  42.        }
  43.    }
  44.    ?>
  45.  
  46.    <html>
  47.        <head>
  48.            <title>Logowanie</title>
  49.            <style>
  50.                form { border: 1px solid black; paddin: 10px }
  51.                #error { color: #FF0000; font-weigh: bold; }
  52.                </style>
  53.        </head>
  54.  
  55.        <body>
  56.            <?
  57.                if ($error) { echo "<p id=\"error\">{$error}</p>\n"; }
  58.            ?>
  59.        <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
  60.            <p>Witamy na stronie&nbsp:P</p>
  61.            <p>Logi: <input type="test" name="user" value="<?= @$user ?>"> <br />
  62.            Haslo: <input type="password" name="pass" value="<?= @$pass ?>"> </p>
  63.            <p><input type="submit" value="Zaloguj" /></p>
  64.        </form>
  65.        </body>
  66.    </html>


i teraz mam taki błąd:
Warning: Cannot modify header information - headers already sent by (output started at E:\Programowanie\php\strona\login.php:23) in E:\Programowanie\php\strona\login.php on line 38

Cytat
jaki jest sens wyświetlanie tego $r['user'] i późniejsze przełączenie na inną stronę (nawet nie zauważy się tego $r['user'], daj tak, żeby nic nie wyświetlać przed header - a wyświetlasz (linia 12 i 13)


W sumie to nie ma sensu. chiałem sprawdzić czy wogóle czyta z bazy i nie usunołem tego
Go to the top of the page
+Quote Post
ChrisB
post
Post #5





Grupa: Zarejestrowani
Postów: 73
Pomógł: 4
Dołączył: 13.01.2004
Skąd: Bielsko-Biała

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


  1. ?>
  2.   <?
  3. ?>


usuń to w 23 linijce, plus pisze się location nie locatio
edit
29 od razu też

Ten post edytował ChrisB 6.09.2008, 17:54:24
Go to the top of the page
+Quote Post
sleedz
post
Post #6





Grupa: Zarejestrowani
Postów: 43
Pomógł: 0
Dołączył: 15.01.2008

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


ok. wszystko działa tylko czemu mi errora nie wyświetla?
Go to the top of the page
+Quote Post
webdice
post
Post #7


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




Temat był przerabiany masę razy na forum, wystarczy poszukać.

Zamykam.
Go to the top of the page
+Quote Post

Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 4.10.2025 - 17:12