Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL]Logowanie + sesje + mysql, problem z logowaniem
einstein
post
Post #1





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

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


Witam napisałem skrypt logowanie oparty na mysql i na sesjach lecz się nie uruchamia(nie wywala błędów). Oto on:
Formularz logowania:
Kod
<?PHP
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    session_start();
    
    if(isset($_POST['username']) && isset($_POST['password']))
    {
        $username = $_POST['username'];
        $password = $_POST['password'];
        
        $db_connect = new mysqli('localhost' , 'usa' , 'haslo', 'engtest');
        
        if(mysqli_connect_errno())
        {
            echo 'POŁĄCZENIE Z BAZĄ DANYCH NIE POWIODŁO SIE: '.mysqli_connect_error();
            exit();
        }
        
        $zapytanie = 'select * from member'
                     ." where username='$username' "
                     ." and password=sha1('$password')";
                    
        $result = $db_connect->query($zapytanie);
        if($result->num_rows > 0)
        {
            $_SESSION['prawid_uzyt'] =$username;
        }
        $db_connect->close();
        
    }
    
    ?>
    
    <HTML>
    <BODY>
    <BR><BR><BR><BR><BR><BR><BR><BR><BR>
    <?php
    
    if(isset($_SESSION['prawid_uzyt']))
    {
        echo 'Użytkownik zalogowany jako: '.$_SESSION['prawid_uzyt'];
    }
    
    else
    {
        if(isset($username))
        {
            echo 'Zalogowanie niemożliwe';
        }
        
        else
        {
            echo 'Użytkownik niezalogowany
    ';
        }
    }
    
    
      echo '<form method="post" action ="member.php">';
      
      echo '<center><TABLE frame="vsides" width = 216>';
      echo '<TR><TD><center>';
      echo '&nbsp;<IMG SRC="img/log.gif" WIDTH="199" HEIGHT="28" BORDER="0" ALT="LOGOWANIE">&nbsp;';
      echo '</center></TD>';
      
      echo '<TABLE frame="vsides" width = 216>';
      echo '<TR><TD><B><center>LOGIN:</center> </B></TD>';
      echo '<TD><B><center><input type="text" name="username" size = 10></center> </B></TD></TR>';
      echo '<TR><TD><B><center>HASŁO:</center> </B></TD>';
      echo '<TD><center><INPUT TYPE="password" NAME="password" size = 10></center></TD></TR>';
      echo '</center></TABLE></form>';
      echo'<INPUT TYPE="submit" value="Loguj">';
    ?>
      
     </BODY>
    </HTML>


Skrypt sprawdzający sesje:
Kod
<?php
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  
  session_start();
  if(isset($_SESSION['prawid_uzyt']))
  {
      header("Location: http://localhost/.../.../admin_pan.html");    
  }
  else
  {
      header("Location: http://localhost/.../.../logon_root.php");
  }
  ?>


Baza:
Kod
create database engtest;
  use member;
  
  create table member
  (username varchar(64) not NULL,
  haslo varchar(64) not null,
  mail varchar(100) not null,
  primary key(username)
  );
  
  insert into member values
  ('jacek' , sha1('jacek') , 'mail');

Sytuacja wygląda tak ze wpisuje login i hasło i ponownie zostaje przelogowany do formularz logowania. Nie wiem co mam zrobić. Siedziałem nad tym kodem i nie znalazłem żadnego błędu możne macie jakieś sugestie?

Bede naprawdę wdzięczny za pomoc. Pozdrawiam.

Ten post edytował einstein 29.09.2008, 19:05:05
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
einstein
post
Post #2





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

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


W pliku konfiguracyjnym php.ini mam coś takiego:
Kod
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; error_reporting is a bit-field.  Or each number up to get desired error
; reporting level
; E_ALL             - All errors and warnings (doesn't include E_STRICT)
; E_ERROR           - fatal run-time errors
; E_WARNING         - run-time warnings (non-fatal errors)
; E_PARSE           - compile-time parse errors
; E_NOTICE          - run-time notices (these are warnings which often result
;                     from a bug in your code, but it's possible that it was
;                     intentional (e.g., using an uninitialized variable and
;                     relying on the fact it's automatically initialized to an
;                     empty string)
; E_STRICT            - run-time notices, enable to have PHP suggest changes
;                     to your code which will ensure the best interoperability
;                     and forward compatibility of your code
; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's
;                     initial startup
; E_COMPILE_ERROR   - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR      - user-generated error message
; E_USER_WARNING    - user-generated warning message
; E_USER_NOTICE     - user-generated notice message


Wiec wygląda na to że wszystko jest ustawione ok. Co teraz?
Go to the top of the page
+Quote Post

Posty w temacie


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.10.2025 - 05:16