Bonjour,
Afin de me familiariser avec l'utilisation de sessions j'ai créé un fichier page1.php et un fichier page2.php.
Dans le fichier page1.php, définition d’une session et affichage de celle-ci comme suivant :
page1.php
Dans la page2.php affichage de la session prédéfinie dans la page1.php comme 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 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="author" content="" /> <meta name="copyright" content="" /> <meta name="description" content=""> <meta name="keywords" content="" /> <title>CESSION page 1</title> </head> <body> <?php session_start(); echo 'Page numéro 1 ' . '</br> '; $_SESSION['favcolor'] = 'vert'; echo $_SESSION['favcolor']; echo '<br /><a href="page2.php?' . SID . '">page 2</a>'; ?> </body> </html>
page2.php
Le problème $_SESSION['favcolor'] dans la page2.php ne s’affiche pas. Auriez-vous une idée ?
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 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="author" content="" /> <meta name="copyright" content="" /> <meta name="description" content=""> <meta name="keywords" content="" /> <title>CESSION page 2</title> </head> <body> <?php session_start(); echo 'Page numéro 2 ' . '</br> '; echo 'Couleur : ' . $_SESSION['favcolor']; echo '<br /><a href="page1.php?' . SID . '">page 1</a>'; ?> </body> </html>
Cordialement.
Partager