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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.