Disallowing access to all pages within a site.

Discussion in 'PHP' started by TimK, Apr 26, 2011.

  1. #1
    How would I be able to disallow access to all the pages within my site, unless a cookie is present? Without modifying all the files in order to check if the cookie is active.


    At a loss on how to go about this.
     
    TimK, Apr 26, 2011 IP
  2. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #2
    If you have header/constant/functions or some other file included in every page/files then you can write a piece of code to check for cookie
    <?php
    if (isset($_COOKIE["cookie_name"]))
      echo "Welcome to our site";
    else
      echo "go away";
    ?>
    PHP:
     
    artus.systems, Apr 27, 2011 IP
  3. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah, I don't have that but I figured out how to do it via .htaccess.

    
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_COOKIE} !^.*cookie-name.*$
    RewriteRule .* /redirectionpage.html [NC,L]
    
    Code (markup):
    For anyone that needs it.
     
    TimK, Apr 27, 2011 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    This isn't a very secure way of restricting access. A cookie can be easily forged which would give someone access to this area when they shouldn't. If there is anything sensitive in the area you're protecting, I would opt for another method.
     
    jestep, Apr 27, 2011 IP
  5. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It's nothing sensitive, it's just mainly them having to click continue on the splash page before being able to access any other pages.
     
    TimK, Apr 27, 2011 IP
  6. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #6
    I see. Should work well then.
     
    jestep, Apr 27, 2011 IP