[PHP] Affichage de page aleatoire

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [PHP] Affichage de page aleatoire

par lux » 24 nov. 2007, 09:33

Pour ça je stockerais une valeur en session, que j'incrémenterai au fur et à mesure.

Et qu'il fasse nimporte quoi, c'est normal c'est un random :lol:

par pertusien » 24 nov. 2007, 01:27

ça fonctionne en faite ej voyais rien car au lieu d'avoir

Code : Tout sélectionner

<img src="images/imagettes/vvv.jpg" width="216" height="50" />
j'avais ça

Code : Tout sélectionner

<img src="../images/imagettes/vvv.jpg" width="216" height="50" />
donc ça ne pouvais pas s'afficher

maintenant que ça matche on peux lui dire de faire un random qui se suit page1 puis page 2 puis page 3 ........ car là il faut un peu n'importe quoi

merci de ton aide

par pertusien » 24 nov. 2007, 01:10

non pas d'echos

l'include fonctionne tres bien j'appel les pages avec index.php?page=contact et je nomme ma page contact.include.php et ça fonctionne tres bien meme quand je mes l'autre code mais le code de page aleatoire ne fonctionne pas

par lux » 24 nov. 2007, 01:03

Et donc ça n'affiche rien ?? Etrange...

MMh je viens de penser à un truc, c'est bien beau de faire une include, mais y a t'il des echo dans tes pages ? (On sait jamais) .. tu inclus mais il faut qu'il y ait un echo qqpart ...

par pertusien » 24 nov. 2007, 00:58

Code : Tout sélectionner

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Kyness Informatique 31 rue de la Murette 84120 Pertuis</title> <link href="template.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="1000" border="0" cellpadding="0" cellspacing="0" background="images/design_05.jpg"> <!--DWLayoutTable--> <tr> <td height="235" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="126" height="235" valign="top"><img src="images/design_01.jpg" alt="Kyness informatique" width="126" height="235" /></td> <td width="543" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/design_02.jpg"> <!--DWLayoutTable--> <tr> <td width="543" height="171">&nbsp;</td> </tr> <tr> <td height="34" valign="bottom"><div class="menu">Accueil | Menu1 | Menu2 | Menu3 | Conctact | Société</div></td> </tr> <tr> <td height="30">&nbsp;</td> </tr> </table></td> <td width="331" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/design_03.jpg"> <!--DWLayoutTable--> <tr> <td width="265" height="40">&nbsp;</td> <td width="66">&nbsp;</td> </tr> <tr> <td height="165" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td height="30">&nbsp;</td> <td>&nbsp;</td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td width="50" height="176">&nbsp;</td> <td width="900" valign="top"><p>&nbsp;<? if(is_file('page/'.$page.'.include.php')) { include('page/'.$page.'.include.php'); }else{ include('page/index.include.php'); } ?></p> &nbsp;<p> <br /> <br /> </p> <?php $random = rand(1,5); include('page/page'.$random.'.php'); ?> </td> <td width="50">&nbsp;</td> </tr> <tr> <td height="24" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/design_22.jpg"> <!--DWLayoutTable--> <tr> <td width="1000" height="24">&nbsp;</td> </tr> </table> </td> </tr> </table> </body> </html>

desolé j'avais pas vu, voilà la modif le script que tu as fais pour moi est en dessou de l'include

par lux » 24 nov. 2007, 00:52

Ha désolé y a eu confusion, vu que il y avait que ça comme code php dans le code que tu as mis.

Si tu mets :
<?php  

$random = rand(1,2);  

include('pages/page'.$random.'.php');  

?>
autre part ? Genre au dessus de ton code que tu viens de citer ?

par pertusien » 24 nov. 2007, 00:46

Code : Tout sélectionner

<? if($page != NULL && is_file('page/'.$page.'.include.php')) { include('page/'.$page.'.include.php'); }else{ include('page/index.include.php'); } ?>
en faite ça c'est un code que j'ai mis pour la premiere partit de mon site qui affiche les pages appelé par mon menu

