Thread: Check my code
View Single Post
Old 10-04-2007, 06:43 PM   #4 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

When you're checking that the visitor is authorised to view the page, if the check fails you should display the message and stop the execution of the script immediately. That way you can get rid of the else safely and know that the script will run only if logged in.

Yours
PHP Code:
    //
    // Check if user is logged in
    //
    
    
if($auth->check() == false || $auth->admin_auth() == false){
        echo 
'Please login as administrator';
    } 
Suggested alternative
PHP Code:
    //
    // Check if user is logged in
    //
    
    
if($auth->check() == false || $auth->admin_auth() == false){
        
//echo 'Please login as administrator';
        
$tpl->assign('szErrorMessage''Please log in as administrator.');
        
$tpl->display(ADMINTEMPLATE_PATH.'error.tpl.php');
        exit; 
// I don't know if $tpl->display() stops the script, so exit here.
    

I haven't looked below the first else yet, so there may be more comments to follow. :)
Salathe is offline  
Reply With Quote