Reputation: 49
I am new to php. I want to redirect user on specific date in every month.
I tried following code, but it is not working.
<?
date_default_timezone_set('Asia/kolkata');
$date = date('Y-m-d');
$dateblock = date ('d', strtotime($date));
if ($dateblock ="2" || $dateblock ="5" || $dateblock ="9" || $dateblock ="11" || $dateblock ="13" || $dateblock ="16" || $dateblock ="18" || $dateblock ="21" || $dateblock ="23" || $dateblock ="25" || $dateblock ="27" || $dateblock ="29" || $dateblock ="30") {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>404 Page Not Found</title>
</head>
<body>
<center>
<img src="images/sorry.png" />
</center>
</body>
</html>
<?}else{
echo "Redirecting You..... Please Wait...";
header('Refresh: 3;url=pagexyz.php');
}?>
Basically I want to show pagexyz.php only on dates in month except dates used in above if statement.
Or
is there any other way to hide pagexyz.php on specific dates in each month ?
Upvotes: 1
Views: 87
Reputation: 41885
Alternatively, you could also utilize an in_array()
function for this:
<?php
date_default_timezone_set('Asia/Kolkata');
// ^ big letter K
$date = date('Y-m-d');
$dateblock = date ('d', strtotime($date));
$restricted_days = array(2,5,9,11,13,16,18,21,23,29,30);
?>
<?php if(in_array($dateblock, $restricted_days)): ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>404 Page Not Found</title>
</head>
<body>
<center>
<img src="images/sorry.png" />
</center>
</body>
</html>
<?php else: ?>
<h1>Redirecting!! Please wait!!!</h1>
<meta http-equiv="refresh" content="3; url=http://www.google.com" />
<?php endif; ?>
Upvotes: 1