apres le code pour les pages aleatoire c'est en bas de mon site pour afficher d'autre page d'information aleatoirement

par lux » 24 nov. 2007, 00:41

En fait ça dépends de ce que tu veux faire, mais le code est relativement explicite par lui même :

if = si, else = sinon :
<? 
if(conditions = true) //le controle = true n'est pas obligatoire
{ 
     suite d'instructions si true
}
else
{ 
      suite d'instructions si false
}
?>
Bon, toi tu veux que ça affiche tout le temps je suppose, pas besoin de structure if/else ...
Enleve les if/else, il doit rester que ça, qui affichera donc sans conditions :
<?php 

$random = rand(1,2); 

include('pages/page'.$random.'.php'); 

?> 

par pertusien » 24 nov. 2007, 00:26

donc je mes ça !
if(is_file('page/'.$page.'.include.php'

par lux » 24 nov. 2007, 00:18

Tu as une condition dans ton if :
if($page != NULL &&
$page n'est initialisé nulle part non ?
Superflu donc ?

par pertusien » 24 nov. 2007, 00:09

Code : Tout sélectionner

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link href="template.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" fptype="dynamicanimation"> <!-- function dynAnimation() {} function clickSwapImg() {} //--> </script> <script language="JavaScript1.2" fptype="dynamicanimation" src="../animate.js"> </script> </head> <body onload="dynAnimation()" language="Javascript1.2"> <table width="1000" border="0" cellpadding="0" cellspacing="0" background="images/design_05.jpg" height="1146"> <!--DWLayoutTable--> <tr> <td height="235" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="126" height="235" valign="top"><img src="images/design_01.jpg" alt="xx informatique" width="126" height="235" /></td> <td width="543" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/design_02.jpg"> <!--DWLayoutTable--> <tr> <td width="543" height="171">&nbsp;</td> </tr> <tr> <td height="34" valign="bottom"> <div class="menu" dynamicanimation="fpAnimformatRolloverFP1" fprolloverstyle="color: #47A3F2" onmouseover="rollIn(this)" onmouseout="rollOut(this)" language="Javascript1.2"> <a href="index.php?page=accueil">ACCUEIL</a> | <a href="index.php?page=service">SERVICE</a> | <a href="index.php?page=magasin">MAGASIN</a> | <a href="index.php?page=tarifs">TARIFS</a> | <a href="index.php?page=game">GAMER</a> | <a href="index.php?page=forum">FORUM</a> | <a href="index.php?page=contact">CONTACT</a></div></td> </tr> <tr> <td height="30">&nbsp;</td> </tr> </table></td> <td width="331" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/design_03.jpg"> <!--DWLayoutTable--> <tr> <td width="265" height="40">&nbsp;</td> <td width="66">&nbsp;</td> </tr> <tr> <td height="165" valign="top">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td height="30">&nbsp;</td> <td>&nbsp;</td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td width="50" rowspan="2">&nbsp;</td> <td width="900" valign="top"><? if($page != NULL && is_file('page/'.$page.'.include.php')) { include('page/'.$page.'.include.php'); }else{ include('page/index.include.php'); } ?><p> &nbsp;</p> <p> &nbsp;<p> <br /> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/Sans_fil.jpg" width="216" height="50"></td> </tr> <tr> <td background="../images/design_19.jpg"><div class="vente">&nbsp;</div> <p align="center"> <img border="0" src="images/prix/prix%20gris.gif" width="200" height="50"></p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td><div align="center"> <table width="175" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/topaffaire.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p align="center"> <img border="0" src="images/prix/prix%20copie.gif" width="200" height="50"></p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/vente_flash.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p align="center" style="margin-top: 0; margin-bottom: 0"> <img border="0" src="images/prix/prix%20gris.gif" width="200" height="50"></p></td> </tr> <tr> <td> <p style="margin-top: 0; margin-bottom: 0"><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/asaisir.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p align="center"> <img border="0" src="images/prix/prix%20copie.gif" width="200" height="50"></p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> </tr> </table> &nbsp;<p> <br /> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/Sans_fil.jpg" width="216" height="50"></td> </tr> <tr> <td background="../images/design_19.jpg"><div class="vente">&nbsp;</div> <p>&nbsp;</p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td width="217"><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/topaffaire.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p>&nbsp;</p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/vente_flash.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p>&nbsp;</p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/asaisir.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p>&nbsp;</p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> </tr> </table> <p>&nbsp;</p> <p> <br /> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/Sans_fil.jpg" width="216" height="50"></td> </tr> <tr> <td background="../images/design_19.jpg"><div class="vente">&nbsp;</div> <p>&nbsp;</p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/topaffaire.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p>&nbsp;</p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/vente_flash.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p>&nbsp;</p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> <td><div align="center"> <table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <img border="0" src="images/imagettes/asaisir.jpg" width="216" height="50"></td> </tr> <tr> <td background="images/design_19.jpg"><div class="vente">&nbsp;</div> <p>&nbsp;</p></td> </tr> <tr> <td><img src="images/design_21.jpg" width="216" height="11" /></td> </tr> </table> </div></td> </tr> </table> <p> <br /> </td> <td width="50" height="887" rowspan="2">&nbsp;</td> </tr> <tr> <td width="900" valign="top"> <table width="900" border="0" cellpadding="0" cellspacing="0" height="37"> <!--DWLayoutTable--> <tr> <td height="37" valign="bottom" width="900"> <div class="menu" dynamicanimation="fpAnimformatRolloverFP1" fprolloverstyle="color: #47A3F2" onmouseover="rollIn(this)" onmouseout="rollOut(this)" language="Javascript1.2"> <p align="center"> <a href="index.php?page=accueil">ACCUEIL</a> | <a href="index.php?page=service">SERVICE</a> | <a href="index.php?page=magasin">MAGASIN</a> | <a href="index.php?page=tarifs">TARIFS</a> | <a href="index.php?page=game">GAMER</a> | <a href="index.php?page=forum">FORUM</a> | <a href="index.php?page=contact">CONTACT</a></div></td> </tr> </table></td> </tr> <tr> <td height="24" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/design_22.jpg"> <!--DWLayoutTable--> <tr> <td width="1000" height="24">&nbsp;</td> </tr> </table> </td> </tr> </table> </body> </html>

par lux » 24 nov. 2007, 00:04

Heu tu peux poster le code de toute la page qu'on puisse se faire une idée ? Pasque la ...

par pertusien » 24 nov. 2007, 00:01

en faite ça marche lorsque je mes dans une page vierge mais des que je rajoute le code suivant dans le haut de ma page pour l'include des page de mon sites le random ne fonctionne plus et plus rien ne s'affiche

<? if($page != NULL && is_file('page/'.$page.'.include.php'))
  {
   include('page/'.$page.'.include.php');
  }else{
   include('page/index.include.php');
  }
 ?>

par lux » 23 nov. 2007, 23:50

Je viens de tester ça :
<?php  

$random = rand(1,10);  

$test = 'page/page'.$random.'.php';
echo $test;  

?> 
Ça écrit bien une page au hasard à charger. Donc ça doit marcher. Tu as bien 10 pages exactement ?? (de plus, recharge la page plusieurs fois, c'est un random, dès fois il fait 6,6,7,6,7,6,3,4 ....)

par pertusien » 23 nov. 2007, 22:17

j'ai mis

PHP:
<?php

$random = rand(1,2);

include('pages/page'.$random.'.php');

?>


j'ai mis la page: page1.php et page2.php dans le dossier pages

mais c'est une page tout blanc qui s'affiche





Mais dans ma page j'ai deja ça qui si trouve:

<? if($page != NULL && is_file('page/'.$page.'.include.php'))
  {
   include('page/'.$page.'.include.php');
  }else{
   include('page/index.include.php');
  }
 ?>