Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 20th Apr 2010, 10:58 AM   #1
Vernazza Otranto
 
Spinethetic's Avatar
 
Join Date: 2009
Location: Manhatten
Posts: 179
Thanks: 20
Thanked 14 Times in 13 Posts
Blog Entries: 2
Default
PHP: Only show page once
Share on: 
fb share twitter share gplus share more share

Iam working on some one time offers that I want to only show once (ie: if they refresh the page, or try to load the oto page at a later date, it will not be availabe to them)

I had this script sitting on my hard drive for the longest time and now after almost an hour of searching I can't find it anymore, can't find it via Google either

I think what it did was record the user's IP address to a text file so that when the oto page loaded it would compare their IP address to those recorded in the text file.

Best regards
~ Ross
Spinethetic is offline  
Unread 20th Apr 2010, 01:15 PM   #2
Advanced Warrior
War Room Member
 
apoorv.parijat's Avatar
 
Join Date: 2010
Location: New Delhi, IN
Posts: 978
Thanks: 93
Thanked 340 Times in 59 Posts
Default
Re: PHP: Only show page once
Share on: 
fb share twitter share gplus share more share

Here is the script.Wrote it for you.

You need to create a "log.txt" file in the same directory and change its permission to writable.I could have inserted a line to create this file but sometimes web hosts disable file creation through PHP.

Hope this helps.

Cheers

<?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);
}
?>
apoorv.parijat is offline  
Unread 20th Apr 2010, 02:59 PM   #3
HyperActive Warrior
War Room Member
 
webtrix's Avatar
 
Join Date: 2009
Location: SE Europe
Posts: 112
Thanks: 13
Thanked 8 Times in 8 Posts
Default
Re: PHP: Only show page once
Share on: 
fb share twitter share gplus share more share

And here's a simple code to check if a proxy is used

if ($_SERVER['HTTP_X_FORWARD_FOR'])
{
$IP = $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$IP = $_SERVER['REMOTE_ADDR'];
}
webtrix is offline  
Unread 20th Apr 2010, 03:13 PM   #4
Vernazza Otranto
 
Spinethetic's Avatar
 
Join Date: 2009
Location: Manhatten
Posts: 179
Thanks: 20
Thanked 14 Times in 13 Posts
Blog Entries: 2
Default
Re: PHP: Only show page once
Share on: 
fb share twitter share gplus share more share

Wicked! Thanks for the script, almost done with one oto and Ill be poutting this in there.

And there are many good uses for detecting proxies, but I think that if my optins are that desperate (what with some of the questionable advertising integrated into them and God knows what else...) to take a second look at my oto through a proxy, than Ill just let them get a second look haha
Spinethetic is offline  
Unread 21st Apr 2010, 06:02 AM   #5
Advanced Warrior
War Room Member
 
apoorv.parijat's Avatar
 
Join Date: 2010
Location: New Delhi, IN
Posts: 978
Thanks: 93
Thanked 340 Times in 59 Posts
Default
Re: PHP: Only show page once
Share on: 
fb share twitter share gplus share more share

Originally Posted by Spinethetic View Post

Wicked! Thanks for the script, almost done with one oto and Ill be poutting this in there.

And there are many good uses for detecting proxies, but I think that if my optins are that desperate (what with some of the questionable advertising integrated into them and God knows what else...) to take a second look at my oto through a proxy, than Ill just let them get a second look haha
You are welcome. I uploaded the script here.

www.salescanvastheme.com/notwice.php

for testing purpose.Works clean.

Cheers
apoorv.parijat is offline  
Unread 21st Apr 2010, 06:06 AM   #6
Advanced Warrior
War Room Member
 
apoorv.parijat's Avatar
 
Join Date: 2010
Location: New Delhi, IN
Posts: 978
Thanks: 93
Thanked 340 Times in 59 Posts
Default
Re: PHP: Only show page once
Share on: 
fb share twitter share gplus share more share

Script update.I realised,message "Not first visit." has to be inside conditional.Fixed now.

<?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)){ << '{' where missing
$visited = TRUE;
echo "Not your first visit.";
} added '}'
}
if (!$visited){
fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\n");
echo "First visit.";
}
fclose($fp);
}
?>
apoorv.parijat is offline  
Closed Thread


Bookmarks

Tags
page, php, show


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 05:03 AM.