Conflit avec if ($file == "xxx") require...

PouiF Messages postés 2 Date d'inscription samedi 12 mars 2005 Statut Membre Dernière intervention 24 avril 2005 - 24 avril 2005 à 13:45
cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 - 24 avril 2005 à 14:04
Bonjour les amis zéros original.gif



Je suis actuellement entrain de faire mon site et cette requete a toujours marché, ce code ce trouve dans requete.php:

PHP Code

<?

if ($file == "Memberz") {

require ("Memberz.php");

}

elseif ($file == "Warz") {

require ("Warz.php");

}

elseif ("index.php?file=news") {

require ("News.php");

}

?>





mais quand je fais un include vers un script d'info serveur SWAT4 (un
jeu), il met met ces 2 erreurs pour ce qui est de mes requete, ce code
se trouve dans s4/index.php:

PHP Code

<?

//Show all errors...

error_reporting(E_ALL);



//Include configuration file

include 'config.php';



//Various functions:

function GetItemInfo ($itemname, $itemchunks) {



$retval = "-";

for ($i = 0; $i < count($itemchunks); $i++) {

//Found this item

if (strcasecmp($itemchunks[$i], $itemname) == 0) $retval = $itemchunks[$i+1];

}

//Return value

return $retval;

}



function GetMinutes($seconds) {

$timemins = intval($seconds / 60);

$timesecs = ($seconds % 60);



$Reqlength = 2; //Amount of digits we need

if
($Reqlength-strlen($timemins) > 0) $timemins =
str_repeat("0",($Reqlength-strlen($timemins))) . $timemins;

if
($Reqlength-strlen($timesecs) > 0) $timesecs =
str_repeat("0",($Reqlength-strlen($timesecs))) . $timesecs;

return $timemins . ":" . $timesecs;

}



function FormatName( $ServerName ) {



$ServerName = ereg_replace("\[.\]","", $ServerName );

$array= explode( "[c=", $ServerName );

$name = "";



if ( count( $array ) == 1 ){return $ServerName;}



for($i=0;$i<count($array);$i++){

$array[$i] = substr_replace ( $array[$i],"",6,1 );

}



for($i=0;$i<count($array);$i++){

$array2 = explode("", $array[$i]);

if ( count( $array2 ) == 1 )

{

$name.= $array2[0];

} else {

$name .="";



for($j=1;$j<count($array2);$j++){$name.=$array2[$j];}

$name.="</s>";

}

}

return $name;

}



function GetServerName() {

global $servername;



//custom servername?

if (strlen($servername) > 0) {

return $servername;

} else {

return "Swat 4 PHP Server Query";

}

}

//End functions



?>



<html>

<head>

<LINK href="/stylewar.css" type=text/css rel=stylesheet>



<meta name="description" content="<?=$query_meta_description;?>">

<meta name="keywords" content="<?=$query_meta_keywords;?>">



</head>



<?

$txtip = $defaultip;



// add 1 to join port to get query port

$txtportnum = $defaultport + 1;



//If there is no IP, return (exit)

if (strlen($txtip) == 0) return;



?>

<?

//Open UDP socket to server

$sock = fsockopen("udp://" . $txtip, $txtportnum, $errno, $errstr,4);

//Check if we have a socket open, if not, display error message

if (!$sock) {

echo "$errstr ($errno)\n";

exit;

}

{

fputs($sock,"\\status\\");

$gotfinal = False;

$data = "";

//Set starttime, for possible loop expiration, so the server doesn't
get too much work.

$starttime = Time();

//Loop until final packet has been received.

while(!($gotfinal == True || feof($sock))) {

//Get data
if(($buf fgetc($sock)) FALSE) {

usleep(100); // wait for additional data? :S whatever

}

//Add to databuffer

$data .= $buf;

//Check if final item (queryid) has been received

if (strpos($data,"final\\") != False) {

$gotfinal = True;

}

//Protect webserver against massive loop.

if ((Time() - $starttime) > 5) {

echo "Data receiving took too long. Cancelled.";

$gotfinal = True;

}

}

//Close socket

fclose ($sock);

//Split chunks by \

$chunks = split('[\]', $data);

?>

<table width="100%" align="center">

----,

<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"
align=\"default\" class=\"tableclass\">

----

Name:,

&nbsp;

<?

// Check to see if server is in reloading state

$query_host_name = getiteminfo("hostname",$chunks);

if ($query_host_name ==
"-")

{

echo "...server is reloading";

} else {

$query_host_name = FormatName( $query_host_name );

echo $query_host_name;

}

?>,

----

Mapname:,

&nbsp;&nbsp;<?=getiteminfo("mapname",$chunks);?>,

----

Gametype:,

&nbsp;&nbsp;<?=getiteminfo("gametype",$chunks);?>,

----

Server IP:,

&nbsp;&nbsp;<?=$txtip;?>:<?=$defaultport;?>,

----

Players:,

&nbsp;&nbsp;<?=getiteminfo("numplayers",$chunks);?>
/ <?=getiteminfo("maxplayers",$chunks);?>


</td>

</tr>

</table>

</td>

</tr>

</table>

<?

}

?>



</HTML>





Voici les 2 erreurs:



QUOTE

Notice: Undefined variable: page in /secu/teamfr/x-seven/requete.php on line 2



Notice: Undefined variable: page in /secu/teamfr/x-seven/requete.php on line 5





Hors, quand j'enleve l'include vers s4/index.php, tout marche parfaitement



Que faire?



PS: le but de la requete était que si on arrive sur index.php, que
news.php apparaisse et que si j'arrive par exemple sur
index.php?file=Warz , le contenu qui se trouve dans Warz.php apparaisse
a la place de News.php



Merci d'avance pour l'aide

PouiF un jour,
PouiF Toujours ...
A voir également:

3 réponses

cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 8
24 avril 2005 à 13:55
Salut,



condense ton code....



Ensuite remplace <? par <?php



je vois "if($file=='machin')"



si ton $file provient de l'url il faut utiliser if(isset($_GET['file']) AND $_GET['file']==='machin'))

<hr size="2" width="100%">




<li>Entraide, dépannage et vulgarisation informatique: Mon site de vulgarisation informatique</li>
0
PouiF Messages postés 2 Date d'inscription samedi 12 mars 2005 Statut Membre Dernière intervention 24 avril 2005
24 avril 2005 à 14:01
j'ai pas très bien comprit l'histoire de



if(isset($_GET['file']) AND $_GET['file']==='machin'))


es-ce possible de me faire un exemple stp?
PouiF un jour,
PouiF Toujours ...
0
cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 8
24 avril 2005 à 14:04
$_GET ce sont les variables provenant de l'url



par exemple : page.php?variable=test&variable2=machin



$_GET['variable'] renverra "test" et $_GET['variable2'] renverra "machin"



ensuite tu utilises isset pour savoir si la variable existe (sinon ça
renverra une erreur de undefined variable si ton PHP est bien
configuré, c'est à dire peu permissif)

<hr size="2" width="100%">




<li>Entraide, dépannage et vulgarisation informatique: Mon site de vulgarisation informatique</li>
0
Rejoignez-nous