Jump to content

not really understanding this not!


scottybwoy

Recommended Posts

It checks if $this->authorise($user) not returns true (returns false). So if $this->authorise returns true if the user is authorized then it checks if the user is not authorized.

What happens if $user is null, empty, false or something similar depends on what is inside the function.

It's spelled authori[b]z[/b]ed by the way ;)
if $user is not populated then essentially the function call will look like
[code]
if (!$this->authorised())
[/code]

you need to look at the authorised method to see what will happen if a value is not passed. if it is nicely written then it will return false.  if the exception is not properly handled it may fail with an error.  alternatively the class may be written so that it is impossible for the $user variable not to be populated with something.

typically a function like this will return true or false but it can return anything.  assuming true/false: yes (to your first question) the antecedent (!) on the method call will mean "take the following action if the user is not authorised". 
OK, here is my autorise function :
[code]
<?php
function authorise($user)
    {
echo $user;

if ($user = TRUE)
{
$stmnt = "SELECT USER_ID FROM users WHERE uNAME = $user";
$result = mssql_query($stmnt);
if ($result != TRUE)
{
echo "You are not entered in the Database, please see the Administrator";
exit;

} else {

$success = TRUE;

}

} else {

$success = FALSE;
return $success;

}

    }
?>
[/code]

Is there a better way of writing it? What I want it to do is get the user to report to admin f they are not already in the database and if they are already in the database just go passed the original function to load the page.  Thanks
I would write it like this: [code]<?php
function authorise($user)
{
echo $user;

if($user == TRUE)
{
if(!mssql_query("SELECT USER_ID FROM users WHERE uNAME = {$user}"))
{
echo "You are not entered in the Database, please see the Administrator";
exit;
}
else {
$success = TRUE;
}
}
else {
$success = FALSE;
}

return $success;
}
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.