Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] refrescar variable de sesion con ajax??

Estas en el tema de refrescar variable de sesion con ajax?? en el foro de PHP en Foros del Web. hola buenas tardes estoy trabajando con sesiones asta ahora ya e iniciado la variable de sesion y la cuenta regresiva en cierto tiempo despues de ...
  #1 (permalink)  
Antiguo 22/11/2013, 12:46
Avatar de Ilidam  
Fecha de Ingreso: julio-2009
Ubicación: Veracruz
Mensajes: 108
Antigüedad: 14 años, 8 meses
Puntos: 0
refrescar variable de sesion con ajax??

hola buenas tardes estoy trabajando con sesiones asta ahora ya e iniciado la variable de sesion y la cuenta regresiva en cierto tiempo despues de entrar al sistema
lo que kiero sabes es como refrescar la variable de sesion por ejemplo cuando se activa la cuenta regresiva si llega a cero k me mande a la pagina de logueo y si lo cancelo que se refreque la sesion mi codigo asta ahora es este
Código PHP:
Ver original
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <script language="JavaScript" src="js/jquery-1.5.1.min.js"></script>
  5. <style>
  6.   html {  background-image: url(images/glowcolor.png); }
  7.  .alerta {
  8.  position: fixed; /* Le damos el valor Fixed para que flote */
  9.  background: rgba(255, 255, 255, 0.50); /* Color de fondo de la capa */
  10.  width: 100%;
  11.  height: 100%;
  12.  top: 0;
  13.  left: 0;
  14.  z-index: 999;
  15. }
  16. .flota{
  17.  background: white; /*Color de fondo del contenedor*/
  18.  border-radius: 2px; /* Redondeado */
  19. box-shadow: 0px 0px 0px 1px black, 5px 5px 14px black; /* Sombra exterior */
  20.  z-index: 9999;
  21.  
  22.     position:absolute;
  23.     left:428px;
  24.     top:182px;
  25.     width:223px;
  26.     height:138px;
  27.     z-index:1;
  28. }
  29.  
  30. .close1{
  31.  position: absolute;
  32.  display: block;
  33.  top: -15px;
  34.  right: -15px;
  35.  cursor: pointer;
  36.  background: url(images/eliminar.png) 0px 0px no-repeat; /* Imagen del boton */
  37.  width: 30px;
  38.  height: 30px;
  39.  overflow: hidden;
  40.  text-indent: -9999px;
  41. }
  42. </style>
  43. <script>
  44. $(document).ready(function() {
  45.     setTimeout(function() {
  46.         $(".alerta").fadeIn(1000);
  47.     },5000);
  48. });
  49.  
  50.     $(document).ready(function() {
  51.  $(".close1").click(function(){ //Le decimos que al dar click en ".close"...
  52.     $(".alerta").hide("drop"); //Oculte el contenedor ".overlay" lentamente(slow)
  53.   event.preventDefault(); // Anulamos el enlace...
  54.  });
  55. });
  56.  
  57. </script>
  58.  
  59. <script type="text/javascript">
  60.  function display_c(start){
  61. window.start = parseFloat(start);
  62. var end = 0 // change this to stop the counter at a higher value
  63. var refresh=1000; // Refresh rate in milli seconds
  64. if(window.start >= end ){
  65. mytime=setTimeout('display_ct()',refresh)
  66. }
  67. else {
  68.     window.location="../login.html";
  69. }
  70. }
  71.  
  72. function display_ct() {
  73. // Calculate the number of days left
  74. var days=Math.floor(window.start / 86400);
  75. // After deducting the days calculate the number of hours left
  76. var hours = Math.floor((window.start - (days * 86400 ))/3600)
  77. // After days and hours , how many minutes are left
  78. var minutes = Math.floor((window.start - (days * 86400 ) - (hours *3600 ))/60)
  79. // Finally how many seconds left after removing days, hours and minutes.
  80. var secs = Math.floor((window.start - (days * 86400 ) - (hours *3600 ) - (minutes*60)))
  81.  
  82. var x = minutes + ":" + secs + " Minutos ";
  83.  
  84.  
  85. document.getElementById('ct').innerHTML = x;
  86. window.start= window.start- 1;
  87.  
  88. tt=display_c(window.start);
  89. }
  90.  
  91. setTimeout(document.getElementById('busca').style.display = 'inline',10);//aki puse esto
  92. </script>
  93.  
  94. </head>
  95. <body onload="display_c(124);">
  96. HOLA
  97. <div class="alerta" id="busca" style="display:none"><!-- Mostrar div DURANTE 10 min de inactividad mientras este oculto-->
  98.     <div  class="flota" style=" width:397px; height:244px; ">
  99.         <div class="close1">
  100.             <a href="#">Cerrar</a>
  101.         </div>
  102.             <center>
  103.                 <br><br><br>
  104.                 EL SISTEMA SE CERRARA POR SEGURIDAD EN
  105.                 <br><br>
  106.                 <span id='ct'></span>
  107.                 <br><br>
  108.                 CANCELAR OPERACION
  109.                 <input type="submit" value="CONTINUAR">
  110.  
  111.             </center>
  112.   </div>
  113. </div>
  114. </body>
  115. </html>
  #2 (permalink)  
