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 ;)
Link to comment
Share on other sites

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". 
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.