Redirection header("Location:...")
DwightShrut
-
DwightShrut -
DwightShrut -
Salut à tous, alors voilà, j'ai fais une petite technique pour rediriger comme je voulais mes liens avec des balises <a> sans problème, néanmoins, j'ai une autre page ou ce n'est pas des balises <a> mais des header("Location:...") j'aimerai donc faire la même chose avec ça et j'ai essayé quelques trucs mais j'ai des problèmes avec tout ce que j'essaye. Merci pour votre aide.
Voici ce que j'ai fais :
Et voici le code avec le quel j'aimerai faire pareil :
Voici ce que j'ai fais :
<?php if ($_SESSION['nom']=="personne1"){ ?> <a href="taches.php?salarie=personne1"> <?php } elseif ($_SESSION['nom']=="personne2"){ ?> <a href="taches.php?salarie=personne2"> <?php } else { ?> <a href="taches.php?salarie=personne3"> <?php } ?>
Et voici le code avec le quel j'aimerai faire pareil :
header("Location:taches.php"); exit();
A voir également:
- Redirection header("Location:...")
- Avertissement de redirection ✓ - Forum MacOS
- Avertissement de redirection Google image - Forum Réseaux sociaux
- 400 bad request request header or cookie too large - Forum Windows
- Logiciel location saisonniere - Forum Gestion de parc
- Firfox 3 et option de redirection (désactiver ✓ - Forum Logiciels
3 réponses
yg_be
Messages postés
23541
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 584
bonjour,
qu'as-tu essayé, quels problèmes as-tu rencontrés?
qu'as-tu essayé, quels problèmes as-tu rencontrés?
yg_be
Messages postés
23541
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 584
je suis étonné par ton code, pourquoi passer le nom via l'url alors qu'il est dans une variable de session?
peux-tu montrer le code de la page taches.php?
peux-tu montrer le code de la page taches.php?
Voilà tout mon code de tâches.php :
Et ma page où se trouve le header("Location:...") est la page modifierTachesReq.php qui permet de faire tous les UPDATE dans la base de donnée après la modification d'une tâche (modifierTache.php)
<body class="fond2"> <?php // si l'utilisateur fait une recherche (taches.php?salarie=id), on change le filtre salarie // [...] execution de la requête sql pour récupérer les taches session_start(); include('pdo.php'); include('header.php'); if ($_SESSION['niveau']=="technicien"){ if($droit['techAcces']=="non"){ header('Location:index.php?acces=interdit'); } } if ($_SESSION['niveau']=="basique"){ if($droit['basiqueAcces']=="non"){ header('Location:index.php?acces=interdit'); } } if(isset($_GET['codeClient'])){ $stmt = $pdo->prepare('SELECT * from clients WHERE codeClient = :codeClient'); $stmt->bindValue(':codeClient', $_GET['codeClient'], PDO::PARAM_STR); $stmt->execute(); $client=$stmt->fetch(); ?> <div class="container" style="text-align:left; position:relative; bottom:10px"> <a href="modifier.php?id=<?php echo $client['id']; ?>" class="retour"><img class="imagehome" src="icones/retour.png"></a> </div> <?php } ?> <br> <div style="text-align:center"> <h1 class="h1liste">Tâches</h1> </div> <?php if(isset($_GET['acces']) AND $_GET['acces']=="interdit"){ ?> <div style="text-align:center; color:red"> Vous n'avez pas les droits d'accès à cette page ! </div><br> <?php } ?> <br> <?php if (isset($_GET['salarie'])) { $filtreSalarie = $_GET['salarie']; } if(isset($_GET['codeClient']) and isset($_GET["moisSelec"]) and isset($_GET["annee"])){ $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient where taches.codeClient = :codeClient AND YEAR(taches.date) = '.$_GET["annee"].' AND MONTH(taches.date) = '.$_GET["moisSelec"].' ORDER BY taches.statut DESC, taches.date DESC'); $stmt->bindValue(':codeClient', $_GET['codeClient'], PDO::PARAM_STR); $stmt->execute(); $resu=$stmt->fetchALL(); } if(isset($_GET['codeClient']) and isset($_GET["moisSelec"]) and isset($_GET["annee"]) and $_GET["annee"] == "ALL"){ $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient where taches.codeClient = :codeClient AND MONTH(taches.date) = '.$_GET["moisSelec"].' ORDER BY taches.statut DESC, taches.date DESC'); $stmt->bindValue(':codeClient', $_GET['codeClient'], PDO::PARAM_STR); $stmt->execute(); $resu=$stmt->fetchALL(); } if(isset($_GET['codeClient']) and isset($_GET["annee"]) and isset($_GET["moisSelec"]) and $_GET["moisSelec"] == "annee"){ $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient where taches.codeClient = :codeClient AND YEAR(taches.date) = '.$_GET["annee"].' ORDER BY taches.statut DESC, taches.date DESC'); $stmt->bindValue(':codeClient', $_GET['codeClient'], PDO::PARAM_STR); $stmt->execute(); $resu=$stmt->fetchALL(); } if(isset($_GET['codeClient']) and isset($_GET["annee"]) and $_GET["annee"]=="ALL" and isset($_GET["moisSelec"]) and $_GET["moisSelec"] == "annee"){ $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient where taches.codeClient = :codeClient ORDER BY taches.statut DESC, taches.date DESC'); $stmt->bindValue(':codeClient', $_GET['codeClient'], PDO::PARAM_STR); $stmt->execute(); $resu=$stmt->fetchALL(); } if(!isset($_GET['codeClient']) and !isset($_GET["moisSelec"]) and !isset($_GET["annee"])){ $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient ORDER BY taches.statut DESC, taches.date DESC'); $stmt->execute(); $resu=$stmt->fetchALL(); } if(isset($_GET['salarie']) and $_GET['salarie']=="TOUS"){ $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient ORDER BY taches.statut DESC, taches.date DESC'); $stmt->execute(); $resu=$stmt->fetchALL(); }elseif (isset($_GET['salarie']) and $_GET['salarie']!="TOUS"){ $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient where taches.salarie=:nom ORDER BY taches.statut DESC, taches.date DESC'); $stmt->bindValue(':nom', $_GET['salarie'], PDO::PARAM_STR); $stmt->execute(); $resu=$stmt->fetchALL(); } /*if(isset($_SESSION['niveau']) AND $_SESSION['niveau']!="admin"){ $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient where taches.salarie=:nom ORDER BY taches.statut DESC, taches.date DESC'); $stmt->bindValue(':nom', $_SESSION['nom'], PDO::PARAM_STR); $stmt->execute(); $resu=$stmt->fetchALL();}*/ if(isset($_GET['date']) AND ($_GET['date']="depasse")){ $dateactuelle=date("Y-m-d"); $stmt = $pdo->prepare('SELECT taches.codeClient, taches.salarie, taches.id, taches.date, taches.minReal, taches.heureReal, taches.statut, clients.id as idd from taches JOIN clients ON taches.codeClient = clients.codeClient where taches.salarie=:nom AND taches.statut = :statut and taches.date < :date ORDER BY taches.date DESC, taches.salarie ASC'); $stmt->bindValue(':nom', $_SESSION['nom'], PDO::PARAM_STR); $stmt->bindValue(':statut', 1, PDO::PARAM_INT); $stmt->bindValue(':date', $dateactuelle, PDO::PARAM_STR); $stmt->execute(); $resu=$stmt->fetchALL(); } ?> <table> <tr> <td></td> <td><div style="text-align: center"><a href="ajoutTache.php"> <img align="center" src="icones/add.png" width="35"> </a></td> <td></td> </tr> <tr> <br><br> <td></td> <td> <form action="taches.php" method="GET"> <select name="salarie" id="id" style="width:200px"> <option value="" <?= empty($filtreSalarie) ? 'selected' : ''; ?>>Tous les salariés</option> <option value="personne3" <?php if ($filtreSalarie == 'personne3') echo 'selected'; ?>>personne3</option> <option value="personne2" <?php if ($filtreSalarie == 'personne2') echo 'selected'; ?>>personne2</option> <option value="personne1" <?php if ($filtreSalarie == 'personne1') echo 'selected'; ?>>personne1</option> </select> <button class="btn" style="width:60px" type="submit"><img src="icones/accept.png" width="40" height="40"></button> </form></td> <td></td> </tr> </table> <br> <div class="container"> <table id= "table-id"> <tr> <th>Code client</th> <th>Salarié</th> <th>Date</th> <th>Temps de réalisation</th> </tr> <?php foreach ($resu as $res){ $heure = ($res['heureReal'] * 60) ; $minutes = ($res['minReal']); $totalHeures += $heure + $minutes; ?> <tr class="trlist"> <td <?php if($res['statut']==1){ ?>style="width:200px; background-color:RGBA(255,0,0,0.4); text-align:left; padding-left:10%"<?php }else { ?> style="width:200px; text-align:left; padding-left:10%"<?php } ?>><a href="modifier.php?id=<?php echo $res['idd']?>" onclick="window.open(this.href); return false;"><?php echo $res['codeClient']?></a></td> <td <?php if($res['statut']==1){ ?>style="width:200px; background-color:RGBA(255,0,0,0.4); text-align:left; padding-left:12%"<?php }else { ?> style="width:200px; text-align:left; padding-left:12%"<?php } ?>><?php echo $res['salarie']?></td> <td <?php if($res['statut']==1){ ?>style="width:200px; background-color:RGBA(255,0,0,0.4); text-align:left; padding-left:10%"<?php }else { ?> style="width:200px; text-align:left; padding-left:10%"<?php } ?>><a href="modifierTache.php?id=<?php echo $res['id']?>"><?php echo strftime('%d-%m-%Y',strtotime($res['date']))?></a></td> <td <?php if($res['statut']==1){ ?>style="width:200px; background-color:RGBA(255,0,0,0.4); text-align:left; padding-left:12%"<?php }else { ?> style="width:200px; text-align:left; padding-left:12%"<?php } ?>><?php echo gmstrftime( "%H h %M min", (($res['heureReal'] * 60) + $res['minReal']) * 60 )?></td> </tr> <?php } ?> </table> <br> <?php if(isset($_GET['codeClient'])){ ?> <h4>Total d'heures : <?php echo gmstrftime( "%H h %M min", $totalHeures * 60 )?></h4> <br> <?php } if(isset($_GET['codeClient'])){ ?> <br> <div class="container" style="text-align: right;"><a href="HTML2PDF/pdfTache.php?codeClient=<?php echo $_GET['codeClient']?>&moisSelec=<?php echo $_GET['moisSelec']?>&annee=<?php echo $_GET['annee']?>" target="_blank"><button type="button" style="width:60px" class="btn"><img src="icones/imprimante.png" style="width:30px"></button></a></div> <?php } ?> <br><br> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
Et ma page où se trouve le header("Location:...") est la page modifierTachesReq.php qui permet de faire tous les UPDATE dans la base de donnée après la modification d'une tâche (modifierTache.php)
Bonjour,
ce code :
Revient à écrire
Mais.. Sachant que tu as le "nom" de la personne en variable de session.... à quoi ça sert de le remettre en variable GET dans l'url sur laquelle tu redirige ?
Le code devrait simplement être :
et dans ton fichier taches.php, remplacer ton GET pour récupérer le salarié par :
Quoi qu'il en soit, si tes soucis persistent.. pense à :
- Vérifier que tu as bien mis un session_start sur chacune de tes pages
- Faire un var_dump($_SESSION); pour vérifier ce qu'elle contient
ce code :
<?php if ($_SESSION['nom']=="personne1"){ header("Location:taches.php?salarie=personne1"); exit(); } elseif ($_SESSION['nom']=="personne2"){ header("Location:taches.php?salarie=personne2"); exit(); } else { header("Location:taches.php?salarie=personne3"); exit(); } ?>
Revient à écrire
<?php $nom = !empty($_SESSION['nom']) ? $_SESSION['nom'] : "personne3"; header("Location:taches.php?salarie=".$nom); exit; ?>
Mais.. Sachant que tu as le "nom" de la personne en variable de session.... à quoi ça sert de le remettre en variable GET dans l'url sur laquelle tu redirige ?
Le code devrait simplement être :
<?php header("Location:taches.php"); exit; ?>
et dans ton fichier taches.php, remplacer ton GET pour récupérer le salarié par :
$salarie = !empty($_SESSION['nom']) ? $_SESSION['nom'] : "personne3";
Quoi qu'il en soit, si tes soucis persistent.. pense à :
- Vérifier que tu as bien mis un session_start sur chacune de tes pages
- Faire un var_dump($_SESSION); pour vérifier ce qu'elle contient
J'ai aussi essayé de faire un copier coller du premier code et de remplacer le header par une balise <a> mais ça n'a pas fonctionné non plus (logique).