Antiguo 22/11/2013, 12:58
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 15 años, 11 meses
Puntos: 2534
Respuesta: refrescar variable de sesion con ajax??

Puedes mandar una petición a tu servidor con Ajax así: sesion.php?timeout=1

Y entonces, en dicho script manejas la lógica para cerrar la sesión.

Es decir, desde Javascript no puedes cerrar la sesión, pero si puedes decirle al servidor que ejecute un script PHP que lo haga.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 22/11/2013, 13:04
Avatar de Ilidam  
Fecha de Ingreso: julio-2009
Ubicación: Veracruz
Mensajes: 108
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: refrescar variable de sesion con ajax??

como se hace esa peticion con ajax?? o en que parte se utilizario el
sesion.php?timeout=1
  #4 (permalink)  
Antiguo 22/11/2013, 13:08
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 15 años, 11 meses
Puntos: 2534
Respuesta: refrescar variable de sesion con ajax??

Bueno, pensaba que ya sabías como hacer una petición Ajax, porque aquí es el foro de PHP no el de Ajax.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #5 (permalink)  
Antiguo 22/11/2013, 13:14
Avatar de Ilidam  
Fecha de Ingreso: julio-2009
Ubicación: Veracruz
Mensajes: 108
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: refrescar variable de sesion con ajax??

entonces podrian mover el tema a foro ajax o lo publico en el foro ajax??
  #6 (permalink)  
Antiguo 22/11/2013, 13:16
Avatar de Dalam  
Fecha de Ingreso: septiembre-2010
Mensajes: 409
Antigüedad: 13 años, 6 meses
Puntos: 56
Respuesta: refrescar variable de sesion con ajax??

Cita:
Iniciado por Ilidam Ver Mensaje
como se hace esa peticion con ajax?? o en que parte se utilizario el
sesion.php?timeout=1
es tan facil como poner la linea esta

Código Javascript:
Ver original
  1. $.ajax({ type: "GET",url: "/reset_session.php" });
entre las lineas 63 y 64 del script que solucionamos en el otro post que estubimos hablando

Con esto al hacer una peticion al servidor se reinicia el session cache expire

y luego creas un script en la carpeta padre del site con el nombre

reset_session.php

Código PHP:
Ver original
  1. <?php
  2. ?>

Última edición por Dalam; 22/11/2013 a las 13:40
  #7 (permalink)  
Antiguo 22/11/2013, 13:48
Avatar de Ilidam  
Fecha de Ingreso: julio-2009
Ubicación: Veracruz
Mensajes: 108
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: refrescar variable de sesion con ajax??

