Jump to content

Autentificarea Utilizatorilor


Recommended Posts

//Similar formularului de inregistrare, acest fisier verifica existenta informatiilor, retine username-ul si parola in doua variabile, apoi executa un query SELECT pentru a verifica daca sunt valide.




//  verifica daca exista date transmise

if ($_POST['login_username'] != "" && $_POST['login_password'] != '') {

    // preia datele din formular

    $username = $_POST['login_username'];

    $password = md5($_POST['login_password']);

    // formeaza si executa query-ul de select din baza de date

    $query = "SELECT * FROM `users` WHERE `Username` = '".$username."' AND `Password` = '".$password."'";

    $result = mysql_query($query) or die ( "Error : ". mysql_error() );

    // verifica daca interogarea MySQL a gasit date valide

    if ($result || mysql_num_rows($result) < 1) {

        // daca nu, afiseaza un mesaj de eroare

        echo "Datele introduse sunt incorecte<br>

            Click <a href='index.php'>aici</a> pentru a reveni la pagina de login";

    } else {

        // salveaza username-ul si parola in sesiune

        $_SESSION['username'] = $username;

        $_SESSION['password'] = $password;

        // afiseaza un mesaj de succes

        echo "Autentificarea a fost efectuata cu succes.";




//In caz de succes, numele de utilizator si parola sunt memorate in sesiune. 

//Acest pas este necesar deoarece permite verificarea unui utilizator utilizand datele din sesiune, fara a-i cere sa introduca de fiecare data numele de utilizator si parola. 

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.