Bonjour,
j'ai suivi le tuto pour créer un espace membre, pour avoir déjà la base et je voudrais améliorer le fonctionnement du système de redirection des pages (quand on valide un formulaire ou autre, on transite par une page avec un message et ensuite on est redirigé sur la page suivante, ex: quand on post sur ce site).
Mon but est de ne plus avoir le message de confirmation pour recharger la page, vu que ça fait de temps en temps planté les données envoyées.
J'ai donc essayé un tuto mais je n'ai pas réussi...
Voilà comment je fais actuellement pour la redirection :
ma_page_avec_formulaire.php
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 <?php // Mon super formulaire ici // FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE // FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE FORMULAIRE // Quand les informations du formulaire sont validées en redirige la personne $informations = array( false, 'Topic Crée', 'Votre topic a été crée !', '', 'ma_page_suivante.php', 5 ); require_once ROOTPATH.'/information.php'; exit();
information.php
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
37
38
39 <?php if(!isset($informations)) { $informations = Array(/*Erreur*/ true, 'Erreur', 'Une erreur interne est survenue...', '', ROOTPATH.'/index.php', 3 ); } if($informations[0] === true) $type = 'erreur'; else $type = 'information'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" > <head> <title><?php echo $informations[1]; ?> : <?php echo TITRESITE; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="language" content="fr" /> <meta http-equiv="Refresh" content="<?php echo $informations[5]; ?>;url=<?php echo $informations[4]; ?>"> <link rel="stylesheet" title="Design" href="<?php echo ROOTPATH; ?>/design.css" type="text/css" media="screen" /> </head> <body> <div id="info"> <div id="<?php echo $type; ?>"><?php echo $informations[2]; ?> Redirection en cours...<br/> <a href="<?php echo $informations[4]; ?>">Cliquez ici si vous ne voulez pas attendre...</a><?php echo $informations[3]; ?></div> </div> </body> </html> <?php unset($informations); ?>
J'ai essayé avec les sessions mais j'ai quand même le message de confirmation donc je bloque un peu...
Voilà ce que j'ai fait :
ma_page_avec_formulaire.php
information.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 $_SESSION['informations'] = array( false, 'Topic Crée', 'Votre topic a été crée !', '', 'ma_page_suivante.php', 5 ); require_once ROOTPATH.'/information.php'; exit();
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 <?php ob_start(); if(!isset($_SESSION['informations'])) { $_SESSION['informations'] = array( true, 'Erreur', 'Une erreur interne est survenue...', '', ROOTPATH.'/', TPSREDIR ); } if($_SESSION['informations'][0] === true) $type = 'erreur'; else $type = 'information'; if(!empty($_POST)) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" > <head> <title><?php echo $_SESSION['informations'][1]; ?> : <?php echo TITRESITE; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="language" content="fr" /> <meta http-equiv="Refresh" content="<?php echo $_SESSION['informations'][5]; ?>;url=<?php echo $_SESSION['informations'][4]; ?>"> <link rel="stylesheet" title="Design" href="<?php echo ROOTPATH; ?>/design.css" type="text/css" media="screen" /> </head> <body> <div id="info"> <div id="<?php echo $type; ?>"><?php echo $_SESSION['informations'][2]; ?> Redirection en cours...<br/> <a href="<?php echo $_SESSION['informations'][4]; ?>">Cliquez ici si vous ne voulez pas attendre...</a><?php echo $_SESSION['informations'][3]; ?></div> </div> </body> </html> <?php $_SESSION['sauvegarde'] = $_POST; if (isset($_SESSION['url_redirection'])) $fichierActuel = $_SESSION['informations'][4]; elseif(!empty($_SERVER['HTTP_REFERER'])) $fichierActuel = $_SERVER['HTTP_REFERER']; else $fichierActuel = '/'; unset($_SESSION['informations']); if(!$_SESSION['informations'][5] == 0) header('refresh:'.$_SESSION['informations'][5].'; url='.$fichierActuel); exit; } if(isset($_SESSION['sauvegarde'])) { $_POST = $_SESSION['sauvegarde']; unset($_SESSION['sauvegarde']); unset($_SESSION['informations']); } ob_end_flush(); ?>
Merci !
Partager