Protecting Pages Code? What Am I Doing Wrong? Please Help

Discussion in 'PHP' started by daniel27lt, Feb 1, 2013.

  1. #1
    Hi there,

    I am having an issue protecting sub-folders within sub-folders with PHP.

    I have been protecting pages with only short directories (doing fine), but now I am wanting to protect new directories with a number of sub-directories and that is where I am having troubles.


    Example:
    PHP Login Script Location: http://www.mydomain.com/login/free/main.php


    Works Fine -
    Pages Protected: http://www.mydomain.com/login/free/members/free.php

    Does not work -
    Wanting Pages Protected: http://www.mydomain.com/login/free/members/free/archive/directory/2008.php
    (and branched out from there)


    This is the code I use on tops of all my pages, but the long one's do not work...

    <?php
    include("..../include/session.php");
    if(!$session->logged_in){ header("Location: ..../main.php"); } else {
    ?>
    <!-- -->
    Code (markup):
    Only "../" works, not "..../" or "....../".

    Can anyone tell me why this is the case and what I am doing wrong.

    Thanks
     
    daniel27lt, Feb 1, 2013 IP
  2. Syndication

    Syndication Active Member

    Messages:
    351
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    90
    #2
    Generally when assigning cookies and sessions in a subfolder, generally they don't carry to upper-level folders unless specified.

    http://forums.phpfreaks.com/topic/218237-session-not-carried-between-sub-folder-and-root/
     
    Syndication, Feb 1, 2013 IP
  3. tiamak

    tiamak Active Member

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    58
    #3
    use ../../ or ../../../


    LOL, no comment ;)
     
    tiamak, Feb 1, 2013 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    Or use the base root of your directories, try reading $_SERVER for more info.
     
    EricBruggema, Feb 2, 2013 IP
  5. profitdollar

    profitdollar Active Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #5
    Another option:

    dirname(__FILE__).'/login/free/members/free/archive/directory/';
    Code (markup):
     
    profitdollar, Feb 5, 2013 IP