Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to limit users to access my script

    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.

  • #2
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    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 Code:
    <?php $remote_address getenv("REMOTE_ADDR"); 
            echo 
    "Your IP address is $remote_address."?>
    and use this script to only allow your ips:
    PHP Code:
    <?
    //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...

  • Users who have thanked shedokan for this post:

    redfroc (11-27-2007)

  • #3
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    this script doesn't have limits it can be even 100 ip's allowed.

  • #5
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    1
    Thanked 0 Times in 0 Posts
    no, I mean, the limitation based on users count, not IPs count.

    could this possible?

  • #6
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    ow now I get it, and yes it's possible.
    let's say $username is where you keep the user's username:
    PHP Code:
    <? 
    //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 users on your website?
    } else { 
    echo 
    "you are not allowed to view this page, get out!!!"
    }

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.

  • #8
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    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...

  • #9
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    shedokan he wants to allow three anonymous users and then block everyone else.
    yes, it's true..

    Quote Originally Posted by Fumigator View Post
    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

  • #10
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •