Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Problem z sesją
Forum PHP.pl > Forum > PHP
sleedz
Mam dziwny problem z sesją...

Mianowicie:
Kiedy jestem wylogowany okno wygląda tak:


Po zalogowaniu się:


A oto kod żródłowy:

index.php
  1. <?
  2.    include "config.php";
  3.    include "style.css";
  4.    echo '<center><table width="1024" border="1" height="200">
  5.      <tr>
  6.        <td>&nbsp;</td>
  7.      </tr>
  8.    </table>';
  9.    
  10.    
  11.    if (!(isset($_SESSION['valid']) && $_SESSION['valid'])) {
  12.        include 'login.php';
  13.        exit();
  14.    } else {
  15.        include 'view.php';
  16.    }
  17.  
  18. ?>
  19.  
  20. <html>
  21.    <head>
  22.        <title>Strona</title>
  23.    </head>
  24.  
  25.    <body>
  26.  
  27. </body>
  28. </html>


login.php
  1. <?
  2.  
  3.    include "config.php";
  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.  
  12.    if (isset($_GET['logoff'])) {
  13.        $_SESSION=array();
  14.  
  15.        if (isset($_COOKIE[session_name()])) {
  16.            setcookie(session_name(), '', time()-1000, '/');
  17.        }
  18.    
  19.        session_destroy();
  20.    }
  21.    
  22.    
  23.    elseif (isset($_SESSION['valid']) && $_SESSION['valid']) {
  24.        header('Locatio: index.php');
  25.        exit();
  26.    }
  27.    
  28.    
  29.  
  30.    elseif (isset($r['user']) || isset($r['pass'])) {
  31.        $user = isset($r['user']) ? $r['user']&nbsp: '';
  32.        $pass = isset($r['pass']) ? $r['pass']&nbsp: '';
  33.        if  ( ($user == $r['user']) && ($pass == $r['pass']) )  {
  34.  
  35.            $_SESSION['valid'] = 1;
  36.            $_SESSION['user'] = $r['user'];
  37.            header('Locatio: index.php');
  38.            exit();
  39.        } else {
  40.            $error = 'Niepoprawne dane użytkownika lub hasło.';
  41.        }
  42.    }
  43.    ?>
  44.    <?
  45.        include "style.css";
  46.    ?>
  47.  
  48.    <html>
  49.        <head>
  50.            <title>Logowanie</title>
  51.  
  52.        </head>
  53.  
  54.        <body>
  55.            <?
  56.                if ($error) { echo "<p id=\"error\">{$error}</p>\n"; }
  57.            ?>
  58.  
  59.        <table width="235">
  60.        
  61.  <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
  62.            <td colspan="3">Zaloguj się&nbsp:P</td>
  63.            <tr>
  64.            <td>Logi: </td><td><input type="test" name="user" class="pole" maxlength="12" value="<?= @$user ?>"></td> <br />
  65.            </tr><tr>
  66.            <td>Haslo: </td><td><input type="password" name="pass" class="pole" maxlength="12" value="<?= @$pass ?>"> </td>
  67.            </tr><tr>
  68.            <td valign="top"><input type="submit" value="Zaloguj" class="przycisk" /></form></td>
  69.            <td ><form action="register.php" method="post"><input type="submit" value="Rejestracja" class="przycisk" /></form>
  70.            </tr>
  71.            <tr height="67"></tr>
  72.            </table>
  73.        </form>
  74.            
  75.        </body>
  76.    </html>


view.php
  1. <?
  2.    include "config.php";
  3.  
  4.    session_start();
  5.    if (!(isset($_SESSION['valid']) && $_SESSION['valid'])) {
  6.        header('Locatio: login.php');
  7.        exit();
  8.    }
  9.  
  10.    $wynik = mysql_query("SELECT * FROM users WHERE user='$user' ")
  11.    or die('Blad zapytania');
  12.    $r = mysql_fetch_assoc($wynik);
  13.    
  14. ?>
  15. <?
  16.    include "style.css";
  17.    
  18. ?>
  19.  
  20. <html>
  21.    <head>
  22.        <title>Elo</title>
  23.    </head>
  24.  
  25.    <body>
  26.    <br>
  27.    <table width="235">
  28.        <tr>
  29.            <td>
  30.                Witaj!<br>
  31.                Zalogowales sie jako:  <? echo $r[nick]; ?>            
  32.            </td>
  33.        </tr>
  34.        <tr>
  35.            <td>
  36.                 <a href="login.php?logoff=true"> Logout</a></td>
  37.        </tr>
  38.        <tr height="112"></tr>
  39.    </table>
  40.                
  41.    
  42.    </body>
  43. </html>
webdice
Temat przerabiany masę razy na tym forum. Wpisałeś chociaż treść błędu w wyszukiwarce? Pozwól że odpowiem za Ciebie - NIE.

Zamykam.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.