开发者

Can I make a php file become a package or library?

开发者 https://www.devze.com 2023-02-26 20:25 出处:网络
I have a utility.php file, but I would like to build it become a library, or something else, just don\'t want people can\'t access the utility.php directly, but they can access it via other page, for

I have a utility.php file, but I would like to build it become a library, or something else, just don't want people can't access the utility.php directly, but they can access it via other page, for example, a register.php, can use the utility.php, how can 开发者_运维问答I do so? Thank you.


Something like this:

<?php //utility.php
    if(!defined('UTILITY_INCLUDED'){
         die('Grrrr...');
    }
?>

and then like this:

<?php //yourFile.PHP
    define('UTILITY_INCLUDED', TRUE);
    include ("utility.php";
?>

You have many other options to protect utility.php

  • Put it some other directory, and prevent access through .htaccess file
  • Use count(get_included_files())==1.. etc


You could include utility.php into any other PHP file. For example:

 //Register.php

 include('utility.php');

 //Use any functions from the utility.php file
 utility_function();
0

精彩评论

暂无评论...
验证码 换一张
取 消