Identify which page requests another through require_once

0

I have a header.php , where my page bar is contained, which in turn has the breadcrumb and also what I call the "Toolbar" which are the action buttons related to the page that is being accessed. For example:

When the user accesses the "Clients" module, they will access client-list.php , which require_once at header.php .

The problem is that each module will have different buttons, just like the user will have permissions. So by accessing client-list.php , header.php should show the relevant client-list.php buttons, also considering the permissions .

How can I make my header.php identify which page / module is calling it through require_once so that it shows information relevant to that page / module?     

asked by anonymous 14.05.2018 / 17:15

1 answer

2

In all page scripts you can create a constant like this:

<?php
define('PAGINA', basename(__FILE__));

require_once 'header.php';

And in header.php use if, switch or anything else, something like:

<?php
switch (PAGINA) {
    case 'client-list.php':
        //Botões especificos para client-list
        break;

    case 'contato.php':
        //Botões especificos para contato
        break;

}

Using $_SERVER['SCRIPT_FILENAME']

To simplify / facilitate, you can also change the% variable within the header.php and you will not need to do anything in the other scripts:

<?php
$pagina = basename($_SERVER['SCRIPT_FILENAME']);

switch (PAGINA) {
    case 'client-list.php':
        //Botões especificos para client-list
        break;

    case 'contato.php':
        //Botões especificos para contato
        break;

}
    
14.05.2018 / 17:25