Jump to content

Redirect on second visit


FocuSoft

Recommended Posts

Hello,

 

I have this 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);
}
?> 

This log ip of visitors, and if is first visit will show us "First visit.", if is not the first visit will show us "Not your first visit."

 

Now I want to do some modifications to this code, I want to redirect visitors if is not the first visit, and if is the first visit to show a newsletter.html page

 

I think is simple, but I'm not a PHP coder and I don't know how to do it.

 

Thanks in advance for help.

Link to comment
https://forums.phpfreaks.com/topic/283081-redirect-on-second-visit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.