Protecting Pages Code? What am I doing wrong. Please help

by 4 replies
5
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 Code:
<?php
include("..../include/session.php");
if(!
$session->logged_in){ header("Location: ..../main.php"); } else { 
?>
<!-- -->
Only "../" works, not "..../" or "....../".

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

Thanks
#programming #code #login #pages #php script #protecting #wrong
  • ..../ can not work...

    In the linux world, when you want to go e.g. 2 subfolders down, you must use:

    ../../subfolder-name

    or for 3 folders:

    ../../../subfolder-name

    Your code would look like this:

    Code:
    <?php
    include("../../include/session.php");
    if(!){ header("Location: ../../main.php"); } else { 
    ?>
    Linux and UNIX cd command help and examples
    • [ 1 ] Thanks
    • [1] reply
    • Thanks a lot really appreciate your time. It worked perfect. I almost got that, I tried ./../ and didn't work. But thank for your time and knowledge. Now I will remember that for next time.
  • One other thing, I see your sending headers to redirect the user:
    however your not exiting the script, so the redirect wont actually happen the page will just continue to load.

    in your if do:
    {
    header('location: mylocation');
    exit();
    }
  • hehe yeah,

    the PHP code is a little bit "strange"

Next Topics on Trending Feed