Problem with session variable

0

On my site, I have a part of the code where two checkbox options should be shown for the check-in date with a difference of 72 hours or more compared to today.

<?php
$difdias = (1/86400)*(strtotime($_SESSION['buscaReserva']['dataInicio'])-strtotime(date('Y-m-d')));
if(($_REQUEST['idHotel'] == '373443') && ($difdias >= 3)) {
echo "<tr><td><div id='chkDolars' name='valueDolars' class='checkbox chkSelecionado' style='margin-bottom: 10px'><span class='ph03_105'></span></div><div id='chkReais' name='valueReais' class='checkbox' style='margin-bottom: 10px'><span class='ph03_103'></span></div></td>";
echo "<td><div id='msgReais'><span id='lblReais' class='ph03_104' style='display: none'></span></div></td></tr>";
//echo $_SESSION['buscaReserva']['dataInicio']; 
}
?>

At first, everything is OK, but if I first do a search with a check-in that is longer than 3 days and then I do another one with a check-in that is less than 3 days, then the checkboxes however, if I repeat this search in the sequence, then checkboxes are added (they should have disappeared the previous time). The same happens if the first search is with a check-in that is less than 3 (the checkboxes do not appear), I make a second search with a check-in greater than 3 and there the checkboxes do not appear and, repeating this second search, they end up appearing should have appeared the previous time.)

In the commented line of the code, I decided to check how the variable $_SESSION['buscaReserva']['dataInicio'] is coming from. I think it takes time to update, and updating the page on new search is usually quick.

I do not know if the situation was very clear. What could I do in this case to just checkboxes in the correct situation (check-in date greater than 3 days) and disappear in the correct situation (check-in date less than 3 days)?

    
asked by anonymous 01.07.2015 / 14:14

2 answers

0

To make use of sessions in php you should start the session with the use of session_start (), both in the screen that places a value in the session and in the screen that reads the same one follows an example.

  

file_session.php

<?php
  session_start();//inicio a sessao
  $_SESSION['buscaReserva']['dataInicio'] = "SUA DATA";
  

file_session.php

<?php
  session_start();//inicio a sessao
  echo $_SESSION['buscaReserva']['dataInicio']; //Vai imprimir SUA DATA

Tip here in php.net you will find a how-to manual the use of session variables.

    
01.07.2015 / 14:38
0

I discovered the solution. This session receives the value of an input whose id is dtIni . Using $_REQUEST['dtIni'] instead of the session variable solved my problem.

    
01.07.2015 / 14:42