Use php file from other directory and include file from current directory -


suppose, have 3 directories a, b , c along engine directory.

now want post search query via post request ../engine/search.php in index file of a, b , c, tell file search.php include config.php file respective directory (with different parameters search). i.e. cannot include ../[a,b,c]/config.php in engine/search.php since depends on search called from.

is there way without having keep separate copy of search.php in each directory , including directly config file respective directory? should possible, since similar multisite php setups exists (e.g. wordpress mu).

maybe __dir__ give path of php file gets called rather located.

for security reasons, not want pass paths part of post request.

after comments on question clarifying you're attempting...

one thing can include hidden field in search forms indicating "type" of search is. simple as:

<input type="hidden" name="searchtype" value="searcha" /> 

then in server-side code can determine file include based on value. this:

switch ($_post["searchtype"]) {     case "searcha":         include("../a/config.php");         break;     case "searchb":         include("../b/config.php");         break;     // etc. } 

that way config determined dynamically form being posted, , not relying on state tracked server-side form loaded.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -