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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    IF statment problem with strstr()

    Hi guys, I'm having a problem with this IF statement. I need it to accept a variable so I can use this with more flexibility.

    Doesn't Work This Way
    if( !strstr( $_SESSION["rights"], $saccess))

    Works This Way
    if( !strstr( $_SESSION["rights"], '10'))

    I need to get the top one to work, what is wrong there? Or how can i fix it?

    Thanks in advance.

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    With that little bit of code, it is impossible to say. Where is $saccess set? I suspect it does not contain what you think it does.
    John

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    sorry i have a function which is included in the page

    <code>
    function veraccess() {
    if( !strstr( $_SESSION["rights"], '10')) { // if has privelages to access page
    $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
    //Check for trailing slashes
    if ((substr($url, -1) == '/') or (substr($url, -1) == '\\')) {
    $url = substr ($url, 0, -1);} //chop off the slash
    //Add the url page
    $url .= '/login.php';
    //redirect
    header("Location: $url");
    }}
    </code>

    and in the page it is set for
    $saccess = '10';

    The rights set up for the user i am testing is equal to "10"

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    is it '10' as a string, or 10 the number? strstr will return false if it's the latter...
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    Yes it's been returning false. In my database i have the privelages set up as VARCHAR and i have 10 entered.

    How can i convert it to a string? or should i just switch the sql database field?

  • #6
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    PHP Code:
    $bar 10;
    $foo = (string) $bar
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

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