problème de session

Nouveau WRInaute
Edit zecat : merci de mettre le code dans les balises code. Je l'ai fait pour toi. Je le referais pas ..

Bonjour,

Voilà gros problme avec les sessions je sais ce n'est pas nouveau, mais je ne comprend rien car dans un cas de figure
ca fonctionne très bien et dans l'autre rien.

SVP un coup de main ca fait deux jours que j'essaie de me dé......patouiller et là je ne vois pas la solution.
Merci d'avance.


Trois scripts ou les sessions fonctionnent bien login.php verif.php et recupsession.php
FICHIER login.php
un formulaire

Code:
<html>
  <head>
  <title>PAGE UNE</title></head>
  <body>
<form name="form" action="verif.php" method='post' enctype="multipart/form-data">
  <table align="center" border="0">
    <tr> 
      <td>Login :</td>
      <td><input type="text" name="LOGIN" maxlength="250"></td>
    </tr>
    <tr> 
      <td>Password</td>
      <td><input type="password"name="PASS" maxlength="10"></td>
    </tr>
    <tr> 
      <td>Num&eacute;ro de secu</td>
      <td><input type="text" name="NUM_SS"></td>
    </tr>
    <tr> 
      <td>ID</td>
      <td><input type="text" name="ID_ADMIN"></td>
    </tr>
    <tr> 
      <td>Nom</td>
      <td><input type="text" name="NOM"></td>
    </tr>
    <tr> 
      <td colspan="2" align="center"><input type="submit" value="log in"></td>
    </tr>
  </table>
</form> 
   </body>
</html>

FICHIER verif.php
recupération du formulaire de login.php

Code:
<?php require_once('../../../Connections/iupaic.php'); ?>
<?php
extract($_POST);
// je recupère toutes les données saisies dans login.php
$_SESSION['LOGIN'] = $LOGIN;
$_SESSION['PASS'] = $PASS;
$_SESSION['NUM_SS'] = $NUM_SS;
$_SESSION['ID_ADMIN'] = $ID_ADMIN;
$_SESSION['NOM'] = $NOM;
?>
<html>
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form2" enctype="multipart/form-data" method="post" action="recupsession.php" >
  <input type="file" name="zoro">
  <input type="submit" name="Submit" value="Envoyer">
</form>
</body>
</html>

fichier recupsession.php

Code:
<?php 
extract($_POST);
// je recupère le chemin de mon fichier saisi dans verif.php
echo $zoro;
$_SESSION['essai'] = $zoro;
?>
<html>
<head>
<title>recup session</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<!-- ici j'ai bien tout-->
<?php
echo $LOGIN;
echo $PASS;
echo $NUM_SS;
echo $ID_ADMIN;
echo $NOM;

echo $zoro;
session_destroy();
?>
</body>
</html>

Dans ces trois scripts tout onctionne bien je récupère bien les infos que je fais circuler à l'aide de session
par contre ppour la suite ce n'est pas pareil.



Tous ces scripts ont été dévelppés avec DEAMWEAVER MX
FICHIER ajout.php

Code:
<?php require_once('../../../Connections/iupaic.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO equipe_administrative (ID_ADMIN, NOM, NUM_SS) VALUES (%s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS['ID_ADMIN'], "int"),
                       GetSQLValueString($HTTP_POST_VARS['LOGIN'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['NUM_SS'], "text"));

  mysql_select_db($database_iupaic, $iupaic);
  $Result1 = mysql_query($insertSQL, $iupaic) or die(mysql_error());

  $insertGoTo = "ajoutimag.php";
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_iupaic, $iupaic);
$query_admin = "SELECT ID_ADMIN FROM equipe_administrative ORDER BY ID_ADMIN DESC";
$admin = mysql_query($query_admin, $iupaic) or die(mysql_error());
$row_admin = mysql_fetch_assoc($admin);
$totalRows_admin = mysql_num_rows($admin);
// je fais une lecture pour récupérer le dernier enregistrement 
$i = $row_admin['ID_ADMIN'];
$i++;
echo $i;
?>
<html>
<head>
<title>CREATION D'UNE PERSONNE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='Le champ '+nm+' doit contenir une adresse e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='Le champ '+nm+' doit contenir un nombre.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' doit contenir un nombre entre '+min+' et '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += 'Le champ '+nm+' doit être rempli.\n'; }
  } if (errors) alert(' Les erreurs suivantes se sont produites :\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<body class="fondecran">
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline"> 
      <td nowrap align="right">ID_ADMIN:</td>
      <td><input type="text" name="admin" value="<?php echo $i;?>" size="32"></td>
    </tr>
    <tr valign="baseline"> 
      <td nowrap align="right">NOM:</td>
      <td><input type="text" name="NOM" value="" size="32"></td>
    </tr>
    <tr valign="baseline"> 
      <td nowrap align="right">NUM_SS:</td>
      <td><input type="text" name="secu" value="" size="32"></td>
    </tr>
    <tr valign="baseline"> 
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insérer l'enregistrement"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
  
</body>
</html>
<?php
mysql_free_result($admin);
?>

Fichier ajoutimag.php

Code:
<?php require_once('../../../Connections/iupaic.php'); ?>
<?php

// //dans ce sript j'ai essayé de placer ici
echo "coucou de depart";
extract($_POST);
echo $secu;
echo $admin;
echo $NOM;
$_SESSION['secu']=$secu;
$_SESSION['admin']=$admin;
$_SESSION['NOM']=$NOM;
echo "coucou fin";
//  //

$colname_ajoutimag = "1";
if (isset($HTTP_POST_VARS['id'])) {
  $colname_ajoutimag = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['id'] : addslashes($HTTP_POST_VARS['id']);
}

// //dans ce sript j'ai essayé de placer là
echo "coucou de depart";
extract($_POST);
echo $secu;
echo $admin;
echo $NOM;
$_SESSION['secu']=$secu;
$_SESSION['admin']=$admin;
$_SESSION['NOM']=$NOM;
echo "coucou fin";
//  //

mysql_select_db($database_iupaic, $iupaic);
$query_ajoutimag = sprintf("SELECT ID_ADMIN, NOM, DOSSIER_PHOTO, NUM_SS FROM equipe_administrative WHERE ID_ADMIN = %s", $colname_ajoutimag);
$ajoutimag = mysql_query($query_ajoutimag, $iupaic) or die(mysql_error());
$row_ajoutimag = mysql_fetch_assoc($ajoutimag);
$totalRows_ajoutimag = mysql_num_rows($ajoutimag);

// //dans ce sript j'ai essayé de placer là
echo "coucou de depart";
extract($_POST);
echo $secu;
echo $admin;
echo $NOM;
$_SESSION['secu']=$secu;
$_SESSION['admin']=$admin;
$_SESSION['NOM']=$NOM;
echo "coucou fin";
//  //

?>
<html>
<head>
<title>Dossier photo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#CC0000">
<table width="75%" border="0 " align="center" dwcopytype="CopyTableCell">
  <tr> 
    <td align="center"> 
	  <form name="form" method="post" action="../Uploadfichier/page_receptrice2.php" enctype="multipart/form-data">
	  <?php extract($_POST);

// //dans ce sript j'ai essayé de placer là
echo $secu;
echo $admin;
echo $NOM;
$_SESSION['secu']=$secu;
$_SESSION['admin']=$admin;
$_SESSION['NOM']=$NOM;
// //

mais rien ne fonctionne, je ne récupére rien
Code:
?>
        <font color="#CC6600" size="4">Veuillez s&eacute;lectionner l'image &agrave; 
        charger :</font><font color="#CC9900"> 
        <input type="file" name="aFile" />
        <input type="submit" name="submitFile" value="Envoyer le fichier" />
        </font> 
      </form>
		</td>
  </tr>
  <tr> 
    <td align="center"><a href="../Formulaire/formulairegene.php">Retour au Menu 
      Formulaire</a><a href="administratif.php">Menu Administratif</a> 
	  <a href="../../../index.php">Retour &agrave; l'Accueil</a></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($ajoutimag);
?>
[/code][/quote]
 
Nouveau WRInaute
probleme session php

bonjour fredsoft,
je ne me sert pas de session_start(); mais de extract); ca fonctionne tres bien dans le cas simple d'un fomulaire, mais dans l'autre cas je vais d'abord chercher le dernier inscrit par un select (bref j'utilise une Bdd).
J'avais d'abord essayé aves session_start(); mais ca ne fonctionnait pas pourquoi mystère c'est en allant sur des forum que j'ai vu ce code, après l'avoir testé j'ai remaqué que lui au moins il me restituait mes variables tout au long donc je l'ai utilisé pour mon applcation. Voilà
 
Discussions similaires
Haut