IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Session perdue d'une page à l'autre


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    58
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 58
    Par défaut Session perdue d'une page à l'autre
    Bonjour,

    Je suis entrain de faire un système de panier avec des sessions

    le problème est que dès que je passe sur visuel.php mon $_SESSION['idCommande'] est vide.
    Je vous laisse les codes sources

    plus.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
     
    <?php  session_start(); ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <link rel="stylesheet" media="screen" type="text/css" title="Design" href="design/index.css" />
     
    <title>A propos </title>
    </head>
     
    <body>
    <img src="images/header.gif" width="1140px">
     
    <?php
     
    include("fonctions-panier.php");
    include("fonction-bdd.php");
    $dom = new DomDocument();
    $dom->load('Surcouf.xml');
    $listeId_Produit = $dom->getElementsByTagName('id_Produit');
    $listeLibelle_Produit = $dom->getElementsByTagName('Libelle-Produit');
    $listeURL_Visuel = $dom->getElementsByTagName('URL_Visuel');
    $listePrix_Barre = $dom->getElementsByTagName('Prix_Barre');
    $listePrix_Remise = $dom->getElementsByTagName('Prix_Remise');
    $liste__Remise = $dom->getElementsByTagName('__Remise');
    $listeimage = $dom->getElementsByTagName('IMG');
    $listePrix = $dom->getElementsByTagName('Prix');
    $image =array();
    $Libelle_Produit =array();
    $URL_Visuel =array();
    $Prix_Barre =array();
    $Prix_Remise =array();
    $__Remise =array();  
    $id = $_GET['id'];
    $k = base64_decode($_GET['k']);
    $R = array();
    $R =NULL;
     
    for($i=1; $i<=5; $i++){
    	while($R[$i] == NULL){
    		$nb= rand(0,9);
    		if($nb != $id && $nb!=$R[1] && $nb!=$R[2] && $nb!=$R[3] && $nb!=$R[4] && $nb!=$R[5]){
    			$R[$i] = $nb;
    		}
    	}
    }
    if(isset($_GET['action'])){
    	$erreur=false;
     	if(in_array( $_GET['action'],array('ajout', 'suppression', 'refresh'))){
      		$action = $_GET['action'];}
     	else{
     		$erreur=true;}
    	$l = preg_replace('#\v#', '', base64_decode($_GET['l']));
     
     	 $q = intval($_GET['q']);
     
    	 $p = floatval(base64_decode($_GET['p']));
     
     
    }
    elseif(isset($_POST['action'])){
     	unset($_GET);
     	$erreur=false;
     
     	if(in_array($_POST['action'],array('ajout', 'suppression', 'refresh')))
      	$action=$_POST['action'];
     	else
      	$erreur=true;
     
      	$l = preg_replace('#\v#', '',base64_decode($_POST['l']));
     
     	$p = floatval(base64_decode($_POST['p']));
     
    	$QteArticle = array();
     
     	$i=0;
    	foreach ($_POST['QteArticle'] as $contenu){
      	$QteArticle[$i++] = intval($contenu);
    	}
    }
    if ($erreur==false){
     
     switch($action){
     
      Case "ajout":
      	ajouterArticle($l,$q,$p);
       	if($_SESSION['idCommande'] == NULL){
       		Ajout_Commande();
       		Ajout_Article($l,$q,$p);
       		$k = $k + 1;}
       else{	
     
       		Ajout_Article($l,$q,$p);
       		$k = $k + 1;
       	}
      	break;
     
      Case "suppression":
      supprimerArticle($l);
      break;
     
      Case "refresh" :
     
      for ($i = 0 ; $i < count($QteArticle) ; $i++)
      {
        modifierQTeArticle($_SESSION['panier']['libelleProduit'][$i],round($QteArticle[$i]));
      }
      break;
     
      Default:
      break;
     
     }
    }
    ?>
    <form method="post" action="plus.php">
     
    <table cellspacing="35px;">
    	<tr>
     
    		<td>
    			<fieldset style="width:300px; padding-top:15px; ">
    				<center>
    					<span style="font-size:14px; color: rgb(153,153,153); ">
    						<strong>Total de votre panier : <?php echo MontantGlobal(); ?> &euro;</strong><br>
    						<strong>Nombre d'article : <?php echo $k ?> </strong>
    					</span>
    				</center>
    			</fieldset>
    			<fieldset style="width:300px; padding-top:15px; ">
    				<center>
    					<strong><?php echo $listePrix->item($id)->firstChild->nodeValue; ?> <br/></strong><br>
    					<a href="plus.php?action=ajout
    					&amp;l=<?php echo base64_encode($listeId_Produit->item($id)->firstChild->nodeValue); ?>&amp;q=1&amp;p=<?php echo base64_encode($listePrix->item($id)->firstChild->nodeValue); ?>
    					&amp;id=<?php echo $id; ?>&amp;k=<?php echo base64_encode($k); ?>">
    					<img src="images/panier2.gif" border ="0"/></a><br/><br/>
    					<a href="visuel_panier.php"><img src="images/mon_panier.gif" border="0"></a><br/><br/>
    					<span style="font-size:12px; color: rgb(153,153,153); ">
    					<strong>Exp&eacute;di&eacute; sous 24h</strong>
    					</span>
    				</center>
    			</fieldset>
    		</td>
    	</tr>
    </table>
     
    <br/>	
     
    <br/>
    <center>
    	<fieldset>
    		<table cellpadding="10px">
    			<tr>
    			<?php
    				for($i = 1; $i<=5; $i++){
    					echo "<td width='200px;'>
    							<table >			
    								<tr>
    									<div class='hautPackage'>
    									<strong>Package num&eacute;ro $i</strong>
    									</div>
    								</tr>
    								<tr>
    									<div class='package'>
    										<a href=plus.php?id=".$R[$i]."&k=".base64_encode($k)." style='color: black; text-decoration:none;'>
    										<strong>".$listeLibelle_Produit->item($R[$i])->firstChild->nodeValue."</strong></a><br>
    										<span style='font-size:12px; color: rgb(153,153,153);'>Type du package</span><br/><br/>
    										<a href='".$listeURL_Visuel->item($R[$i])->firstChild->nodeValue."' style='text-decoration:none;' target=_blank >
    										<img src=".$listeimage->item($R[$i])->firstChild->nodeValue." width='150px;' border=0/></a>
    										<br/>
    										<a href=plus.php?id=".$R[$i]."&k=".base64_encode($k)." style='font-size:12px; color: black; float:right; text-decoration:none;'> <strong>>> En savoir plus </strong></a><br/>
    									</div>
    								</tr>
    				    		</table>
    						  </td>";
    				}
    			?>		
    			</tr>
    		</table>
    	</fieldset>
    </center>
     
    </form>
    </body>
    </html>
    fonction-bdd.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
     
    include("connectdb.php");
    function Ajout_Commande(){
    	$a = new connectDb("", "", "", "");
    	$date = date("Y-m-d");
    	$SQL_Commande = "INSERT INTO `surcouf`.`CMMD_Commande` "." (`CMMD_IdCommande` ," .
    			""."`CLNT_IdClient`,"."`CMMD_Date-Commande`,"."`CMMD_Flag`)
    		    "." VALUES ("."NULL ,"." NULL,"." '$date',"." '0');";
    		$resultat = mysql_query($SQL_Commande) or die("Erreur SQL".$SQL_Commande."<br />".mysql_error());
    		$test = mysql_insert_id();
    		$_SESSION['idCommande'] = $test;
    		mysql_close();
    }	
     
    function Ajout_Article($libelleProduit,$qteProduit,$prixProduit){
    	$a = new connectDb("", "", "", "localhost");
    	$truc = $_SESSION['idCommande'];
    	echo $SQL_Article = "INSERT INTO `surcouf`.`ARTC_Article` "." (`ARTC_IdArticle` ," .
    			""."`CMMD_IdCommande`,"."`ARTC_Libelle`,"."`ARTC_SKU`,"."`ARTC_Num-Commande`, "."`ARTC_Prix`)
    		    "." VALUES ("."NULL ,"." '$truc',"." '$libelleProduit',"." NULL, NULL,"."'$prixProduit');";
    		$resultat = mysql_query($SQL_Article) or die("Erreur SQL".$SQL_Article."<br />".mysql_error());
    		mysql_close();
    }
    function Afficher_panier(){
     
    	echo "session".$_SESSION['idCommande'];
    	$a = new connectDb("", "", "", "localhost");
     
    	//echo "idcommande".$idcommande = $_SESSION['idCommande'];
    	echo $SQL_Panier = "SELECT * FROM ARTC_Article WHERE CMMD_IdCommande = '$id_commande';";
    	$resultat = mysql_query($SQL_Panier)or die("ERREUR SQL".$SQL_Panier."<br>".mysql_error());
    	$tableau_liste_panier = array ();
    	$i = 0;
    		while ($ligne = mysql_fetch_array($resultat, MYSQL_ASSOC)){
    			$tableau_liste_panier[$i] = $ligne;
    			$i ++;}
    		mysql_close();
    		return $tableau_liste_panier;
    }
     
     
     
    ?>
    visuel.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <?php
     
    include("fonction-bdd.php");
    echo "session html".$_SESSION['idCommande'];
    //$idcommande = base64_decode($_GET['idcommande']);
    ?>

  2. #2
    jnore
    Invité(e)
    Par défaut
    Bonjour,

    Sur chaque page qui utilise les sessions, il faut impérativement faire un session_start() en début de script!

    L'as-tu fait?

    Dans le cas de visuel.php, cela doit donner:
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    <?php
    session_start();
    include("fonction-bdd.php");
    echo "session html".$_SESSION['idCommande'];
    //$idcommande = base64_decode($_GET['idcommande']);
    ?>

Discussions similaires

  1. variables de session non conservées d'une page à l'autre
    Par titemimine dans le forum Langage
    Réponses: 10
    Dernier message: 04/06/2010, 16h29
  2. Réponses: 1
    Dernier message: 18/02/2010, 13h17
  3. [MySQL] Session qui ne reste pas d'une page à l'autre
    Par nO_life dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 22/11/2008, 16h07
  4. Réponses: 2
    Dernier message: 06/09/2007, 09h23
  5. Perte de Session d'une page à l'autre
    Par Flam dans le forum Langage
    Réponses: 3
    Dernier message: 15/03/2006, 14h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo