Skip to content

Check if current PHP page name is the one you’re looking for.

Share Button
 <?php 

/** Check if current page is a specific one we're looking for */
function isPage($checkpage){
    
    /** Check basename of the file 
    *   basename returns trailing name of the component/file */
    $page = basename(__FILE__);
    
    /** Add .php extension to given argument 
    *   so we don't need to specify it when calling function */
    $checkpage .=".php";
    /** Perform checks */
    if($checkpage == $page){
        /** Return page name */
        return $page;
    } else {        
        return false;
    }
}

/** Change name of the file/argument and do something with the function...*/  
if(isPage("smallFunctions")){
    echo "Correct Page Check";
}

?>
Share Button