SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is this line doing??

    I am trying to make it so that only people with access rights of A can access a particular part of the site. But I ma struggling to get it to work.

    Where am I going wrong?? The code below is what I am trying to use

    Cheers

    Code:
    <?php
    session_start();
    if ($_SESSION["accessrights"] === 'B' || 'C'){
    header ( 'location: /' );
    exit;
    }
    ?>

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It checks whether a session variable called "accessrights" is either "B" or "C", and if so, redirects the user to the site's home page and terminates the script.

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    pretty sure you cant short cut in that way.
    PHP Code:
    if ($_SESSION["accessrights"] == 'B' || $_SESSION["accessrights"] == 'C'){ 
    and === means identical.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right so it should work shouldn't it. If i have access right so f A then i should be able to get past that page, but if i have b or c then i can't and will not be able to enter.

    Cheers

  5. #5
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Struggling View Post
    I am trying to make it so that only people with access rights of A can access a particular part of the site. But I ma struggling to get it to work.

    Where am I going wrong?? The code below is what I am trying to use

    Cheers

    Code:
    <?php
    session_start();
    if ($_SESSION["accessrights"] === 'B' || 'C'){
    header ( 'location: /' );
    exit;
    }
    ?>
    if ($_SESSION["accessrights"] === 'B' || 'C') is illogical. You cant use compound statements like this in branch declarations. The correct statement,

    if ($_SESSION["accessrights"] === 'B' || $_SESSION["accessrights"] === 'C')
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  6. #6
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers guys go that sorted now.

    Thanks

  7. #7
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you only want people with access rights of A to access it, wouldnt it be better to use

    PHP Code:
    $_SESSION["accessrights"] !== 'A' 
    ?

    What happens if you add a D later on? They would be able to access the page as well, and you probably don't want them to.

  8. #8
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    How about:

    PHP Code:
    if ($_SESSION["accessrights"] !== 'A' ){
    // relocate and exit

    } else {
    // loads of code 


    Last edited by Cups; Nov 25, 2008 at 08:38. Reason: dohh .... beaten too it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •