...

View Full Version : How to limit users to access my script



redfroc
11-27-2007, 03:37 AM
Hi all..

I need to limit my script access, 'cause I create an application in trial.

Can I limit users to access my scrip without using any text file or database?
I need to limit access in 3 users max.

thank you. :)

shedokan
11-27-2007, 03:47 AM
try only allowing the ips of the people who are allowed to use the script.
you can use this script to eco your ip:

<?php $remote_address = getenv("REMOTE_ADDR");
echo "Your IP address is $remote_address."; ?>
and use this script to only allow your ips:


<?
//replace the 1.1.1.1 with each ip hat is allowed.
$allowip = array("1.1.1.1","1.1.1.1","1.1.1.1");

$x = count($allowip);

for ($y = 0; $y < $x; $y++) {

if ($REMOTE_ADDR == $allowip[$y]) {
//here put your script that only you can see
Exit;}

} else {
echo "you are not allowed to view this page, get out!!!";
}

I have't tested the script so I can't assre you anything...

redfroc
11-27-2007, 09:31 AM
that's a great code. but it just limit for known IPs so we should type it manually. I mean, how to limit access to our page for 3 users max (whatever IPs). As long the access not reach the limit yet, anybody can access the page.

could it do in php?

thank you.

shedokan
11-27-2007, 12:54 PM
this script doesn't have limits it can be even 100 ip's allowed.

redfroc
11-27-2007, 01:20 PM
no, I mean, the limitation based on users count, not IPs count.

could this possible?

shedokan
11-27-2007, 03:33 PM
ow now I get it, and yes it's possible.
let's say $username is where you keep the user's username:

<?
//replace the 1.1.1.1 with each ip hat is allowed.
$allowuser = array("username1","username1","username1");

$x = count($allowuser);

for ($y = 0; $y < $x; $y++) {

if ($username == $allowuser[$y]) {
//here put your script that only you can see
Exit;}

do you have user's on your website?
} else {
echo "you are not allowed to view this page, get out!!!";
}

Fumigator
11-27-2007, 04:08 PM
shedokan he wants to allow three anonymous users and then block everyone else.

Without some mechanism of storing the number of users that have visited the page through a text file, database, or some other storage medium, I don't believe you'll be able to do it.

shedokan
11-27-2007, 04:13 PM
ow...
sorry can't helpya I'm no good in opening files with php, and he's right you can only do it with a database or a text file nothing else...

redfroc
11-27-2007, 04:17 PM
shedokan he wants to allow three anonymous users and then block everyone else.

yes, it's true.. :D


Without some mechanism of storing the number of users that have visited the page through a text file, database, or some other storage medium, I don't believe you'll be able to do it.

oh I see. my application use MySQL. If I use it to storing the number of user, is there any method to know how much users are accessing the page?

thank you

aedrin
11-27-2007, 05:16 PM
You can only get a best guess. The problem is that you don't know when someone stops browsing a page.

You could implement a custom session destroy handler and decrement the counter at that time. But it might not be very accurate. And you'd have to lower your session timeout to get a realistic count.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum