Preventing direct url access to a page without login

Discussion in 'PHP' started by shaleem, Jul 21, 2010.

  1. #1
    Hello,

    Can anyone explain to me how to prevent direct url access to a file unless the person has login.
    let say I have a file: ..../client.php, I want user to login first before accessing this page.
     
    shaleem, Jul 21, 2010 IP
  2. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Assuming you're using apache, you can use htaccess to do this for you. Failing that, you could create a php login script - however, that wont help when the files not a php file!
     
    bencummins, Jul 21, 2010 IP
  3. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #3
    If you use php, and use sessions, you can use this:

    if(!isset($_SESSION['id']))header('Location: index.php')
    PHP:
    If you don't have to much knowledge about php, you can better use htaccess protection.
     
    ssmm987, Jul 21, 2010 IP
  4. shaleem

    shaleem Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello,
    I just try to use htaccess by typing: Deny from all.
    But the problem is that it deny access even if a user register and use the login form.
    I guess I need to write a different code but I don't really know what. The page I want to protect is name client.php
     
    shaleem, Jul 21, 2010 IP