IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

authentification d'un utilisateur en PHP


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut authentification d'un utilisateur en PHP
    Bonjour tout le monde,
    J'essaie de réaliser une page d'authentification en PHP.
    J'ai développé l'interface graphique en CSS et maintenant j'essaie d'intégrer un fichier en PHP.

    La partie concernée de ma pahe HTML est la suivante:
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    <!-- page "login in" -->
    <div id="login" class="animate form">
     
      <form  action="members.php" autocomplete="on">  <!-- appel du fichier members.php -->
          <h1>Log in</h1> 
          <p> 
             <label for="username" class="uname" data-icon="u" > Username </label>
             <input id="username" name="username" required="required" type="text" placeholder="example  mymail@mail.com"/>
          </p>
     
          <p> 
             <label for="password" class="youpasswd" data-icon="p"> Password </label>
             <input id="password" name="password" required="required" type="password" placeholder="example mypassword"/> 
          </p>
     
          <p class="keeplogin"> 
    	 <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> 
    	 <label for="loginkeeping">Keep me logged in</label>
          </p>
     
          <p class="login button"> 
          <input type="submit" value="Login" /> 
          </p>
     
          <p class="change_link">  Not a member yet ?
          <a href="#toregister" class="to_register">Register</a>
          </p>
       </form>
    </div>
    le fichier qui assure la connexion à la base et la vérification des données est members.php, le contenu est le suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
     
    <?php
     
    //STEP 1 Connect To Database
    $connect = mysql_connect('localhost','root','Orange2424');
    if (!$connect)
    {
    die("MySQL could not connect!");
    }
     
    $DB = mysql_select_db('OrangeTunisie');
     
    if(!$DB)
    {
    die("MySQL could not select Database!");
    }
     
    //STEP 2 Declare Variables
     
    $Name = $_POST['username'];
    $Pass = $_POST['password'];
    $Query = mysql_query("SELECT * FROM Authentication WHERE Username='$Name' AND Password='$Pass'");
    $NumRows = mysql_num_rows($Query);
    $_SESSION['username'] = $Name;
    $_SESSION['password'] = $Pass;
     
    //STEP 3 Check to See If User Entered All Of The Information
     
    if(empty($_SESSION['username']) || empty($_SESSION['password']))
    {
    die("Go back and login before you visit this page!");
    }
     
    if($Name && $Pass == "")
    {
    die("Please enter in a name and password!");
    }
     
    if($Name == "")
    {
    die("Please enter your name!" . "</br>");
    }
     
    if($Pass == "")
    {
    die("Please enter a password!");
    echo "</br>";
    }
     
    //STEP 4 Check Username And Password With The MySQL Database
     
    if($NumRows != 0)
    {
    while($Row = mysql_fetch_assoc($Query))
    {
    $Database_Name = $Row['username'];
    $Database_Pass = $Row['password'];
    }
    }
    else
    {
    die("Incorrect Username or Password!");
    }
     
    if($Name == $Database_Name && $Pass == $Database_Pass)
    {
    // If The User Makes It Here Then That Means He Logged In Successfully
    echo "Hello " . $_SESSION['username'] . "!";
    }
     
    ?>
    <html>
    <body>
    <p>Here is where you can put information for the user to see when he logs on. (Anything inside these html tags!)</p>
    </body>
    </html>
    mais je n'arrive pas à le faire fonctionner j'ai toujours l'erreur "Go back and login before you visit this page!"!!

    merci d'avance pour votre aide

  2. #2
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Septembre 2009
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Septembre 2009
    Messages : 875
    Points : 1 313
    Points
    1 313
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    $Name = $_POST['username'];
    $Pass = $_POST['password'];
    $Query = mysql_query("SELECT * FROM Authentication WHERE Username='$Name' AND Password='$Pass'");
    $NumRows = mysql_num_rows($Query);
    $_SESSION['username'] = $Name;
    $_SESSION['password'] = $Pass;
    Tu stockes tes mots de passe en clair dans la base?

    Tu utilises mal la session:
    Tout d'abord je te déconseille fortement de mettre le mot de passe en session, il est plus sécurisé de mettre seulement un booléen (exemple is_authenticated) a true si le login a réussi.
    Deuxièmement, il ne faut mettre des variables en session que si le login a réussi.

    Dernier point, l'erreur actuelle vient du fait de cette requete:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $Query = mysql_query("SELECT * FROM Authentication WHERE Username='$Name' AND Password='$Pass'");
    lorsqu'on vérifie un login, on récupère l'utilisateur qu'avec son login et non le couple login/mdp


    je te laisse essayer de corriger ton script, si tu bloques encore longtemps je cracherai du code

  3. #3
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    Merci beaucoup, je suis nouvelle en PHP, avant je n'utilisais que java pour ce genre de manipulation.
    Mais j'aimerai faire un maximum d'effort pour corriger le problème toute seule. Je te consulterai si je n'y arrive pas

  4. #4
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    En fait, j'i un peu testé quelques code mais je me rend compte que l'erreur ne vient pas de la requête SQL mais de cette ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $Name = $_POST['username'];
    la variable $Name est vide, le contenu de la zone de texte "Username" n'est pas récupéré mais je ne comprend pas pourquoi

  5. #5
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 250
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 250
    Points : 8 538
    Points
    8 538
    Billets dans le blog
    17
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <form  action="members.php" autocomplete="on">  // appel du fichier members.php
    A priori le formulaire n'est pas soumis en POST. Tu ne peux donc pas récupérer username avec $_POST.

  6. #6
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    j'ai essayé d'ajouter la methode "post" mais ça n'a rien changé:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <form  action="members.php" autocomplete="on" method="post">

  7. #7
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 250
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 250
    Points : 8 538
    Points
    8 538
    Billets dans le blog
    17
    Par défaut
    Fais un print_r($_POST) dans la page de traitement du formulaire pour voir ce que tu y reçois.

  8. #8
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    je reçoi ceci:

  9. #9
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 250
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 250
    Points : 8 538
    Points
    8 538
    Billets dans le blog
    17
    Par défaut
    Donc tu ne reçois pas de requête POST.

    Montre tes scripts mis à jour.

  10. #10
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    mon script HTML est le suivant:
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    <form  action="members.php" autocomplete="on" method="post"> 
          <h1>Log in</h1> 
          <p> 
             <label for="username" class="uname" data-icon="u" > Username </label>
             <input id="username" name="username" required="required" type="text" placeholder="example  mymail@mail.com"/>
          </p>
     
          <p> 
             <label for="password" class="youpasswd" data-icon="p"> Password </label>
             <input id="password" name="password" required="required" type="password" placeholder="example mypassword"/> 
          </p>
     
          <p class="keeplogin"> 
    	 <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> 
    	 <label for="loginkeeping">Keep me logged in</label>
          </p>
     
          <p class="login button"> 
          <input type="submit" value="Login" /> 
          </p>
     
          <p class="change_link">  Not a member yet ?
          <a href="#toregister" class="to_register">Register</a>
          </p>
       </form>

    et le script PHP est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    <?php
     
    //STEP 1 Connect To Database
    $connect = mysql_connect('localhost','root','Orange2424');
    if (!$connect)
    {
    die("MySQL could not connect!");
    }
     
    $DB = mysql_select_db('OrangeTunisie');
     
    if(!$DB)
    {
    die("MySQL could not select Database!");
    }
     
    //STEP 2 Declare Variables
     
    $Name = $_POST['username'];
    $Pass = $_POST['password'];
    $Query = mysql_query("SELECT * FROM Authentication WHERE Username='$Name' AND Password='$Pass'");
    $NumRows = mysql_num_rows($Query);
    $_SESSION['username'] = $Name;
    $_SESSION['password'] = $Pass;
     
    //STEP 3 Check to See If User Entered All Of The Information
     
    if(empty($_SESSION['username']) || empty($_SESSION['password']))
    {
    print_r($_POST);
    die("Go back and login before you visit this page!");
    }
     
    if($Name && $Pass == "")
    {
    die("Please enter in a name and password!");
    }
     
    if($Name == "")
    {
    die("Please enter your name!" . "</br>");
    }
     
    if($Pass == "")
    {
    die("Please enter a password!");
    echo "</br>";
    }
     
    //STEP 4 Check Username And Password With The MySQL Database
     
    if($NumRows != 0)
    {
    while($Row = mysql_fetch_assoc($Query))
    {
    $Database_Name = $Row['username'];
    $Database_Pass = $Row['password'];
    }
    }
    else
    {
    die("Incorrect Username or Password!");
    }
     
    if($Name == $Database_Name && $Pass == $Database_Pass)
    {
    // If The User Makes It Here Then That Means He Logged In Successfully
    echo "Hello " . $_SESSION['username'] . "!";
    }
     
    ?>
    <html>
    <body>
    <p>Here is where you can put information for the user to see when he logs on. (Anything inside these html tags!)</p>
    </body>
    </html>
    merci pour votre aide

  11. #11
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 250
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 250
    Points : 8 538
    Points
    8 538
    Billets dans le blog
    17
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if(empty($_SESSION['username']) || empty($_SESSION['password']))
    {
    print_r($_POST);
    Ben là forcément y aura pas grand chose dans $_POST...

    Met le print_r( ) en haut de page.

  12. #12
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    ça ne change rien toujours le même résultat!

  13. #13
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 250
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 250
    Points : 8 538
    Points
    8 538
    Billets dans le blog
    17
    Par défaut
    Citation Envoyé par supcomingenieur Voir le message
    ça ne change rien toujours le même résultat!
    Montre les scripts mis à jour stp.

  14. #14
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    je n'ai pas réalisé de grand changements, j'ai juste fait sorti ke r_print($post)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    <?php
    
    //STEP 1 Connect To Database
    $connect = mysql_connect('localhost','root','Orange2424');
    if (!$connect)
    {
    die("MySQL could not connect!");
    }
    
    $DB = mysql_select_db('OrangeTunisie');
    
    if(!$DB)
    {
    die("MySQL could not select Database!");
    }
    
    //STEP 2 Declare Variables
    
    $Name = $_POST['username'];
    $Pass = $_POST['password'];
    $Query = mysql_query("SELECT * FROM Authentication WHERE Username='$Name' AND Password='$Pass'");
    $NumRows = mysql_num_rows($Query);
    $_SESSION['username'] = $Name;
    $_SESSION['password'] = $Pass;
    print_r($_POST);
    
    //STEP 3 Check to See If User Entered All Of The Information
    
    if(empty($_SESSION['username']) || empty($_SESSION['password']))
    {
    
    die("Go back and login before you visit this page!");
    }
    
    if($Name && $Pass == "")
    {
    die("Please enter in a name and password!");
    }
    
    if($Name == "")
    {
    die("Please enter your name!" . "</br>");
    }
    
    if($Pass == "")
    {
    die("Please enter a password!");
    echo "</br>";
    }
    
    //STEP 4 Check Username And Password With The MySQL Database
    
    if($NumRows != 0)
    {
    while($Row = mysql_fetch_assoc($Query))
    {
    $Database_Name = $Row['username'];
    $Database_Pass = $Row['password'];
    }
    }
    else
    {
    die("Incorrect Username or Password!");
    }
    
    if($Name == $Database_Name && $Pass == $Database_Pass)
    {
    // If The User Makes It Here Then That Means He Logged In Successfully
    echo "Hello " . $_SESSION['username'] . "!";
    }
    
    ?>
    <html>
    <body>
    <p>Here is where you can put information for the user to see when he logs on. (Anything inside these html tags!)</p>
    </body>
    </html>

  15. #15
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 250
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 250
    Points : 8 538
    Points
    8 538
    Billets dans le blog
    17
    Par défaut
    Ce dernier script collé s'appelle bien members.php ?

    Si oui tu ne reçois pas le POST. Fais un print_r($_REQUEST).

  16. #16
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    je n'ai pas réalisé de grand changements, j'ai juste fait sorti ke r_print($post)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    <?php
    
    //STEP 1 Connect To Database
    $connect = mysql_connect('localhost','root','Orange2424');
    if (!$connect)
    {
    die("MySQL could not connect!");
    }
    
    $DB = mysql_select_db('OrangeTunisie');
    
    if(!$DB)
    {
    die("MySQL could not select Database!");
    }
    
    //STEP 2 Declare Variables
    
    $Name = $_POST['username'];
    $Pass = $_POST['password'];
    $Query = mysql_query("SELECT * FROM Authentication WHERE Username='$Name' AND Password='$Pass'");
    $NumRows = mysql_num_rows($Query);
    $_SESSION['username'] = $Name;
    $_SESSION['password'] = $Pass;
    print_r($_POST);
    
    //STEP 3 Check to See If User Entered All Of The Information
    
    if(empty($_SESSION['username']) || empty($_SESSION['password']))
    {
    
    die("Go back and login before you visit this page!");
    }
    
    if($Name && $Pass == "")
    {
    die("Please enter in a name and password!");
    }
    
    if($Name == "")
    {
    die("Please enter your name!" . "</br>");
    }
    
    if($Pass == "")
    {
    die("Please enter a password!");
    echo "</br>";
    }
    
    //STEP 4 Check Username And Password With The MySQL Database
    
    if($NumRows != 0)
    {
    while($Row = mysql_fetch_assoc($Query))
    {
    $Database_Name = $Row['username'];
    $Database_Pass = $Row['password'];
    }
    }
    else
    {
    die("Incorrect Username or Password!");
    }
    
    if($Name == $Database_Name && $Pass == $Database_Pass)
    {
    // If The User Makes It Here Then That Means He Logged In Successfully
    echo "Hello " . $_SESSION['username'] . "!";
    }
    
    ?>
    <html>
    <body>
    <p>Here is where you can put information for the user to see when he logs on. (Anything inside these html tags!)</p>
    </body>
    </html>

  17. #17
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 250
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 250
    Points : 8 538
    Points
    8 538
    Billets dans le blog
    17
    Par défaut
    Ce dernier script collé s'appelle bien members.php ?

    Si oui tu ne reçois pas le POST. Fais un print_r($_REQUEST).

  18. #18
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    Je ne sais pas ce qui se passe avec ce code mais clairement il n'est pas optimisé. et présente plein de problème. J'en ai trouvé un autre et ça fonctionne très bien. le voici:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
    <?php
    //ouvrir une connexion vers mysql 
     
    $connect = mysql_connect('localhost','root','Orange2424');
    if (!$connect)
    {
    die("MySQL could not connect!");
    }
     
    $DB = mysql_select_db('OrangeTunisie');
     
    if(!$DB)
    {
    die("MySQL could not select Database!");
    }
     
    if(isset($_POST) && !empty($_POST['username']) && !empty($_POST['password'])) {
    extract($_POST);
    // on recupère le password de la table qui correspond au login du visiteur
    $sql = "select Password from Authentication where Username='".$_POST['username']."'";
    $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
     
    $data = mysql_fetch_assoc($req);
     
    if($data['Password'] != $_POST['password']) {
    echo '<p> Invalid Username or Password. Try again </p>';
    include('auth.php'); // On inclut le formulaire d'identification
    exit;
    }
    else {
    session_start();
    $_SESSION['username'] = $_POST['username'];
    include('IHM.php');
    }
    }
    else {
    echo '<p> Please fill out all the fields.</p>';
    include('auth.php'); // On inclut le formulaire d'identification
    exit;
    }
     
    ?>
     
    <?
    session_start();
     
    /*
    si la variable de session login n'existe pas cela siginifie que le visiteur
    n'a pas de session ouverte, il n'est donc pas logué ni autorisé à
    acceder à l'espace membres
    */
    if(!isset($_SESSION['username'])) {
    echo 'Your are not allowed to access this page. Please register';
    include('auth.php');
    exit;
    }
    ?>

  19. #19
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    324
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Août 2012
    Messages : 324
    Points : 13
    Points
    13
    Par défaut
    J'ai un petit problème concernant l'affichage des message d'erreur.
    Je voudrais que ces messages soient affichés dans la page courante.Pour ceci j'utilise la syntaxe suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    if($Password != $Re_Password)
    {
    echo '<p> Passwords do not match</p>';
    include('auth.php'); // On inclut le formulaire d'identification
    exit;
    }
    le problème est que le fichier auth.php comporte deux pages html une page "log in" et une page "sign up". lorsque je suis dans la section "sign up", mes mesages d'erreurs s'affiches dans la section "log in". Je ne sais pas comment réfénrencer la page courant.

  20. #20
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 250
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 250
    Points : 8 538
    Points
    8 538
    Billets dans le blog
    17
    Par défaut
    Tu ne peux pas procéder de la sorte.

    Si tu veux afficher les messages d'erreur sur la page du formulaire alors le plus simple est de traiter le formulaire sur la même page que le formulaire.

Discussions similaires

  1. [MySQL] calcul de temps passé d'un utilisateur en php
    Par sitti dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 11/05/2007, 18h04
  2. [Authentification Realm] Infos utilisateur et redirection
    Par mamiberkof dans le forum Servlets/JSP
    Réponses: 5
    Dernier message: 22/04/2006, 22h16
  3. [Sécurité] Quota d'utilisateur, htaccess/php ?
    Par Dnegel dans le forum Langage
    Réponses: 1
    Dernier message: 31/03/2006, 14h39
  4. [LDAP] Authentification d'un utilisateur
    Par toctof dans le forum Sécurité
    Réponses: 7
    Dernier message: 13/12/2005, 18h21
  5. [Calendrier] Multi-utilisateurs en php avec les ACL
    Par moabomotal dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 5
    Dernier message: 06/12/2005, 17h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo