Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/03/2013, 07:05
tonisaez
 
Fecha de Ingreso: mayo-2011
Mensajes: 9
Antigüedad: 13 años
Puntos: 0
Problema con varias sesiones en PHP

Hola!
Tengo una duda con el tema de sesinoes en PHP que no sé solucionar.
Estoy programando una tienda con Dreamweaver y tengo una sesión llamada "carrito" que me guarda los datos seleccionados (nombre del producto y precio del producto) y los coloca en la página resumen.php De esta manera cuando el comprador vuelve a trás puede seleccinoar otros productos y se van sumando. Hasta aquí bien.
Lo que quisiera hacer es que cuando el comprador ya tiene sus productos seleccionados y vaya a comprar, tenga que loggearse para que asocie sus datos a los productos seleccionados. Esto lo hago con la opción 'Conectar usuario' de Dreamweraver.
El problema es que cuando hago el link para que se loggeen y vuelvo para atrás, los productos seleccinoados en la sesión "carrito" se pierden y entonces el comprador debería volver a seleccinoarlos.
¿Existe alguna forma de que permanezcan estos datos cuando el usuario inicie su sesión?

Estos son los archivos utilizados: resumen.php e iniciarsesion.php:

resumen.php:
Código PHP:
<?php require_once('../../Connections/compra.php'); ?>
<?
session_start
();
if(isset(
$_SESSION['carrito'])){
    
$carrito_mio=$_SESSION['carrito'];
}

?>
<?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_ocolor$ocolor);
$query_r_noticias "SELECT *,DATE_FORMAT(fecha_noticias,'%d-%m-%Y') AS fecha_noticias FROM noticias";
$r_noticias mysql_query($query_r_noticias$ocolor) or die(mysql_error());
$row_r_noticias mysql_fetch_assoc($r_noticias);
$totalRows_r_noticias mysql_num_rows($r_noticias);

mysql_select_db($database_ocolor$ocolor);
$query_r_usuarios "SELECT * FROM usuarios";
$r_usuarios mysql_query($query_r_usuarios$ocolor) or die(mysql_error());
$row_r_usuarios mysql_fetch_assoc($r_usuarios);
$totalRows_r_usuarios mysql_num_rows($r_usuarios);

$colname_r_categorias "-1";
if (isset(
$_GET['id_categorias'])) {
  
$colname_r_categorias $_GET['id_categorias'];
}

$colname_r_productos "-1";
if (isset(
$_GET['id_categorias'])) {
  
$colname_r_productos $_GET['id_categorias'];
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Tienda Online</title>
<link href="../../Css/estilos.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
<link href="../../Css/estilos.css" rel="stylesheet" type="text/css" />
<style type="text/css"></style>
</head>
<body>
<div id="contenedor">
      <div id="centro">
        <form action="../../Wlibres/final.php" method="post">
        <table width="550" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td>
                  <table width="550" border="0" align="center" cellpadding="0" cellspacing="0" id="tb_result">
                <tr>
                  <td height="20" colspan="8">&nbsp;</td>
                  </tr>
                <tr>
                  <td height="20" colspan="8" align="center"><span class="Estilo8">Resumen del pedido </span></td>
                </tr>
                <tr>
                  <td height="20" colspan="8"><span class="Estilo1"></span></td>
                </tr>
                <tr>
                  <td width="5" bgcolor="#C5C5C5"><span class="Estilo1"></span></td>
                      <td width="202" height="20" bgcolor="#C5C5C5"><span class="Estilo5 Estilo1"><strong>Producto</strong></span></td>
                      <td width="82" height="20" align="center" bgcolor="#C5C5C5"><span class="Estilo5 Estilo1"><strong>Marca</strong></span></td>
                      <td width="76" height="20" align="center" bgcolor="#C5C5C5"><span class="Estilo5 Estilo1"><strong>Referencia</strong></span></td>
                      <td width="54" height="20" align="right" bgcolor="#C5C5C5"><span class="Estilo5 Estilo1"><strong>Precio</strong></span></td>
                      <td width="69" height="20" align="center" bgcolor="#C5C5C5"><span class="Estilo5 Estilo1"><strong>Cantidad</strong></span></td>
                      <td width="57" height="20" align="right" bgcolor="#C5C5C5"><span class="Estilo5 Estilo1"><strong>Total</strong></span></td>
                       <td width="5" align="right" bgcolor="#C5C5C5"><span class="Estilo1"></span></td>
                </tr>
                <?
                
if(isset($_SESSION['carrito'])){
                
$total=0;
                for(
$i=0;$i<=count($carrito_mio)-1;$i ++){
                if(
$carrito_mio[$i]!=NULL){
                
?>
                <tr>
                  <td width="5" valign="middle" bgcolor="#E1E1E1">&nbsp;</td>
                      <td height="50" valign="middle" bgcolor="#E1E1E1"><span class="Estilo8"><? print $carrito_mio[$i]['nombre_productos'];   ?></span></td>
                     <td height="50" align="center" valign="middle" bgcolor="#E1E1E1" class="Estilo1"><span class="Estilo1"><? print $carrito_mio[$i]['nombre_marcas'];   ?></span></td>
                     <td height="50" align="center" valign="middle" bgcolor="#E1E1E1" class="Estilo1"><span class="Estilo1"><? print $carrito_mio[$i]['referencia_productos'];   ?></span></td>
                     <td height="50" align="right" valign="middle" bgcolor="#E1E1E1" class="Estilo1"><span class="Estilo1"><? print $carrito_mio[$i]['precioparticular_productos'];   ?></span></td>
                      <td height="50" align="right" valign="middle" bgcolor="#E1E1E1" class="Estilo1"><span class="Estilo1"><? print $carrito_mio[$i]['cantidad'];   ?></span></td>
                      <td height="50" align="right" valign="middle" bgcolor="#E1E1E1" class="Estilo1"><span class="Estilo8">
                         <?  print $carrito_mio[$i]['precioparticular_productos'] * $carrito_mio[$i]['cantidad'];  ?>
                         <strong>&euro;</strong>
                       </span></td>
                       <td width="5" align="right" valign="middle" bgcolor="#E1E1E1" class="Estilo1">&nbsp;</td>
                </tr>
                <?
                $total
=$total + ($carrito_mio[$i]['precioparticular_productos'] * $carrito_mio[$i]['cantidad']);
                }
                }
                }
                
?>
                <tr>
                  <td colspan="8">&nbsp;</td>
                  </tr>
                <tr>
                      <td colspan="4"><span class="Estilo11"></span></td>
                      <td>&nbsp;</td>
                      <td align="left"><span class="Estilo12"><strong>Total:</strong></span></td>
                      <td colspan="2" align="right"><span class="Estilo12"><strong>
                       <? 
                      
if(isset($_SESSION['carrito'])){
                      print 
$total
                      }
                       
?> 
                       &euro; </strong></span></td>
                     </tr>
            </table>
              
              </td>
            </tr>
            </table>
        </form>
          <input type="submit" name="Submit24" value="Ya estoy registrado" onclick="window.location='../../Usuarios/iniciarsesion.php'"/>
          <input type="submit" name="Submit222" value="Registrarme" onclick="window.location='../../Usuarios/registrarse.php'"/>
          <input type="submit" name="Submit232" value="Comprar sin registrarme" onclick="window.location='../../Wlibres/final2.php'"/>
        </div>
</div>
</body>
</html>
<?php
mysql_free_result
($r_noticias);

mysql_free_result($r_usuarios);
?>
A continuación adjunto archivo iniciarsesion.php!!!