1

Currently using this to check the permissions of a user, If the user is logged in then it shows the file and lists the DIR. This works fine along with the login screen showing up if the user is not shown to be logged in.

I need it to be that if the product is not owned by the user (i.e. the permission is not level 3) then it will automatically link them to the brochure. I had a header setup to send the user but it does not function as I want it to.

Now what it does is loads the page but does not pass on the DIV (hence the name to check on the f12 debug to see if it had passed)

What am I missing?

p.s. the PHP logs show no errors

-- Update --

Gone through and commented out sections to see if the IF statement was attached to wrong thing, currently nothing still getting same problem

<?php

if (!securePage($_SERVER['PHP_SELF'])){die();}
$parts = parse_url($_SERVER["REQUEST_URI"]);
$page_name = basename($parts['path']);

//Links for logged in user
if(isUserLoggedIn()) {

    //Links for permission level 3 (BOF)

    if ($loggedInUser->checkPermission(array(3))){
        if ($handle = opendir('CD500/')) {
            while (false !== ($file = readdir($handle)))
                {
                    if ($file != '.' && $file != '..'){
                        $thelist .= '<a href="/CD500/'.$file.'" target="_blank" >'.$file.'</a></br>';
                    }
                }

            closedir($handle);


            echo "
                        <div id='output'>
                        List of help files:</div>
                        <div id='List'>
                 $thelist ";
        }

        else {

            echo " asdfasdfasdfadf ";

        }

    }   

    ?>

    <div id='default'>
    <?php } else { ?>

<li><a class="<?php echo ($page_name=='login.php')?'selected':'';?>" href="login.php">Login</a></li>
     <li><a class="<?php echo ($page_name=='register.php')?'selected':'';?>" href="register.php">Register</a></li>
     <li><a class="<?php echo ($page_name=='forgot-password.php')?'selected':'';?>" href="forgot-password.php">Forgot Password</a></li>
     <?php } ?></div>
Marriott81
  • 275
  • 2
  • 16
  • Where do you set `$loggedInUser`? – Barmar Mar 12 '14 at 14:20
  • As you can see by the proper indentation - the `else` is applied to `.. = opendir(..)` and not the `checkPermission()`! – kero Mar 12 '14 at 14:21
  • @kingkero ah yea I can see that, best way to fix it? and its set on the login page I believe – Marriott81 Mar 12 '14 at 14:25
  • @Marriott81 move the `else` clause where it belongs! And in the future please indent your code as it should be, then mistakes like this will be of the past – kero Mar 12 '14 at 14:27
  • as in just move it back? I am confused @kingkero .. – Marriott81 Mar 12 '14 at 14:29
  • Which variable does it not pass when redirecting? I don't see you sending/storing any. – Alderis Shyti Mar 12 '14 at 14:38
  • Realized I posted the backup, where the header is I changed it to be a div just to see if it passed it but it is not @AlderisShyti – Marriott81 Mar 12 '14 at 14:41
  • I still don't understand what `$variable` you want to send and to where. You say you have a problem with the else clause where you have the header. The header redirects you to "new_page.html" and nothing else. Currently you are not posting anything anywhere. Do you need to pass something to that page from this one here? – Alderis Shyti Mar 12 '14 at 14:47
  • @AlderisShyti the plan was, if you have permission you see the DIR, if you do not it redirects you, If i add an "!==2" so the else then it will send you to the newpage, problem is I need it to be 3 now 2. Currently I want it to move you to the new page. However I changed the Header to a div to check for errors, when I pushed f12 on crome the DIV was not there I.E not been passed to the web browser – Marriott81 Mar 12 '14 at 14:50
  • Your else clause containing the header is not triggered when `($loggedInUser->checkPermission(array(3)))` is false but belongs to your inner `if` --> `($handle = opendir('CD500/'))`. Check that. Like mentioned before you have your else clause in the wrong place. – Alderis Shyti Mar 12 '14 at 15:00
  • @AlderisShyti have gone through and commented out sections and replaced to see, still nothing still going it, Am I missing a } too or is it just me? – Marriott81 Mar 12 '14 at 15:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/49577/discussion-between-alderis-shyti-and-marriott81) – Alderis Shyti Mar 12 '14 at 15:10

1 Answers1

1

The problem lies at your else clause not belonging to your first if statement where you check for user login. I have also changed the code a bit at the point where you need to conditionally print some html. Try the following.

<?php

if (!securePage($_SERVER['PHP_SELF'])){die();}
$parts = parse_url($_SERVER["REQUEST_URI"]);
$page_name = basename($parts['path']);

//Links for logged in user
if(isUserLoggedIn()) {

    //Links for permission level 3 (BOF)
    if ($loggedInUser->checkPermission(array(3))){

        if ($handle = opendir('CD500/')) {

            while (false !== ($file = readdir($handle))){
                if ($file != '.' && $file != '..'){
                    $thelist .= '<a href="/CD500/'.$file.'" target="_blank" >'.$file.'</a></br>';
                }
            }

            closedir($handle); ?>

            <?php if($thelist): ?>
              <div id='output'>
                List of help files:
              </div>

              <div id='List'>
                  <?php echo $thelist; ?>
              </div>
            <?php endif; ?>

<?php   }

    } else {
        header( 'Location: http://www.yoursite.com/new_page.html' ) ;
    }

} else { ?>

<div>
  <li><a class="<?php echo ($page_name=='login.php')?'selected':'';?>" href="login.php">Login</a></li>
  <li><a class="<?php echo ($page_name=='register.php')?'selected':'';?>" href="register.php">Register</a></li>
  <li><a class="<?php echo ($page_name=='forgot-password.php')?'selected':'';?>" href="forgot-password.php">Forgot Password</a></li>
</div>

<?php } ?>
Alderis Shyti
  • 278
  • 1
  • 8