I am trying to show a different iframe depending on the age of the visitor without a redirection / refresh.
However after verifying the visitors age, the javascript is not being applied correctly, or at all.
I keep ending up with a blank iframe. Someone please take a look at my code below:
<html>
<head><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script></head>
<form method="post">
<input type="date" name="dob"><br>
<input type="submit" name="submit" value="Verify Age" />
</form>
<?php
$minAge = 18; // You might read this from a file/database.
$minAge *= 3600*24*365.25; // $minAge in seconds
if(isset($_POST['submit'])){
$birth_date = strtotime($_POST['dob']);
$now = strtotime("now");
$age = $now - $birth_date; // age is in seconds
if($age > $minAge)
echo '<script>$("#myiframe").attr("src", "http://URL1.com");</script>';
else
echo '<script>$("#myiframe").attr("src", "http://URL2.com");</script>';
} ?>
<iframe id="myiframe"></iframe>
</html>
echo '<iframe src="http://URL1.com"></iframe>';?