Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    ubh
    ubh is offline
    Regular Coder ubh's Avatar
    Join Date
    Apr 2008
    Location
    Portland, Oregon U.S.A.
    Posts
    443
    Thanks
    108
    Thanked 15 Times in 14 Posts

    On the fly "if" conditions deciding factor?

    Horrible thread title, but again would know how to word it... moving on.

    Is there something in PHP that would allow me to be a bit more divers about a if condition and its deciding factor on the fly?

    For instance I want to do a security check and make sure that anyone who has not be set with a authorized SESSION username will be redirected if the variable "pageName" equals any of the following. Something like this maybe?

    PHP Code:
    if(!isset($_SESSION['username']) && $pageName=="this"||"that"||"theOther"||"anythingElse")
    {
       
    header('Location: [url]http://www.website.com/home.php');[/url]

    Thanks for your time.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This part won't work: $pageName=="this"||"that"||"theOther"||"anythingElse", but otherwise you're good to go. I'd put those into an array, and make it simple:
    PHP Code:
    $aPages = array(
        
    'this',
        
    'that',
        
    'theOther',
        
    'anythingElse',
    );
    if(!isset(
    $_SESSION['username']) && in_array($pageName$aPages))
    {
        
    header....

    There is no rule that says you need to compare a variable to a constant, it is legal to do $this == $that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    ubh (04-12-2009)

  • #3
    ubh
    ubh is offline
    Regular Coder ubh's Avatar
    Join Date
    Apr 2008
    Location
    Portland, Oregon U.S.A.
    Posts
    443
    Thanks
    108
    Thanked 15 Times in 14 Posts
    Interesting. Thanks Fou-Lu, again

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Np.
    I should mention that I lied in my above post. $this is reserved for objects of course, so you can't use it as a variable: $that == $other
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    ubh
    ubh is offline
    Regular Coder ubh's Avatar
    Join Date
    Apr 2008
    Location
    Portland, Oregon U.S.A.
    Posts
    443
    Thanks
    108
    Thanked 15 Times in 14 Posts
    lol.. I did notice that, but I thought I would be reading to much into it. Comparing via $pageName, $aPages and the array was the light bulb I was looking for


  •  

    Posting Permissions

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