I have a small elearning app and I want to check against the DB for the start and end dates (from mysql) and if they meet the criteria, good, else location.redirect to expired.php??

It doesn't redirect, any suggestions?

Here's an example below...

function Timebomb() {
 
  var StartDate = <?php echo $row_product['startdate']; ?>;
  var EndDate = <?php echo $row_product['enddate']; ?>;

  var nowDate = new Date();
  var day = nowDate.getUTCDate();
  var month = nowDate.getUTCMonth();
  var correctedMonth = month + 1; 

/* Date Checker corrector */

  if (correctedMonth < 10) {
    correctedMonth = "0" + correctedMonth;
  }
   
  if (day < 10) {
    day = "0" + day;
  }

  var year = nowDate.getYear();
  if (year < 1900) {
    year = year + 1900;
  }

  var GMTdate = year + "" + correctedMonth + "" + day;

/* End of Date Correcter */

  if ((GMTdate <= EndDate) && (GMTdate >= StartDate)) {
    document.redirect('expire.php')
  }
}

Thanks,
Ted

You can do this in php itself ! Why do you want to rely on javascript ?

I actually did it in php...

Why would I rely on javascript? because I thought I could do it easier...

Thanks.
Ted

What if the client has disabled javascript ?

that's why I did it in php...

:) Yeah.. Cool!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.