View Full Version : IF statment problem with strstr()

12-31-2007, 05:54 PM
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.

12-31-2007, 06:09 PM
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.

12-31-2007, 06:20 PM
sorry i have a function which is included in the page

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';
header("Location: $url");

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

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

12-31-2007, 07:01 PM
is it '10' as a string, or 10 the number? strstr will return false if it's the latter...

12-31-2007, 07:05 PM
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?

12-31-2007, 09:25 PM
$bar = 10;
$foo = (string) $bar;