8791 sujets

Développement web côté serveur, CMS

Bonjour a tous!

Je voudrais comprendre comment faire pour faire disparaitre le message d'erreur dans mon code ci-dessous. lorsque j'execute la page,on m'affiche un message d'erreur.
Message d'erreur: Notice: Undefined index: var in c:\easyphp\www\site\variable.inc.php on line 2
NB: Je suis débutant donc soyez indulgent SVP!

<?php
$var=$_GET['var'];
switch ($var) {
  case "historique" :
   	 $page="historique.inc.php";
  	 break;
	 
  case "mission" :
   	 $page="mission.inc.php";
  	 break;
	 	 
  case "mot" :
   	 $page="lemot.inc.php";										  
  	 break;
 
 case "organe" :
   	 $page="organe.inc.php";										  
  	 break;
	 
 case "attribution" :
   	 $page="attribution.inc.php";										  
  	 break;
   
   case "structures" :
   	 $page="structures.inc.php";
  	 break;
	 
   case "cooperation" :
   	 $page="cooperation.inc.php";
  	 break;
 
  case "admission" :
   	 $page="admission.inc.php";
  	 break;
	 
	   case "admission2" :
   	 $page="admission2.inc.php";
  	 break;

  case "direct" :
   	 $page="direct.inc.php";
  	 break;
   
  case "prof" :
   	 $page="prof.inc.php";
  	 break;
  
  case "etranger" :
   	 $page="etranger.inc.php";
  	 break;

  case "resultat" :
   	 $page="resultat.inc.php";
  	 break;
 
  case "inscription" :
   	 $page="inscription.inc.php";
  	 break;
 
  case "f_initiale" :
   	 $page="f_initiale.inc.php";
  	 break;

  case "f_continue" :
   	 $page="f_continue.inc.php";
  	 break;
   
  case "contacts" :
   	 $page="contacts.inc.php";
  	 break;
  
  case "ecrire" :
   	 $page="ecrire.inc.php";
  	 break;

case "actualite" :
   	 $page="actualite.inc.php";
  	 break;	 
  default :
  	$page="accueil.inc.php";
  	 
} ?>
Bonjour,
je pense que tu écris
$var=$_GET['var'];
mais que le paramètre "var" n'arrive pas via get.

du devrais tester cette valeur:

$var = 'valeur par défaut';
if( isset($_GET['var']) )
      $var=$_GET['var'];
Merciiiii Beaucoup sa marche a moitié. Lol
Ci-dessous le code modifier(cette page est nommé: variable.inc.php).
J'ai une autre page accueil.php où j'appelle ensuite la page variable.inc.php avec la fonction <?php require_once('variable.inc.php'); ?>. Aussi j'appelle la variable $page comme ceci:
<?php require($page); ?> mais lorsque j'execute j'obtient un message 'erreur: Notice: Undefined variable: page in c:\easyphp\www\site\accueil.php on line 307
Fatal error: main(): Failed opening required '' (include_path='.;C:/EasyPHP\php\pear\') in c:\easyphp\www\site\accueil.php on line 307
NB: la ligne 307 est: <td valign="top"><?php require($page); ?></td>

Page variable.in.php
<?php
[i]if( isset($_GET['var']) ) {
$var=$_GET['var'];[/i]
switch ($var) {
  case "historique" :
   	 $page="historique.inc.php";
  	 break;
	 
  case "mission" :
   	 $page="mission.inc.php";
  	 break;
	 	 
  case "mot" :
   	 $page="lemot.inc.php";										  
  	 break;
 
 case "organe" :
   	 $page="organe.inc.php";										  
  	 break;
	 
 case "attribution" :
   	 $page="attribution.inc.php";										  
  	 break;
   
   case "structures" :
   	 $page="structures.inc.php";
  	 break;
	 
   case "cooperation" :
   	 $page="cooperation.inc.php";
  	 break;
 
  case "admission" :
   	 $page="admission.inc.php";
  	 break;
	 
	   case "admission2" :
   	 $page="admission2.inc.php";
  	 break;

  case "direct" :
   	 $page="direct.inc.php";
  	 break;
   
  case "prof" :
   	 $page="prof.inc.php";
  	 break;
  
  case "etranger" :
   	 $page="etranger.inc.php";
  	 break;

  case "resultat" :
   	 $page="resultat.inc.php";
  	 break;
 
  case "inscription" :
   	 $page="inscription.inc.php";
  	 break;
 
  case "f_initiale" :
   	 $page="f_initiale.inc.php";
  	 break;

  case "f_continue" :
   	 $page="f_continue.inc.php";
  	 break;
   
  case "contacts" :
   	 $page="contacts.inc.php";
  	 break;
  
  case "ecrire" :
   	 $page="ecrire.inc.php";
  	 break;

case "actualite" :
   	 $page="actualite.inc.php";
  	 break;	 
  default :
  	$page="accueil.inc.php";
	} 
}
  	 
?>



Page accueil.php
<?php require_once('variable.inc.php'); ?>
<?php require_once('Connections/connect.php'); ?>
<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_connect, $connect);
$query_rs = "SELECT id_infos, date_jour, titre, resume, article, auteur, valide FROM actualite WHERE valide = 'Afficher' ORDER BY id_infos ASC";
$rs = mysql_query($query_rs, $connect) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" dir="ltr" lang="fr">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.Style13 {	color: #000
}
.Style217 {color: #FF6600}
.Style218 {	color: #009900;
	font-style: italic;
}
.Style3 {color: #FFFFFF}
.Style61 {
	font-family: Arial, Helvetica, sans-serif
}
body {
	background-repeat: no-repeat;
}
.Style123 {font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
}
.Style129 {font-size: 12px}
.Style92 {color: #006600;
	font-weight: bold;
}
.Style221 {
	font-family: 'Trebuchet MS', arial, verdana, 'sans serif';
	font-size: 12px;
}
.Style222 {font-family: 'Trebuchet MS', arial, verdana, 'sans serif'}
.Style223 {color: #FF0000}
.Style225 {
	font-family: 'Trebuchet MS', arial, verdana, 'sans serif';
	font-size: 10px;
}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<head>
	<title>ENA: ECOLE NATIONALE D'ADMINISTRATION</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="generator" content="SPIP" />
	<link rel="shortcut icon" href="squelettes/fav.ico" />
	<!-- Lien vers le backend pour navigateurs eclaires -->
	<link rel="alternate" type="application/rss+xml" title="Syndiquer tout le site" href="spip04ff.php?page=backend" />

	<!-- Ceci est la feuille de style par defaut pour le code genere par SPIP -->
	<link rel="stylesheet" href="dist/spip_style.css" type="text/css" media="all" />
	<!-- Feuille de styles CSS pour l'affichage du site sur ecran -->
	<link rel="stylesheet" href="dist/habillage.css" type="text/css" media="projection, screen, tv" />
	<!-- Feuille de styles CSS pour l'impression -->
	<link rel="stylesheet" href="dist/impression.css" type="text/css" media="print" />
	<!-- feuilles de styles de la page -->
		
	
	<!-- style fr -->
	<link rel="stylesheet" href="squelettes/style.css" type="text/css" media="all" />
	
</head>
	<body>
<!-- conteneur - fond de la page en dégradé -->
<table class="corps" height="100%" cellspacing="0" cellpadding="0" width="1000" 
align="center" border="0">
  <tbody>
    <tr>
      <td background="images/degrade_gauche.gif" height="103">&nbsp;</td>
      <td width="900" rowspan="5" align="center" valign="top" bgcolor="#FFFFFF" class="txt12Noir"><div id="fenetre">
        <!-- conteneur de la page - fond blanc -->     
        <div id="c_page">
          <!-- conteneur de la page - padding interieur -->
          <table width="938" border="0" cellspacing="0" bgcolor="#D6F5D9" ">
          <tr>
            <td colspan="3"><div id="c_bandeau">
              <!-- logo et texte ENA -->
              <h1 class="disparu">ENA - Ecole Nationale d'Administratio </h1>
              <p><a name="retour_accueil_logo"  id="retour_accueil_logo"><span class="invisible">Accueil</span></a>
                  <!-- moteur de recherche et version langue -->
                  <!-- fin moteur de recherche et version langue -->
                  <img src="images/haut.png" alt="" width="940" height="120" /></p>
            </div></td>
          </tr>
          <tr>
            <td colspan="3"  bgcolor="#333333"></td>
          </tr>
          <tr>
            <td width="460" rowspan="2"><div id="image_glpi"> <span class="invisible"> </span>
                  <script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','460','height','200','src','flash/index','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','bgcolor','#00FF33','movie','flash/index' ); //end AC code
                </script>
                  <noscript>
                  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="460" height="200">
                    <param name="movie" value="flash/index.swf" />
                    <param name="quality" value="high" /><param name="BGCOLOR" value="#00FF33" />
                    <embed src="flash/index.swf" width="460" height="200" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#00FF33"></embed>
                  </object>
                  </noscript>
            </div></td>
            <td width="196" valign="top" bgcolor="#FCF8EC"><span class="breves Style223" ><strong>Fash Info &gt;&gt;</strong></span>&nbsp;</span></td>
            <td width="233" valign="top" bgcolor="#FCF8EC">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2" valign="top" bgcolor="#FCF8EC"><div id="c_texte_deifle">
              <marquee behavior="scroll" direction="down" scrollamount="1" scrolldelay="15" onmouseover="this.stop();" onmouseout="this.start();">
              <?php do { ?>
              <table width="490" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="middle" class="Style13"><div align="left" class="Style81 Style63 Style61 Style82 Style85">
                      <div align="left"><span class="Style92"><img src="images/new.gif" alt="" width="31" height="12" /> <span class="Style221"><?php echo $row_rs['titre']; ?></span><span class="Style221"></span></span></div>
                  </div></td>
                </tr>
                <tr>
                  <td height="18" valign="top"><div align="left" class="Style221"><?php echo $row_rs['resume']; ?></div></td>
                </tr>
                <tr>
                  <td height="14" valign="middle"><a href="suite.php?id_infos=<?php echo $row_rs['id_infos']; ?>" target="_blank" class="Style222 Style129 Style129">(<em>Suite...</em>)</a></a></td>
                </tr>
                <tr>
                  <td width="468" height="14" valign="middle"><span class="Style123">.........................................................................................................................................</span></td>
                </tr>
              </table>
                <?php } while ($row_rs = mysql_fetch_assoc($rs)); ?>
              </marquee>
            </div></td>
          </tr>
          
          <tr>
            <td colspan="3"><div id="c_baniere">
                <script language="JavaScript1.2" type="text/javascript">


//Specify the marquee's width (in pixels)
var marqueewidth="940px"
//Specify the marquee's height
var marqueeheight="20px"
//Specify the marquee's marquee speed (larger is faster 1-10)
var marqueespeed=2
//configure background color:
var marqueebgcolor="#003300"
//Pause marquee onMousever (0=no. 1=yes)?
var pauseit=1

//Specify the marquee's content (don't delete <nobr> tag)
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

var marqueecontent='<nobr><font size="2" face="Arial, Helvetica, sans-serif" color="#FFFFFF" ><b>ECOLE NATIONALE D\'ADMINISTRATION:</b></font>  <font size="2" face="Arial, Helvetica, sans-serif" color="#FFFFFF" ><b>&nbsp;La formation de l\'&eacute;lite ivoirienne... &nbsp;&nbsp;||&nbsp;Une administration au service du citoyen et qui pr&eacute;pare l\&rsquo;&eacute;conomie nouvelle...</b></font>  </nobr>'


////NO NEED TO EDIT BELOW THIS LINE////////////
marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
var actualwidth=''
var cross_marquee, ns_marquee

function populate(){
if (iedom){
cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
cross_marquee.innerHTML=marqueecontent
actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
}
else if (document.layers){
ns_marquee=document.ns_marquee.document.ns_marquee2
ns_marquee.left=parseInt(marqueewidth)+8
ns_marquee.document.write(marqueecontent)
ns_marquee.document.close()
actualwidth=ns_marquee.document.width
}
lefttime=setInterval("scrollmarquee()",20)
}
window.onload=populate

function scrollmarquee(){
if (iedom){
if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
else
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"

}
else if (document.layers){
if (ns_marquee.left>(actualwidth*(-1)+8))
ns_marquee.left-=copyspeed
else
ns_marquee.left=parseInt(marqueewidth)+8
}
}

if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div style="position:relative;width:'+marqueewidth+';height:'+marqueeheight+';overflow:hidden">')
write('<div style="position:absolute;width:'+marqueewidth+';height:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
write('<div id="iemarquee" style="position:absolute;left:0px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee" bgColor='+marqueebgcolor+'>')
write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
            </script>
              </div></td>
            </tr>
        </table>
        
 
          <div id="page">
            <!-- conteneur ht de la page -->
            <!-- conteneur contenu de la page -->
<div id="c_contenu">
              <!-- menu horizontal -->
              <div id="c_menu_vert">
                <!-- lien retour &agrave; l'accueil -->
                <a href="accueil2.php?var=accueil" title="accueil " id="retour_accueil" lang="fr" xml:lang="fr"><span class="invisible">Accueil</span></a>
                <ul id="menu_principal">
                  <li class="intitul Style3">
                    <?php include('date.inc.php'); ?>
                  </li>
                  <li class="intitule">G&eacute;n&eacute;bralit&eacute;s</li>
                  <li><a href="accueil2.php?var=historique" >Historique</a></li>
                  <li class="Style13"><a href="accueil2.php?var=mission">Missions</a></li>
                  <li><a href="accueil2.php?var=mot" >Mot du DG</a></li>
                  <li class="intitule">Organisation</li>
                  <li><a href="accueil2.php?var=organe" >Organes</a></li>
                  <li><a href="accueil2.php?var=attribution" >Attributions</a></li>
                  <li><a href="accueil2.php?var=structures" >Structures de formation</a></li>
                  <li><a href="accueil2.php?var=cooperation" >Coop&eacute;ration internationale</a></li>
                  <li class="intitule">Admisson</li>
                  <li><a href="accueil2.php?var=admission" >Admission</a></li>
                  <li><a href="#" >Dossier et candidature</a></li>
                  <ul type="square">
                    &nbsp;&nbsp;&nbsp;1.<a href="accueil2.php?var=direct" >Concours direct</a>
                  </ul>
                  <ul type="square">
                    &nbsp;&nbsp;&nbsp;2.<a href="accueil2.php?var=prof" >Concours professionnel</a>
                  </ul>
                  <ul type="square">
                    &nbsp;&nbsp;&nbsp;3.<a href="accueil2.php?var=etranger" >À titre &eacute;trangers</a>
                  </ul>
                  <li><a href="accueil2.php?var=resultat" >R&eacute;sultats</a></li>
                  <li><a href="accueil2.php?var=inscription" >Inscription en ligne</a></li>
                  <li class="intitule">Formation</li>
                  <li><a href="accueil2.php?var=f_initiale" >Formation initiale</a></li>
                  <li><a href="accueil2.php?var=f_continue" >Formation continue</a></li>
                  <li class="intitule">Nous saisir</li>
                  <li><a href="accueil2.php?var=contacts" >Contacts</a></li>
                  <li><a href="accueil2.php?var=ecrire" >Nous &eacute;crire</a></li>
                  <li class="intitule">Actualit&eacute;</li>
                  <li><a href="accueil2.php?var=actualite" >Informations</a></li>
                </ul>
              </div>
              <!-- fin menu horizontal -->
              <!-- contenu annonce-->
              <div id="c_contenu_rubrique" ><!-- contenu : annonce demandée + liste des annonces -->
                
                <table width="100%"  border="0" align="left" cellpadding="0" cellspacing="0">
                    <tr>
                    <td valign="top"><?php require($page); ?></td>
                  </tr>
                </table>
              </div>
              <div class="sep">gBB</div>
              <!-- fin contenu brèves -->
            </div>
            <!-- fin contenu de la page -->
          </div>
          <!-- conteneur pied de page - cadre arrondi -->
          <div id="c_pied">
            <h1 id="lien_admin">&nbsp;</h1>
            <h1 class="pied">&copy; copyright <span class="Style217">2012</span><span class="Style218"> ENA</span> <strong><a href="ecrire/index.html" title="ADMIN" lang="fr" xml:lang="fr">&nbsp;</a></strong>| Tous droits r&eacute;serv&eacute;s</h1>
            <h1 id="mentions"><span class="pied"> Sauf mention contraire, les documents publi&eacute;s sur le site sont plac&eacute;s sous licence<em> Ecole Nationale d'Administration</em>.</span><br />
            </h1>
          </div>
          <!-- SPIP-CRON -->
          <div style="background-image: url('spip1e29.gif?action=cron');"></div>
        </div>
      </div>
      <map name="Map" id="Map">
        <area shape="rect" coords="904,7,995,23" href="mailto:infounited@yahoo.fr" target="_blank" />
      </map>      </td>
      <td 
    background="images/degrade_droit.png">&nbsp;</td>
    </tr>
    <tr>
      <td height="40" background="images/degrade_gauche.gif"><img height="10" 
      src="images/gif_transparent.gif" width="32" /></td>
      <td background="images/degrade_droit.png"><img 
      height="10" src="images/gif_transparent.gif" 
      width="32" /></td>
    </tr>
    <tr>
      <td width="32" height="327" 
    background="images/degrade_gauche.gif">&nbsp;</td>
      <td width="32" 
    background="images/degrade_droit.png">&nbsp;</td>
    </tr>
    <tr>
      <td height="10" background="images/degrade_gauche.gif">&nbsp;</td>
      <td 
    background="images/degrade_droit.png">&nbsp;</td>
    </tr>
    <tr>
      <td height="36" background="images/degrade_gauche.gif">&nbsp;</td>
      <td 
    background="images/degrade_droit.png">&nbsp;</td>
    </tr>
  </tbody>
</table>
<p>&nbsp;</p>
	</body>
</html>
<?php
mysql_free_result($rs);
?>
Modérateur
Bonjour,

tu as différents problèmes
massbbc a écrit :
Notice: Undefined variable: page in c:\easyphp\www\site\accueil.php on line 307

Avec le isset $page n'est jamais initialisé si aucune variable var n'est passée dans l'url.

massbbc a écrit :
Fatal error: main(): Failed opening required '' (include_path='.;C:/EasyPHP\php\pear\') in c:\easyphp\www\site\accueil.php on line 307

L'include path utilise un slash UNIX dans un système windows. Vérifie dan ton php.ini que tout tes slash soit bien '\'. (include_path = ".;c:\ … ")

De plus selon ton code, les fichiers que tu inclus sont-ils bien dans le même dossier que le fichier dans lequel tu fais l'include_once

Sinon ton code est très long pour pas grand chose, voici un exemple amélioré:


// initialise $page par défaut:
$page = 'accueil.inc.php';
// si var est défini:
if( isset($_GET['var']) ) {
  $var=$_GET['var'];
  // On pourrait faire $page= $var.'inc.php' et vérifier avec file_exist mais cela peut poser des problèmes de sécurité.
  // Alors on définit les valeurs acceptées de $var à l'aide d'un tableau par exemple:
  $pages = array('historique','mission','lemot','attribution','structures');
  if (in_array($var, $pages)) $page = $var.'inc.php';
}

Modifié par kustolovic (21 May 2012 - 13:12)
Merci infiniment kustolovic pour tes conseil et pour le code. sa marche nikel.
Encore merci et vive le forum