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

PHP & Base de données Discussion :

Authentification dans une session


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Janvier 2008
    Messages : 51
    Par défaut Authentification dans une session
    bonjour tout le monde;
    je travail actuellement sur un site web en php/mysql.
    j'essai de faire une zone membre pour que les users se connectent a d'autre page.
    je travail sur deux pages:
    membre.php (contient deux zone de texts et bouton)
    index.php (page principale)
    jai inseré la page menbre dans la page index.
    le code de la page membre 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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    <? 
    session_start();
    $zm=$_SESSION['zm'];
     
    if(empty($zm))
    {
    ?>
    <CENTER>
      <table width="100" height="50" border="0" cellpadding="0" cellspacing="0">
      <form action="index.php" method="POST" name="membres" target="_top">
      <input type="hidden" name="p" value="111" />
      <input name="log" type="hidden" value="log">
        <tr> 
            <td height="20"><img src="images/login.gif"></td>
        </tr>
        <tr> 
            <td align="right"><font size="1">
              <input name="login" type="text" id="login" size="15" maxlength="15">
              </font></td>
        </tr>
        <tr> 
            <td height="20"><img src="images/password.gif" width="69" height="10"></td>
        </tr>
        <tr> 
            <td align="right">
              <input name="pass" type="password" id="pass" size="15" maxlength="15">
            </td>
        </tr>
        <tr> 
          <td height="35" align="right"><input name="ok" type="submit" value="Connexion"></td>
        </tr>
     
    	    <tr> 
            <td align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Mot de passe oublié</font></td>
        </tr>
    	    <tr> 
            <td align="left"><a href="./?p=11"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Nouveau compte</font></a></td>
        </tr>
    	</form>
      </table>
    <? } else {?>
    <table width="10%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td>&nbsp;</td>
        <td>Compte : </td>
      </tr>
      <tr> 
        <td>&nbsp;</td>
        <td><?PHP		include("db.php");
     
     
    				$connection_r=mysql_connect($my_host,$my_usr,$my_pass);
    				mysql_select_db($my_db,$connection_r);
    				if(isset($_POST) && !empty($_POST['login']) && !empty($_POST['pass'])) {
    				extract($_POST);
    				 $sql = "select utilisateur_password from dt_utilisateur where utilisateur_login='".$login."'";
    				$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
    			    $data = mysql_fetch_assoc($req);
    				if($data['utilisateur_password'] != $pass) {
    				echo '<p>Mauvais login / password. Merci de recommencer</p>';
    				include('index.php'); // On inclut le formulaire d'identification
    				exit;
    				} 
    				else {
    				session_start();
    				$_SESSION['login'] = $login;
     
    				echo 'Vous etes bien logué';
    				include('default.php');
     
    					}   
    				}
    				else {
    				echo '<p>Vous avez oublié de remplir un champ.</p>';
    				include('index.php'); // On inclut le formulaire d'identification
    				exit;
    					}
     
     
    				?>
          <font color="#639ACE"><? print("$row_s[1] $row_s[2]"); ?></font></td>
      </tr>
        <tr> 
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr> 
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr> 
        <td>&nbsp;</td>
        <td><div align="right"><a href="./?p=13" target="_parent"><img src="images/deconnexion.gif" border="0"></a></div></td>
      </tr>
    </table>
    <? }?>
    </CENTER>

    le code de page index 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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
     
    <?PHP
    session_start();
    if(isset($_POST["variable"])) $variable=$_POST["variable"];
    echo $_session['login'];
    if(!isset($_POST["p"]))  $p=$_POST["p"];
     
     
    					if ($page == 13) {unset($_SESSION['zm']);$page = 0;}
     
    					$psi=$_REQUEST["PHPSESSID"];
     
    					$ll=$_REQUEST["login"];
     
    					$pp=$_REQUEST["pass"];
     
    					$accepte=0;
    					if($p=='111'){
    						$pp=md5($pp);
     
    						include("db.php");
     
    						$connection_login=mysql_connect($my_host,$my_usr,$my_pass)
    						or die ("Connexion au serveur impossible") ;
    ;
    						mysql_select_db($my_db,$connection_login)
    						or die ("Sélection de la base de données impossible");
    						$requete_login="SELECT * from dt_utilisateur WHERE utilisateur_login='$ll' and utilisateur_password='$pp' and utilisateur_active='1'";
    						$resultat_login=mysql_query($requete_login,$connection_login);
    						$row_login=mysql_fetch_row($resultat_login);
    						if ($row_login)
    							{
    							$_SESSION['login'] = $ll;
    							$_SESSION['pass']   = $pp;
    							$_SESSION['ip'] = $REMOTE_ADDR;
    							$_SESSION['zm']   = $row_login[0];
    							$_SESSION['droits']   = $row_login[4];
    							$_SESSION['id']   = $row_login[0];
    							// Fonctionne si le cookie a été accepté
    							$psi=session_id();
    							$accepte=1;
    							}
    							else {
    									print("<font color='red'>Utilisateur non disponnible ou non validé ! </font><br>Si votre compte n'a pas été validé, contactez l'administrateur au 11429");
    									$accepte=0;
    								}
    						mysql_close(); 
    		}
     
    if ($p==13) {unset($_SESSION['zm']); $page=0;}
     
    function test_cle($cle) {
    include("db.php");
    	$id=$_SESSION['id'];
    	$req="SELECT * from dt_droits where drt_user='$id' AND drt_cle='$cle'";
    	$conn=mysql_connect($my_host,$my_usr,$my_pass);
    	mysql_select_db($my_db,$conn);
    	$res=mysql_query($req,$conn);
    	$r=mysql_num_rows($res);
    	return $r;
    }
    ?>
     
    <script language="JavaScript" type="text/javascript">
    var popUpWin=0;
     
    function popUpWindow(URLStr, left, top, width, height)
     
    {
     
      if(popUpWin)
     
      {
     
        if(!popUpWin.closed) popUpWin.close();
     
      }
     
      popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
     
    }
    </script>
    <html>
    <head>
    <title>DGSN/CAB/DT</title>
    <meta http-equiv="Content-Type" content="text/html;">
    <!-- Fireworks MX Dreamweaver MX target.  Created Mon Mar 06 20:11:06 GMT+0000 (Greenwich) 2006-->
    </head>
    <body bgcolor="#ffffff">
    <center>
      <table border="0" cellpadding="0" cellspacing="0" width="900">
        <!-- fwtable fwsrc="CHOIX3.png" fwbase="index.gif" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
        <tr> 
          <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="5" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="79" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="68" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="7" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="26" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="99" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="110" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="168" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="100" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="235" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="7"><img name="r1_c1" src="images/r1_c1.gif" width="285" height="73" border="0" alt=""></td>
          <td colspan="6" align="right" valign="top" background="images/r1_c8.gif"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif"><?=date("Y-m-d")?><br><br>
          Problèmes, remarques et suggestions : <a href="javascript:popUpWindow('sugg.php', '100', '100', '500', '350')"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">ICI</font></a> </font></strong></td>
          <td><img src="images/spacer.gif" width="1" height="73" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="3"><a href="./"><img name="r2_c1" src="images/r2_c1.gif" width="85" height="35" border="0" alt=""></a></td>
          <td colspan="3"><img name="r2_c4" src="images/r2_c4.gif" width="101" height="35" border="0" alt=""></td>
          <td><a href="./?p=hd"><img name="r2_c7" src="images/r2_c7.gif" width="99" height="35" border="0" alt=""></a></td>
          <td><img name="r2_c8" src="images/r2_c8.gif" width="110" height="35" border="0" alt=""></td>
          <td><img name="r2_c9" src="images/r2_c9.gif" width="168" height="35" border="0" alt=""></td>
          <td><img name="r2_c10" src="images/r2_c10.gif" width="100" height="35" border="0" alt=""></td>
          <td colspan="3"><img name="r2_c11" src="images/r2_c11.gif" width="237" height="35" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="35" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><img name="r3_c1" src="images/r3_c1.gif" width="160" height="38" border="0" alt=""></td>
          <td rowspan="17" colspan="6"><iframe name="main" align="center" frameborder="0" height=470 id="main" scrolling="auto" width=100% src="main.php?variable=<?=$variable?>&p=<?=$p?>&PHPSESSID=<?=psi?>"></iframe></td>
          <td rowspan="17" colspan="2"><img name="r3_c12" src="images/r3_c12.gif" width="2" height="471" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="38" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="2"><img name="r4_c1" src="images/r4_c1.gif" width="6" height="154" border="0" alt=""></td>
          <td colspan="2"><? include("zone_membre.php"); ?></td>
          <td><img name="r4_c5" src="images/r4_c5.gif" width="7" height="154" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="154" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><img name="r5_c1" src="images/r5_c1.gif" width="160" height="3" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="3" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><img name="r6_c1" src="images/r6_c1.gif" width="160" height="26" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="26" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><a href="./?p=6" target="_top"><img name="r7_c1" src="images/m_personnel.gif" width="160" height="20" border="0" alt=""></a></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><a href="./?p=2&PHPSESSID=<?=$psi?>"><img name="r8_c1" src="images/m_sites.gif" width="160" height="20" border="0" alt=""></a></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><a href="./?p=3&PHPSESSID=<?=$psi?>"><img name="r9_c1" src="images/m_materiel.gif" width="160" height="20" border="0" alt=""></a></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><a href="./?p=4&PHPSESSID=<?=$psi?>"><img name="r10_c1" src="images/m_documents.gif" width="160" height="20" border="0" alt=""></a></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><a href="./?p=msg"><img name="r11_c1" src="images/m_messages.gif" width="160" height="20" border="0" alt=""></a></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><a href="./?p=hd"><img name="r12_c1" src="images/m_interventions.gif" width="160" height="20" border="0" alt=""></a></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5" background="images/r14_c1.gif"><strong><a href="./?p=7"><img src="images/m_lignes.gif" width="160" height="20" border="0"></a></strong></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5" background="images/r14_c1.gif"><a href="./?p=8"><img name="r15_c1" src="images/r15_c1.gif" width="160" height="20" border="0" alt=""></a></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><img name="r15_c1" src="images/r15_c1.gif" width="160" height="20" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><img name="r16_c1" src="images/r16_c1.gif" width="160" height="20" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><img name="r17_c1" src="images/r17_c1.gif" width="160" height="20" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><img name="r18_c1" src="images/r18_c1.gif" width="160" height="20" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="20" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="5"><img name="r19_c1" src="images/r19_c1.gif" width="160" height="10" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="10" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="13"><img name="r20_c1" src="images/r20_c1.gif" width="900" height="58" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="58" border="0" alt=""></td>
        </tr>
        <tr> 
          <td><img name="r21_c1" src="images/r21_c1.gif" width="1" height="13" border="0" alt=""></td>
          <td colspan="11" align="center" bgcolor="#6699CC"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">MAQUETTE 
          REALISEE PAR DGSN/CAB/DT/URS/SAR</font></td>
          <td><img name="r21_c13" src="images/r21_c13.gif" width="1" height="13" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="13" border="0" alt=""></td>
        </tr>
        <tr> 
          <td colspan="13"><img name="r22_c1" src="images/r22_c1.gif" width="900" height="1" border="0" alt=""></td>
          <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
        </tr>
      </table>
    </center>
    </body>
    </html>
    le probleme c'est quand je click sur le bouton rien ne se passe, je reste dans la meme page(index).
    merci pour votre aide.

    bonne journée

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Rien ne se passe ou bien la page se recharge et tu reviens sur ton formulaire ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Janvier 2008
    Messages : 51
    Par défaut
    bonsoir;
    merci pour votre reponse.
    oui tu as raison la page se recharge et je reste sur la meme page index.

    merci pour votre interet.

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    107
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 107
    Par défaut pb redirection
    Bonjour yucef83,

    Moi pour envoyer une donnée en cliquant sur un bouton j'utilise la balise <form> dans laquelle tu mets ton <table> etc... en gros tu fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <form action="tapage_de_redirection.php" name="form" ... >
    <table>
    <tr><td><input type="txtbox"......>
    </table>
    </form>
    Cordialement,
    Ginger

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Janvier 2008
    Messages : 51
    Par défaut
    merci pour ton aide;
    mais ce que je veux c'est ,quand un user s'authentifier, de rester sur la même page, cacher les deux zone de texte et le bouton et d'afficher déconnexion.
    bonne journée

  6. #6
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Et c'est écrit ou dans ton code actuellement ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

Discussions similaires

  1. [Interbase] Recordset dans une session ?
    Par hxt dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 24/05/2006, 15h49
  2. Réponses: 3
    Dernier message: 20/05/2006, 23h28
  3. Réponses: 7
    Dernier message: 15/05/2006, 13h36
  4. Entrer dans une session sans devoir cliquer sur ok au demarr
    Par beegees dans le forum Windows Serveur
    Réponses: 3
    Dernier message: 22/12/2005, 10h50
  5. [Sécurité] Variables dans une session
    Par philippef dans le forum Langage
    Réponses: 6
    Dernier message: 14/10/2005, 16h30

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