muchas gracias ya me funciono asi
dejo el codigo por si alguien le sirve
Código PHP:
Ver original
  1. <html>
  2.     <head>
  3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4.     <script language="JavaScript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
  5.     <script type="text/javascript">if(typeof jQuery==='undefined'){document.write(unescape("<scri"+"pt src='js/jquery-1.3.2.min.js' type='text/javascript'></scri"+"pt>"));}</script>
  6.     <style>
  7.           html {  background-image: url(images/glowcolor.png); }
  8.      .alerta {
  9.      position: fixed; /* Le damos el valor Fixed para que flote */
  10.      background: #FFF; /* Color de fondo de la capa */
  11.     width: 100%;
  12.      height: 100%;
  13.      top: 0;
  14.      left: 0;
  15.      z-index: 999;
  16.      display:none;
  17.     }
  18.     .flota{
  19.      opacity:1.0; /* opacidad del 60% */
  20.      filter:alpha(opacity=100); /* Opacidad para IE8 y earlier */
  21.      background: rgba(255, 255, 255, 0.50); /* Color de fondo de la capa */
  22.      border-radius: 8px; /* Redondeado */
  23.      box-shadow: 0px 0px 0px 1px black, 5px 5px 14px black; /* Sombra exterior */
  24.      position:absolute;
  25.      left:50%;
  26.      top:50%;
  27.      margin-left:-112px;
  28.      margin-top:-70px;
  29.      width:224px;
  30.      height:140px;
  31.      z-index:1;
  32.      color:#000;
  33.    }
  34.  
  35.     .flota h2 {
  36.         margin:auto;
  37.         text-align:center;
  38.     }
  39.     .flota span {
  40.         text-align:center;
  41.         width:100%;
  42.         position:inherit;
  43.         margin-top:20%;
  44.         font-size:36px;
  45.     }
  46.  
  47.     .close{
  48.      position: absolute;
  49.      display: block;
  50.      top: 0;
  51.      right: 2;
  52.      cursor: pointer;
  53.      background: url(images/eliminar.png) 0px 0px no-repeat; /* Imagen del boton */
  54.      width: auto;
  55.      height: 30px;
  56.      overflow: hidden;
  57.     }
  58.     </style>
  59.     <script>
  60.         $(document).ready(function() {
  61.             $(".close").click(function(){ //Le decimos que al dar click en ".close"...
  62.                 $(".alerta").hide("slow"); //Oculte el contenedor ".overlay" lentamente(slow)
  63.                 window.clearInterval(mytime); // Delete interval
  64.                 $.ajax({ type: "GET",url: "expira.php" });
  65.                 display_c(120); // Redefine time for new session expire
  66.                 event.preventDefault(); // Anulamos el enlace...
  67.              });
  68.         });
  69.     </script>
  70.     <script type="text/javascript">
  71.     function display_c(start){
  72.     window.start = parseFloat(start);
  73.     var end = 0 // change this to stop the counter at a higher value
  74.     var refresh=1000; // Refresh rate in milli seconds
  75.     var timeShow = 119;
  76.     if(window.start >= end ){
  77.         if(window.start <= timeShow){
  78.             $(".alerta").show();
  79.         }
  80.         mytime=setTimeout('display_ct()',refresh)
  81.     }
  82.     else {
  83.        window.location="../login.html";
  84.     }
  85.     }
  86.  
  87.     function display_ct() {
  88.     // Calculate the number of days left
  89.     var days=Math.floor(window.start / 86400);
  90.     // After deducting the days calculate the number of hours left
  91.     var hours = Math.floor((window.start - (days * 86400 ))/3600)
  92.     // After days and hours , how many minutes are left
  93.     var minutes = Math.floor((window.start - (days * 86400 ) - (hours *3600 ))/60)
  94.     // Finally how many seconds left after removing days, hours and minutes.
  95.     var secs = Math.floor((window.start - (days * 86400 ) - (hours *3600 ) - (minutes*60)))
  96.  
  97.     var x = minutes + ":" + secs + " Minutos ";
  98.  
  99.  
  100.     document.getElementById('ct').innerHTML = x;
  101.     window.start = window.start - 1;
  102.  
  103.     tt=display_c(window.start);
  104.     }
  105.     function wait(time) {
  106.         setTimeout('display_ct()',refresh);
  107.     }
  108.     </script>
  109.     </head>
  110.     <body onload="display_c(120);">
  111.     HOLA
  112.     <div class="alerta" id="busca" ><!-- Mostrar div DURANTE 10 min de inactividad mientras este oculto-->
  113.         <div  class="flota" style=" width:397px; height:244px; ">
  114.             <div class="close">
  115.                 <a href="#">Cerrar</a>
  116.             </div>
  117.             <h2>La sessi&oacute;n caducara en </h2>
  118.     <span id='ct'></span>
  119.       </div>
  120.     </div>
  121.  
  122.     </body>
  123.     </html>

Etiquetas: html, refrescar, variable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:18.