Here is my scenario:

Users opens IE and home page loads based on our group policy in that page I need the following to happen:

1) creates a cookie with an expiration date of 30 days
2) checks to see if cookie is set, if it is set and its has been > or = to 30 days then it checks the users IP address. If the users IP address is an internal IP address it then redirects them to our Intranet site, if IP address is external it redirects them to an external site.
3) If the cookie is older than 30 days, say day 31, then a pop up message pops up notifying them of an event and then checks their IP, if IP is an internal IP then user is redirected to Intranet Site, if the IP is external then it redirects them to a external site

I think I have the cookie working in PHP, and the redirect script seems to work to, but when you combine the cookie script, conditional script of checking if the cookie is set and if it is less than, equal to, or greater than 30 days, then checking IP and redirecting it all goes to crud.

PHP is all kinda new to me so I am trying to wrap my hands around it. This is all hosted on an IIS server too if that matters.

Thanks in advance, Gym

Please provide the code as claim to have. Reading from magic ball is skill long forgotten, so we may not know what is going on in your code...

Sorry about that, here is the code:

set_cookie.php

<?php
//Set Cookie and redirect to check_cookie.php based on html meta-redirect due to IIS issues with properly setting cookies and using header() function
//Sets cookie
//Calculate 30 days in the future
//seconds * minutes * hours * days + current time
	$inOneMonth = 60 * 60 * 24 * 30 + time();
	setCookie('lastVisit',date("G:i - m/d/y"), $inOneMonth);
?>
<html>
<head>
<meta http-equiv="refresh" content="0;URL=check_cookie.php">
</head>
<body>
Redirecting...
</body>
</html>

check_cookie.php

<?php
//Check to see if cookie is set
//If cookie is set and lastVisit <= 30 days then header(location:redirect page based on ip)
  $inOneMonth = 60 * 60 * 24 * 30 + time();
	if(isset($_COOKIE['lastVisit']) =< ($inOneMonth){
		//$last = $_COOKIE['lastVisit'];
		//$days = 30;
		//if($last >= $days){
			header('Location: load_popup.php');
		}
		else
		{
		header('Location: ip_redirect.php');
	}
		//echo $_COOKIE['lastVisit'];
		//header('Location: ip_redirect.php');
		//echo "Cookies exist";
	}
	//header('Location: ip_redirect.php');
//elseif cookie is set and lastVisit > 30 days then header(location:load pop up page)
	//elseif(isset($_COOKIE['lastVisit'] > 30))
	//header('Location: load_popup.php');
?>

load_popup.php

<?php
//loads pop up code and redirects user to redirect page based on IP
?>
<html>
<head>
<meta http-equiv="refresh" content="10;URL=ip_redirect.php">
</head>

<body OnLoad="CommunitySatisfaction=window.open('popup_msg.html', 'CommunitySatisfaction', 'toolbar=0, location=0, directories=0, menuBar=0, scrollbars=1, resizable=1, width=500, height=400, left=50, top=50');">
<center>
Redirecting....
</center>
</body>
</html>

ip_redirect.php

<?php
//redirects user to Intranet or domain.com based on IP address.
	//Checks IP address
	$ip=$_SERVER['REMOTE_ADDR']; 
 		//echo "<br />Your IP address is : $ip";
 	if (preg_match("/172.16/",$ip)) {
      header('Location: intranet_domain.com');
}  elseif (preg_match("/172.18/",$ip)) {
      header('Location: intranet_domain.com');
} else {
      header('Location: domain.com');
};
?>
This article has been dead for over six months. Start a new discussion instead.