1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

can i ban website visitors after they visit a certain page?

Discussion in 'General Programming Chat' started by smetten2, Dec 9, 2008.

  1. smetten2

    smetten2 BANNED BANNED

    Joined:
    Nov 1, 2008
    Messages:
    38
    Likes Received:
    15
    Hi

    Is it possible to ban an ip address after they visit a certain page on my website. Suppose i only want people to see this page 1 time, so when they come back or refresh they see another page or they see no page (banned by ip address).

    Greetz

    Nick
     
  2. bigmoneyX

    bigmoneyX Registered Member

    Joined:
    Feb 20, 2008
    Messages:
    99
    Likes Received:
    26
    couldn't you do this with a cookie?
     
  3. himpula

    himpula Newbie

    Joined:
    Nov 27, 2008
    Messages:
    1
    Likes Received:
    0
    Do you want the ban to happen to the whole site, or everything in a folder including stuff in all subfolders, or only one page?
    It's very easy to do with .htaccess and php, it's also possible by php only.

    Answer the first question and also tell do you have htaccess support, and I will write you sample code.
     
  4. smetten2

    smetten2 BANNED BANNED

    Joined:
    Nov 1, 2008
    Messages:
    38
    Likes Received:
    15
    can you tell me how this is done, if possible.

    Thx in advance

    Greetz

    smetten
     
  5. smetten2

    smetten2 BANNED BANNED

    Joined:
    Nov 1, 2008
    Messages:
    38
    Likes Received:
    15
    yeah i have access to the htaccess file.
    I want people to be banned from the whole site.

    Thx for the help

    Smetten
     
  6. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    Use PHP to grab the visitors IP and then write a deny line to your htaccess.
     
  7. ultimatium1

    ultimatium1 Junior Member

    Joined:
    Oct 10, 2008
    Messages:
    107
    Likes Received:
    19
    I belive its proberly possible with sesssions and php, If somebody hasnt pmed u the code already, pm me 2morrow, and il write and test it for u
     
  8. emgxxg

    emgxxg Registered Member

    Joined:
    Nov 3, 2008
    Messages:
    93
    Likes Received:
    523
    While you can deny using .htaccess it is not at all an efficient way to work as you are basing your assumption that the user has a static IP. Doing the same thing with php and cookies would definitely be a better way to go. I am adding a sample code, you can use this, modify it or get someone to make another.

    Place this right at the begining of the php document:
    Code:
    <?php
    if (!isset($_COOKIE["blockafterview"])) {
    
      setcookie("blockafterview", $_POST["blockafterview"]);
      setcookie("visits", 1);
    
      $blockipviews= 1;
    
    } else {
      setcookie("visits", ++$_COOKIE["visits"]);
    
      $blockipviews= 2;
    }
    ?>
    
    Now use the following to perform whatever action you want:

    Code:
    <?php if ($blockipviews == "1") : ?>
            ADD THE CODE OR INCLUDE ANOTHER PHP FILE FOR THE ACTION FOR FIRST VISIT
    <?php else : ?>
            ADD THE CODE OR REDIRECT FOR THE ACTION TO BE TAKEN FOR BLOCKING HERE
    <?php endif; ?>