Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/12/2005, 09:32
Avatar de lado2mx
lado2mx
Colaborador
 
Fecha de Ingreso: agosto-2001
Ubicación: Veracruz
Mensajes: 3.720
Antigüedad: 22 años, 8 meses
Puntos: 9
Sesiones que no agarran en un AJAX

Intento hacer algo así
Código PHP:
<? 
session_register
();
session_start();
include(
"interfase.php");
conexion(); 
$noticia=$_GET['noticia'];
[...]
?><body>
[...]
<?             $_SESSION['busqueda'] = "SELECT * FROM gb_noticias_fotos WHERE id_noticia=".$noticia
?>
<script language="javascript"  type="text/javascript"> 

var url = "imagenajax.php?pagina=";  
var http = getXmlHttpObject(); 

function handleHttpResponse(){ 
    if (http.readyState == 1){ 
        document.getElementById('resultado').innerHTML = "Cargando..."; 
    } 
    if (http.readyState == 4){ 
        results = http.responseText; 
        document.getElementById('resultado').innerHTML = results; 
    } 


function sendQuerystring(pagina){ 
    http.open("GET", url + pagina, true); 
    http.onreadystatechange = handleHttpResponse; 
    http.send(null); 


function getXmlHttpObject(){ 
    var xmlhttp; 

    /*@cc_on 
    @if (@_jscript_version >= 5) 
    try{ 
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    } 
    catch (e){ 
    try{ 
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    catch (e){ 
    xmlhttp = false; 
    } 
    } 
    @else 
    xmlhttp = false; 
    @end @*/ 

    if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){ 
        try{ 
            xmlhttp = new XMLHttpRequest(); 
        } 
        catch (e){ 
            xmlhttp = false; 
        } 
    } 
    return xmlhttp; 


</script>
<?
            
$sql 
mysql_query($busqueda); 
$total_registros mysql_affected_rows(); 
$TAMANO_PAGINA 1
$total_paginas ceil($total_registros $TAMANO_PAGINA); 

if (
$total_paginas 1){ 
    for (
$i=1;$i<=$total_paginas;$i++){ 
?>
    
    <a href="#" class="link" onClick="sendQuerystring('<?  echo $i?>')"><?    
    $il
=$i-1;
    
$sql mysql_query($busqueda " LIMIT $il, $TAMANO_PAGINA"); 
    
$fila_ciclo_imagenes=mysql_fetch_array($sql);

// Tomado de http://www.ladodos.com/webtotal

$maxwidth "50"// Ancho predefinido
$maxheight"50"// Alto predefinido
$imagehw GetImageSize($fila_ciclo_imagenes['url_foto']);
$imagewidth $imagehw[0]; 
$imageheight$imagehw[1]; 

IF (
$imagewidth  $maxwidth)  { $alto=$imageheight/5$ancho=$imagewidth/5; } ELSE { $ancho=$imagewidth; }

IF (
$imageheight $maxheight) { $alto=$imageheight/5$ancho=$imagewidth/5; } ELSE { $alto=$imageheight; }
?>
<img src="imagenjpeg2.php?ruta=<? echo $fila_ciclo_imagenes['url_foto']; ?>&ancho=<? echo $ancho?>&alto=<? echo $alto?>&texto=" alt="<? echo $fila_ciclo_imagenes['pie_foto']; ?>" width="<? echo $ancho?>" height="<? echo $alto?>" border="0" align="top"></a><? 
    

}else{ 
    echo 
"$i ";  
?></td>
                </tr>
              </table></center>
              
<div id="resultado">
  <div align="center"><em> 
  Escoje alguna para ampliarlo aqu&iacute; abajo </em></div>
</div>
Imagenajax.php dice así:
Código PHP:
<?php 
session_register
();
session_start();
function 
quitar($mensaje

$mensaje str_replace("<","&lt;",$mensaje); 
$mensaje str_replace(">","&gt;",$mensaje); 
$mensaje str_replace("\'","'",$mensaje); 
$mensaje str_replace('\"',"&quot;",$mensaje); 

return 
$mensaje


$busqueda=$_SESSION['busqueda'];
$TAMANO_PAGINA 1
$pagina $_GET["pagina"]; 
if (!
$pagina) { 
    
$inicio 0
    
$pagina=1

else { 
    
$inicio = ($pagina 1) * $TAMANO_PAGINA
}  
include(
"interfase.php");
conexion(); 
$sql mysql_query($busqueda) or die("Error de busqueda: ".mysql_error()); 
$total_registros mysql_affected_rows(); 
$total_paginas ceil($total_registros $TAMANO_PAGINA); 

$sql mysql_query($busqueda " LIMIT $inicio, $TAMANO_PAGINA;"); 

while (
$row mysql_fetch_array($sql)){ ?>

<center><?
$imagehw 
GetImageSize($row['url_foto']);
$imagewidth $imagehw[0]; 
$imageheight$imagehw[1]; ?>
<img src="imagenjpeg2.php?ruta=<? echo $row['url_foto']; ?>&ancho=<? echo $imagehw[0]; ?>&alto=<? echo $imagehw[1]; ?>&texto=" alt="<? echo $fila_ciclo_imagenes['pie_foto']; ?>" width="<? echo $imagehw[0]; ?>" height="<? echo $imagehw[1]; ?>" border="0" align="center"></center>
<?



?>
El detalle es muy obvio, $_SESSION['busqueda'] no me lo registra, y por ello no hace ver nada de lo que aparece, es más, no aparece ya nada.

Antes hice la corrección a $_GET['busqueda']; pero como era una sentencia SQL era muy apto a ataques de cualquier tipo, por eso cambié a sesiones, ¿que puedo hacer con esto?