0

Have built a login system, I can assign permissions to a user which lets them access a page or not, all works fine. Currently if the user is logged in it and has permission is shows the content and if not logged in it redirects to login page.

I am trying to add a redirect in so that if you are logged in but do no have permission then it takes you to the page which has information on the product.

I have it currently set up as :

 <?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))){
     *do something*

    (more code)

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

I know I could do going through and say "If permission is not this then do this" but I have over 20 permissions currently and climbing. I was trying something like:

    if ($loggedInUser <> 3){
        header( 'Location: http://www.yoursite.com/new_page.html' ) ;
        }

However it parses but displays no result, I'm guessing its something to do with the variable being empty?

Any ideas on the best workout please?

Marriott81
  • 275
  • 2
  • 16

2 Answers2

1

It seems like you mixed objects and variables.

Judging by

($loggedInUser->checkPermission(array(3)))

$loggedInUser should be an object.

But then you try to compare an object with an integer. May be, you forgot a method? Smth like

if($loggedInUser->id!=3)
Jehy
  • 4,729
  • 1
  • 38
  • 55
  • This method is great and works, my only problem is if you have permission if redirects you and if you dont it lets you view the content.. – Marriott81 Mar 06 '14 at 12:05
0

turn on error reporting and check for any errors.
check for BOM characters in your output... they can prevent redirection
other than that, i cannot think of anything else to assist you

EDIT1: Help debugging var_dump() your variable and check the type (interger/string) you get. Perhaps you need to alter your if statements with === (if $a===$b), which checks value and type

For too many ifs... you can use switch..case statements, easier to debugging imo

andrew
  • 2,058
  • 2
  • 25
  • 33
  • @Marriott81 ok .. check the value of your variable (var_dump() it) perhaps you need to use === instead for your logic. IF (a===b) { do sometiing} – andrew Mar 06 '14 at 11:47
  • @Marriott81 you can use also switch...case if you got too many if statements - easier to debug – andrew Mar 06 '14 at 11:48