Merci pour ton aide Jérôme. Par contre, je n'arrive pas à aller bien loin :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 if ( ! $auth ){ header( 'WWW-Authenticate: Basic realm="EIS SUPPORT WEBSITE"' ); header("HTTP/1.1 401 Unauthorized"); echo "Accès Restreint...<br/>"; echo "<a href=\"indexpage.php\">Authentification</a>"; } else ...
authenticate.php :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 function authentification(){ // 1/ récupération des données $entered_user = (isset($_SERVER["PHP_AUTH_USER"]))? $_SERVER["PHP_AUTH_USER"] : ''; $entered_pass = (isset($_SERVER["PHP_AUTH_PW"]))? $_SERVER["PHP_AUTH_PW"] : ''; if( !empty($entered_user) && !empty($entered_pass) ){ // 2/ vérification de la présence en BdD $sql = "SELECT user FROM users WHERE user = :user;"; $qid = $bdd->prepare($sql); // ligne 23 $qid->bind_param( ':user', $entered_user); $qid->execute(); $rowAll = $qid->fetchAll(PDO::FETCH_ASSOC); // on obtient un array() ...
dans le fichier principal (indexpage.php) :
global $bdd;
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 include dirname(__DIR__)."\pdo\connect_mysql.php"; ... include dirname(__DIR__)."\pdo\authenticate.php"; $auth=authentification();
connect_mysql.php :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?php include_once (dirname(__DIR__).'\pdo\new\MyPdo.php'); header('Content-type: text/html; charset=UTF-8'); //// connexion try{ $bdd = new MyPdo(); } catch(PDOException $e){ echo "argggggggggggggg".$e->getMessage(); return(FALSE); } ?>
MyPdo.php :
affiche :
Code php : 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 <?php error_reporting(E_ALL ^ E_DEPRECATED ^ E_NOTICE); ini_set('display_errors','1'); // MyPDO // ls : la classe MyPdo hérite de la classe PDO (extends) class MyPdo extends PDO { static public $DB_NAME = "su_dev_eis"; static public $HOST = "localhost"; static public $USER = $_SERVER["PHP_AUTH_USER"]; static public $PASS =$_SERVER["PHP_AUTH_PW"]; //static public $USER ="root"; //static public $PASS ="root"; // ls : le constructeur de MyPdo appelle le constructeur de PDO en lui passant ses paramètres function __construct() { $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $pdo_options[PDO::ATTR_EMULATE_PREPARES] = false;//important sur les configs récentes $pdo_options[PDO::ATTR_DEFAULT_FETCH_MODE] = PDO::FETCH_OBJ;//pour le mode objet $pdo_options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES utf8";//pour l'utf-8 parent::__construct('mysql:host=' . MyPdo::$HOST . ';dbname=' . MyPdo::$DB_NAME, MyPdo::$USER,MyPdo::$PASS, $pdo_options); //MyPdo::$USER } } // fin MyPDO ?>Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\devjupiter_serveur291214\pdo\authenticate.php on line 23
Partager