Bonjour,
je n'ai pas posé de question tout de suite, mais depuis ce matin, je n'y arrive pas...
Mon but est de permettre de demander plusieurs fois une authentification, afin de faire plusieurs tests sans devoir redémarrer le PC entre 2 essais. J'utilise pour cela une variable de session. Le problème, c'est que soit il ne demandait jamais l'authentification, soit il la demande mais ne la valide pas. Le cas du code actuel que voici est le premier cas :
indexpageavecauth.php :
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
26 <?php error_reporting(E_ALL ^ (E_NOTICE|E_WARNING|E_DEPRECATED)); header('Content-type: text/html; charset=UTF-8'); session_start(); include (dirname(__DIR__).'\pdo\config\config.php'); include dirname(__DIR__)."\pdo\authenticateauth.php"; if ((isset($_SESSION["annul"]))&&($_SESSION["annul"]==0)) $auth=authentification(); // DEMANDE D'AUTHENTIFICATION if ( ! $_SESSION["auth"]) { $_SESSION["annul"]==0; header( 'WWW-Authenticate: Basic realm="EIS SUPPORT WEBSITE"' ); header("HTTP/1.1 401 Unauthorized"); echo "Accès Restreint...<br/>"; echo "<a href=\"".SITE_URL_HTTP."\indexpageavecauth.php\">Authentification</a>"; } else { ... } ?> <br/><a href="<?php echo SITE_URL_HTTP;?>\annul_auth.php">Annul_auth</a>
authenticateauth.php
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 <?php session_start(); function authentification() { $auth=0; $entered_user = $_SERVER["PHP_AUTH_USER"]; $entered_pass = $_SERVER["PHP_AUTH_PW"]; if (isset($entered_user) && isset($entered_pass)) { $auth=false; // contrôle authentif et positionnement de $auth } } $_SESSION["auth"]=$auth; return $auth; } ?>
annul_auth.php
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <?php session_start(); include (dirname(__DIR__).'\pdo\config\config.php'); $_SESSION["auth"]=0; $_SESSION["annul"]=1; $file=SITE_URL_HTTP."/indexpageavecauth.php? "; header('Location:'.$file); exit; ?>
config.php :
Que faut-il changer ?
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <?php // ----------------------------------------------------------- // CONFIGURATION : // ----------------------------------------------------------- if(!defined('SITE_URL_WWW')) define('SITE_URL_WWW', '10.234.40.34/devjupiter/pdo'); // en TEST LOCAL, A REMPLACER PAR... //if(!defined('SITE_URL_WWW')) define('SITE_URL_WWW', 'www.mon-site-en-ligne.com'); // en PRODUCTION if( !defined('SITE_URL_HTTP')) define('SITE_URL_HTTP', 'http://'.SITE_URL_WWW); ?>
Partager