Patrick Madden
New member
Alright,
So what I'm Trying to do sounds simple, but I'm having a hard time getting it to work right...
I am working on a coupon system for customers at a store.
We want to be able to make it so they can go to our site (IE: www.test.com/coupons)
and from there, click on the appropriate coupon.
Simple enough
Here's where I'm stuck:
We only want the user to be able to download a certain coupon once a week.
Right now, I have it set up as follows:
CODE:
<?php
$dateTime = date('Y/m/d G:i:s');
$fp = fopen('log.txt', 'r+');
if(!$fp){
echo "Log file doesn't exists.";
}
else{
$visited = FALSE;
while (!feof($fp))
{
$buffer = fgets($fp);
list ($ip, $time) = split(' ', $buffer);
//Checks if IP is already logged.
if ($_SERVER['REMOTE_ADDR'] == trim($ip)){
$visited = TRUE;
echo "Not your first visit.";
}
}
if (!$visited){
fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\n");
echo "First visit.";
}
fclose($fp);
}
?>
END CODE
So, this code only allows the user to view the page once per IP
How can this be modified to reset over a set time?
Or do I need a new script?
Thanks In Advance
So what I'm Trying to do sounds simple, but I'm having a hard time getting it to work right...
I am working on a coupon system for customers at a store.
We want to be able to make it so they can go to our site (IE: www.test.com/coupons)
and from there, click on the appropriate coupon.
Simple enough
Here's where I'm stuck:
We only want the user to be able to download a certain coupon once a week.
Right now, I have it set up as follows:
CODE:
<?php
$dateTime = date('Y/m/d G:i:s');
$fp = fopen('log.txt', 'r+');
if(!$fp){
echo "Log file doesn't exists.";
}
else{
$visited = FALSE;
while (!feof($fp))
{
$buffer = fgets($fp);
list ($ip, $time) = split(' ', $buffer);
//Checks if IP is already logged.
if ($_SERVER['REMOTE_ADDR'] == trim($ip)){
$visited = TRUE;
echo "Not your first visit.";
}
}
if (!$visited){
fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\n");
echo "First visit.";
}
fclose($fp);
}
?>
END CODE
So, this code only allows the user to view the page once per IP
How can this be modified to reset over a set time?
Or do I need a new script?
Thanks In Advance