Bonjour ,
voici le code de trois fichiers qui s'appelle l'un l'autre.
Je désire bénéficier de variables $_SESSION comme variables globales :

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
<?php
    session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
<title>TRA&Ccedil;ABILIT&Eacute;</title>
</head>
<body>
<form method="post" action="verif.php">
<input type="text" name="identifiant"/>
<select name="service">
<option value="CAMINO_ETAGE">Camino etage</option>
<option value="CAMINO_RDC">Camino rdc</option>
</select>
<input type="submit" value="Valider"/>
</form>
</body>
</html>
voici vérifie.php :
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
<?php
    session_start();
    // Récupération identifiant
    $id = $_POST['identifiant'];// récupération de l'identifiant
    $bdd = new PDO('mysql:host=localhost;dbname=PERSONNEL','Philippe','');
    $req = $bdd->prepare('SELECT pseudo FROM Agents WHERE id = ?');
    $req->execute(array($id));
    $pseudo = ($req->fetch())['pseudo'];
    $req->closeCursor();
    // Vérification identifiant et droits
    ;
    // Enregistrement variables session
    $_SESSION['pseudo'] = $peudo;
    $_SESSION['service'] = $_POST['service'];
    $_SESSION['id'] = $id;
    $bdd = new PDO('mysql:host=localhost;dbname=TRACABILITE','Philippe','');
    $_SESSION['bdd'] = $bdd->query('SELECT * FROM Todo');
    //
    echo 'Identifiant : ' . $_SESSION['id'] . '<br/>service : ' . $_SESSION['service'] . '</br>';
    // Redirection vers formulaire
    header('Location: cible.php');
?>
et voici cible.php :
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
31
32
<?php
    session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
<title><?php echo $_SESSION['service']; ?></title>
</head>
<body>
<p>
<?php
    echo 'Identifiant : ' . $_SESSION['id'] . '<br/>service : ' . $_SESSION['service'] . '</br>';
?>
</p>
<?php
    $donnees = $_SESSION['bdd']->fetch(PDO::FETCH_ASSOC);
    echo $donnees['lieu'];
    echo '<button>' . '>>>' . '</button>';
    echo '<form id="ref" method="post" action="record.php">';
    foreach($donnees as $cle => $element)
    {
        if ($element == 'O')
        {
            echo '<input type="checkbox" name="' . $cle . '" id="' . $cle . '"/>';
            echo '<label for="' . $cle .'">' . $cle . '</label>';
        }
    }
    //$req->closeCursor();
?>
</form>
</body>
</html>
mon problème c'est que les variables de session sont vides dans cible.php
puis-je savoir pour quelle raison ?