tags:

views:

49

answers:

2

I have these declared

$username = $this->users->getUsernameById($file->user);
$sessionuser = $this->session->userdata('username');

How would i go about comparing to the two values and if they match, execute code. I had

if ( $username == $sessionuser){

blalghalhalhalhllahblahhblahhblahhh }

However, even when the two variables are the same, it doesnt seem to trigger the if statement, did i do something wrong? maybe not ==, just =???

+2  A: 

Use strcmp() function - or strcasecmp() for case-insensitive comparison.

if ( strcmp($username, $sessionuser) == 0) {
ChssPly76
+2  A: 

Generally speaking PHP is very forgiving when it comes to comparison operations because of the loosely typed dynamic nature of the language.

Try this to debug your code:

echo $username . '<br/>' . $sessionuser;

You may find that the values you are expecting aren't actually the values you're getting.

Another thing that I frequently have to do when stepping through my code is to place something like this:

echo 'got here';
exit;

immediately inside the if block to very whether it is that the block is not executing or whether it is the code within the block that is not executing as I expected it to.

Noah Goodrich