jerrrrry
asked on
deprecated php script to convert to msqli pdo please
CREATE TABLE IF NOT EXISTS `membres` (
`id_user` int(10) unsigned NOT NULL auto_increment,
`login` varchar(50) NOT NULL default '',
`pass` varchar(50) NOT NULL default '',
`nom` varchar(50) NOT NULL default '',
`prenom` varchar(50) NOT NULL default '',
`privilege` varchar(50) NOT NULL default '',
PRIMARY KEY (`id_user`)
);
INSERT INTO `membres` VALUES (
1, 'test', 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', 'NOM_TEST', 'Prénom_test', 'admin'
);
there are a few page
before saying to me it's too long please READ
*> i have put a few comment
basicaly you have connection.php should there be a fonction? maybe? you can see that this file is called by <?php require_once('connexion.ph
mysql_select_db($database_
is deprecaded
mysql_real_escape_string also
and a few other thing
i think that if you correct one file i should be able to convert the 2 others....
//////////////////////////
connection.php
//////////////////////////
// paramètres de connexion
$hostname_dbprotect = "localhost"; // nom de votre serveur
$username_dbprotect = "root"; // nom d'utilisateur (root par défaut) !!! ATTENTION, en utilisant root, vos visiteurs ont tous les droits sur la base
$password_dbprotect = ""; // mot de passe (aucun par défaut mais il est conseillé d'en mettre un)
$database_dbprotect = "artiste"; // nom de votre base de données
$tablename_dbprotect= "membres"; // nom de la table utilisée
$link = new mysqli($hostname_dbprotect,$username_dbprotect,$password_dbprotect ,$database_dbprotect);
if ($link->connect_errno) die("Error " . $link->connect_errno );
$link->query("SET NAMES 'utf8'");
if ($result = $link->query("SELECT DATABASE()")) {
$row = $result->fetch_row();
printf("La base de données courante est %s.\n", $row[0]);
$result->close();
}
////////////////////////
index.php
////////////////////////
<?php
require_once('connexion.php');
/*
-----------------------------------
---- SCRIPT D'AUTHENTIFICATION ----
DBProtect V1.5
Contact : david@borrat.net
Mise à jour php5
+
cryptage sha1 par aventurier19
-----------------------------------
*/
session_start(); // début de session
if (isset($_POST['login'])){ // execution apres envoi du formulaire
$login = mysql_real_escape_string($_POST['login']); // mise en variable du nom d'utilisateur > deprecated!!
$pass = sha1($_POST['pass']); // mise en variable du mot de passe crypté
// requete sur la table administrateurs (on récupère les infos de la personne
mysql_select_db($database_dbprotect, $dbprotect);
>here there is a problem i tried this mysql_select_db($database_
$verif_query = sprintf("SELECT * FROM $tablename_dbprotect WHERE login='$login' AND pass='$pass'"); // requête sur la base administrateurs
$verif = mysql_query($verif_query, $dbprotect) or die(mysql_error());
$row_verif = mysql_fetch_assoc($verif);
$utilisateur = mysql_num_rows($verif);
if ($utilisateur) { // On test s'il y a un utilisateur correspondant
$_SESSION['authentification'] = 1; // enregistrement de la session
// déclaration des variables de session
$_SESSION['privilege'] = $row_verif['privilege']; // le privilège de l'utilisateur (permet de définir des niveaux d'utilisateur)
$_SESSION['nom'] = $row_verif['nom']; // Son nom
$_SESSION['prenom'] = $row_verif['prenom']; // Son Prénom
$_SESSION['login'] = $row_verif['login']; // Son Login
$_SESSION['pass'] = $row_verif['pass']; // Son mot de passe (à éviter)
header("Location: accueil.php"); // redirection si OK
exit;
}
else {
header("Location: index.php?erreur=login"); // redirection si utilisateur non reconnu
exit;
}
}
// GESTION DE LA Déconnexion
if (isset($_GET['erreur']) && $_GET['erreur'] == 'logout'){ // Test sur les paramètres d'URL qui permettront d'identifier un "contexte" de déconnexion
header("Location: index.php?erreur=delog");
exit;
}
?>
<html>
<head>
<title>Authentification - DBProtect 1.5</title>
<style type="text/css">
<!--
.Style2 {color: #0000FF}
.Style5 {color: #FF0000}
.Style6 {font-family: Verdana, Arial, Helvetica, sans-serif}
.Style7 {font-size: 12px}
.Style10 {
font-size: 14px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<form action="" method="post" name="connect" class="Style6">
<p align="center" class="Style7"><strong>
<?php if(isset($_GET['erreur']) && ($_GET['erreur'] == "login")) { // Affiche l'erreur
echo '<span class="Style5">Echec d\'authentification !!! > login ou mot de passe incorrect</span>';
}
if(isset($_GET['erreur']) && ($_GET['erreur'] == "delog")) { // Affiche l'erreur
echo '<span class="Style2">Déconnexion réussie... A bientôt '.$_SESSION['prenom'].' !</span>';
session_unset();
}
if(isset($_GET['erreur']) && ($_GET['erreur'] == "intru")) { // Affiche l'erreur
echo '<span class="Style5">Echec d\'authentification !!! > Aucune session n\'est ouverte</span>
<span class="Style5">ou vous n\'avez pas les droits pour afficher cette page.</span>';
} ?>
<p align="center" class="Style10"> - : : : DBProtect 1.5 : : : -</p>
<p align="center" class="Style7"><em>Authentification sécurisée utilisant :<br>
- BDD MySQL<br>
- Sessions PHP<br>
- Cryptage par SHA1</em></p>
<p align="center" class="Style7"><em><a href="lisez_moi.htm">lire les instructions >></a></em></p>
<div align="center" class="Style7">
<table width="300" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td><table width="400" border="0" cellpadding="10" cellspacing="0" bgcolor="#eeeeee">
<tr>
<td width="50%"><span class="Style7">LOGIN</span></td>
<td width="50%"><input name="login" type="text" id="login"></td>
</tr>
<tr>
<td width="50%"><span class="Style7">MOT DE PASSE </span></td>
<td width="50%"><input name="pass" type="password" id="pass"></td>
</tr>
<tr>
<td height="34" colspan="2"><div align="center">
<input type="submit" name="Submit" value="Se connecter">
</div></td>
</tr>
</table></td>
</tr>
</table>
Script par <a href="http://www.borrat.net">DB</a><br />
Mise à jour php5 + cryptage sha1 par aventurier19</div>
</form>
</body>
</html>
/////////////////////////
accueil.php
//////////////////////////
<?php
require_once('connexion.php');
/*
-----------------------------------
---- SCRIPT D'AUTHENTIFICATION ----
DBProtect V1.5
Contact : david@borrat.net
Mise à jour php5
+
cryptage sha1 par aventurier19
-----------------------------------
*/
session_start(); // On relaye la session
if (isset($_SESSION['authentification'])){ // vérification sur la session authentification (la session est elle enregistrée ?)
// ici les éventuelles actions en cas de réussite de la connexion
}
else {
header("Location: index.php?erreur=intru"); // redirection en cas d'echec
exit;
}
?>
<html>
<head>
<title>Accueil</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.Style2 {font-family: Verdana, Arial, Helvetica, sans-serif}
.Style3 {font-size: 12px}
.Style4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.Style8 {color: #0000FF; font-weight: bold; }
.Style11 {font-size: 10px}
.Style12 {font-size: 14px}
-->
</style>
</head>
<body>
<p align="center" class="Style2 Style12"><strong>- : : : DBProtect 1.5 : : : -</strong></p>
<p class="Style2 Style3">Bienvenue "<span class="Style8"><?php echo $_SESSION['nom']; ?>
<?php echo $_SESSION['prenom']; ?></span>" dans votre espace sécurisé. </p>
<p class="Style4">Vous êtes connecté en tant que "<span class="Style8"><?php echo $_SESSION['login']; ?></span>" avec le privilège "<span class="Style8"><?php echo $_SESSION['privilege']; ?></span>"</p>
<p class="Style4">Votre mot de passe est "<span class="Style8"><?php echo $_SESSION['pass']; ?></span>" (crypté par SHA1)</p>
<p class="Style4"> </p>
<p class="Style4">
<?php
/*
--- AFFICHAGE CONDITIONNEL OU REDIRECTION EN FONCTION DU PRIVILEGE ---
Config actuelle : le script gère un affichage conditionnel
Pour rediriger l'utilisateur en fonction de son privilege, ajoutez les lignes suivantes aux endroits indiqués
Dans la zone d'affichage admin :
header("Location:URL SI ADMIN")
Dans la zone d'affichage admin :
header("Location:URL SI USER SIMPLE")
Note: pour ajouter des privilèges, editez ce fichier en rajoutant une condition d'affichage
et editez le fichier admin.php en ajoutant à la liste "select" un privilege.
*/
// si l'utilisateur est connecté comme admin ...
if ($_SESSION['privilege'] == "admin") { // Affichage conditionnel : si et seulement si l'utilisateur est connecté avec le privilege administrateur ?>
<strong>En tant qu'administrateur vous pouvez effectuer les actions suivantes : </strong></p>
<p class="Style4">- <a href="admin.php">Gérer les utilisateurs</a>
<?php } // fin de l'affichage conditionnel?></p>
<p class="Style4">
<?php
// si l'utilisateur est connecté comme simple utilisateur ...
if ($_SESSION['privilege'] == "user") { // Affichage conditionnel : si et seulement si l'utilisateur est connecté avec le privilege utilisateur simple ?>
<strong>En tant qu'utilisateur simple vous ne pouvez pas effectuer d'actions</strong>
<?php } // fin de l'affichage conditionnel?>
</p>
<p align="left" class="Style4 Style3"><a href="index.php?erreur=logout"><strong>Vous déconnecter</strong></a></p>
<p align="center" class="Style4 Style11"> </p>
<p align="center" class="Style4 Style11"><strong>EN EDITANT CETTE PAGE (accueil.php), VOUS ALLEZ POUVOIR CONFIGURER DES ACTIONS A EFFECTUER EN FONCTION DU PRIVILEGE DE L'UTILISATEUR CONNECTE (redirection ou affichage conditionnel).<br />
Les instructions sont dans le fichier source. HAVE FUN ;-) </strong></p>
<p align="center" class="Style4 Style11"><span class="Style3">Script par <a href="http://www.borrat.net">DB</a></span><br />
Mise à jour php5 + cryptage sha1 par aventurier19</p>
</body>
</html>
thanks
login.zip
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://support.experts-exchange.com/customer/portal/articles/481419
What was wrong with this answer? Did you find an error in the article? If so, please let us know so it can be corrected!