Salimax Posted September 3, 2005 Share Posted September 3, 2005 Bonjour. J'aimerais connaitre le "script" en php qui permet d'accéder directement à une page internet : du style pour le html : <a href="http://www.pcinpact.com">PCI</a> mais la pour le php : if ($pass == "xxx") -amène sur pcinpact- else {echo "ERREUR";} Merci Link to comment Share on other sites More sharing options...
Ishiro Posted September 3, 2005 Share Posted September 3, 2005 if ($pass == "xxx") { echo "<a href=\"http://www.pcinpact.com\">PCI</a>"; } else { echo "ERREUR"; } Sinon si tu veux une redirection, tu peux le faire avec la fonction PHP header, mais ca marche seulement si tu n'as rien envoyé au navigateur avant (pas de echo) : header('Location: mapage.html'); ou bien sinon en javascript. Link to comment Share on other sites More sharing options...
Salimax Posted September 3, 2005 Author Share Posted September 3, 2005 Merci Ishiro, mais en fait voila, j'ai du mal m'exprimer donc tu va tout comprendre à ma question par cet exemple : Si, lorsque je rentre le pass "xxx", je veux accéder directement à Google. Donc d'après toi je met : if ($pass == "xxx") {header ('Location: http://www.google.fr');} else {echo "<center><font color=red><b>ERREUR</b></font></center>";} Pourtant sa ne marche pas ... Link to comment Share on other sites More sharing options...
Coren Posted September 4, 2005 Share Posted September 4, 2005 Si ca marche Faut mettre location, pas Location ! Link to comment Share on other sites More sharing options...
Salimax Posted September 4, 2005 Author Share Posted September 4, 2005 Je met : if ($pass == "xxx") {header ('location: http://www.google.fr');} else {echo "<center><font color=red><b>ERREUR</b></font></center>";} et il me répond : Warning: Cannot modify header information - headers already sent by (output started at c:\program files\Wamp\www\parts.php: in c:\program files\Wamp\www\parts.php on line 12 Link to comment Share on other sites More sharing options...
kenji Posted September 4, 2005 Share Posted September 4, 2005 lorsque tu met un header tu ne doit avoir aucune sortie ecran avant ni aucun caractere html sur ta la page la tu as en ligne 8 dans part 8 un echo ou un truc dans le style ensuite apres un header met toujours un exit(); if ($pass == "xxx") {header ('location: http://www.google.fr'); exit();} else {echo "<center><font color=red><b>ERREUR</b></font></center>";} Link to comment Share on other sites More sharing options...
ImoTheP Posted September 4, 2005 Share Posted September 4, 2005 Et dans le cas où tu peux pas passer par un header, tu as toujours la solution JavaScript (Mieux vaut faire autrement si c'est possible) : if ($pass == "xxx") { echo "<script type=\text/javascript\">window.location='http://www.pcinpact.com'</script>"; } else { echo "ERREUR"; } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.