Jump to content

PHP


Salimax

Recommended Posts

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 :ouioui:

Link to comment
Share on other sites

if ($pass == "xxx")
{
  echo "<a href=\"http://www.pcinpact.com\">PCI</a>";
}
else
{
  echo "ERREUR";
}

:ouioui:

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...