/    Sign up×
Community /Pin to ProfileBookmark

IP access with timer

Hello all,

I have a script which blocks your IP for X amount of time thereby allowing you 1 visit per day. It is

[code=php]<?php

$ipLog=’ipLogFile.txt’; // Your logfiles name here
$timeout=’1′; // How many hours to block IP
$goHere=’???.php’; // Allowed pages name here

function recordData($REMOTE_ADDR,$ipLog,$goHere)
{
$log=fopen(“$ipLog”, “a+”);
fputs ($log,$REMOTE_ADDR.”][“.time().”n”);
fclose($log);
Header (“Location: $goHere”); exit(0);
}
function checkLog($REMOTE_ADDR,$ipLog,$timeout)
{
global $valid; $ip=$REMOTE_ADDR;
$data=file(“$ipLog”); $now=time();

foreach ($data as $record)
{
$subdata=explode(“][“,$record);
//Subdata Below Set Ammount Of Access
if ($now < ($subdata[1]+3600*$timeout) && $ip == $subdata[0])
{
$valid=0; echo “would you like to register? Or come back in $timeout hours.”;
break;
}
}
}
checkLog($REMOTE_ADDR,$ipLog,$timeout);
if ($valid!=”0″) recordData($REMOTE_ADDR,$ipLog,$goHere);

?>[/code]

FORWARDS TO :: [B]$goHere=’???.php’; // Allowed pages name here[/B]
if only you have been here more than 1 hour ago. If I wantyou to got to a certain page if NOT allowed how would that go??

I hope someone understands me. In the end i want to limit someones number of links generated from another PHP page. Can someone help me, Please

Thank You

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@bokehNov 04.2006 — What is the question?
Copy linkTweet thisAlerts:
@Disabled1authorNov 04.2006 — The question is ...

Where do I and how do I insert [B]if you have been here within the last hour, I would like to forward them to another page.[/B]

In the script above it sends you to a [[allowed page ???.php]] if you have accessed over an hour ago.

Thank You for super fast reply. Hope I clarified what I wanted.

Disabled
Copy linkTweet thisAlerts:
@bokehNov 04.2006 — Can you edit your post and put your code between [B]&#91;PHP&#93;&#91;/PHP&#93;[/B] tags. At the minute it is unreadable.
Copy linkTweet thisAlerts:
@Disabled1authorNov 06.2006 — [B]Anyone?[/B]
Copy linkTweet thisAlerts:
@bokehNov 06.2006 — This piece of code:[code=php]if ($valid!="0")[/code]will always return true unless you explicitely give it a value. Also even when you do set it you are only doing so in local scope and only to zero. Use a boolean; it's a lot clearer. Also your script relies on register globals to be "On" while the majority of servers have this set to "Off". You need to modify the script to get the IP from the $_SERVER superglobal.
×

Success!

Help @Disabled1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...