Link to home
Start Free TrialLog in
Avatar of HamidHossain
HamidHossain

asked on

Auto Include a file

Hi,

Is there any way to inforce including a file into any php file user visits under my subfolder?

- root
     |
      --- subfolder
                 |
                  --- config.php
                 |
                 --- page1.php
                 |
                 --- page2.php

for example, I want to include config.php file if user visited page1.php or page2.php files. This inclusion must be automatic. I am not looking for using include() or require() etc... I am looking for some .htaccess command or something in this level.

Regards,
Hamid
Avatar of C0deJunkie
C0deJunkie

I do not believe this is possible, atleast not in php itself.

What you could do is use a script like below as index.php. That way the urls you use could stay almost the same and request the seperate scripts like this. Unfortunately, if its an existsing project, it might mean alot of adjusting links/redirects etc.

the original requests were:
page1.php?var1=2
page2.php?var3=4

that would become:
index.php?var1=2&src=page1
index.php?var3=4&src=page2

<?
    include 'config.php';
    include $_REQUEST['src'] . '.php'; //todo: you should encode the src variable to avoids hacks
?>
If your server supports it, you could create a .htaccess file in the subfolder that contains:

php_value auto_prepend_file "/full/path/to/root/subfolder/config.php"
so it is possible using a htaccess.. was wondering... :)
ASKER CERTIFIED SOLUTION
Avatar of benbalbo
benbalbo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:
   Split: Codejunkie, benbalbo

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

- Neester -
EE Cleanup Volunteer