View Full Version : IF statment problem with strstr()
macleodjb
12-31-2007, 04: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.
PappaJohn
12-31-2007, 05: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.
macleodjb
12-31-2007, 05:20 PM
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"
is it '10' as a string, or 10 the number? strstr will return false if it's the latter...
macleodjb
12-31-2007, 06: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?
$bar = 10;
$foo = (string) $bar;
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.