Function valid for all pages

Asked

Viewed 61 times

2

It is possible to set a function for all pages without using include() in all of them?

  • Ex: I have a secret directory ../seg/staff/login/ and want to define which user with permission level less than 3 can not access them.

Could create a file seg.php:

if($nivel < 3){
    echo ("Você não possui permissão para isto.");
}

And call him too much with include("seg.php").

Now let’s say I have 70 pages. Is there any possibility I can define this in some .htacess or another without having to put require(""), include(""), etc. in all files?

  • 2

    I see a lot of people suffering to do basic things by not knowing or even not interested in using some framework development, people, we do not need to suffer with the development of basic things in the nail, there are already many people working to make it ready for us, I suggest you take a look at Laravel, or any other Development Framework PHP...you will get this, and thousands of other problems solved easily...

  • 1

    @Kennyrafael Blz never really went after framework I will try to take a look at it. Thank you for the feedback

  • 1

    At best, if you only have PHP files in the directory, that’s only and only pure PHP, then you will only have one <?php by file, this way you can use your Editor/IDE to replace all <?php for <?php include("seg.php");, this way all files in the directory will have the include("seg.php"). Now, if you join PHP with HTML and have more than one possibly have more than one <?php, then you’ll have a problem.

1 answer

2

You can use the PHP "auto_prepend_file" directive, this will include your logic on all pages.

  • Where does this directive go? could you give an example.

  • @rray can be in . htaccess # just put here the path of your script to be included in your pages # ---------------------------------------------------------------------- php_value auto_prepend_file "/path-to-script/your-script.php"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.