Warran Posted June 16, 2023 Posted June 16, 2023 Hi, We have a web application and I am trying to use external php files as includes within templates. This is so we can centralise certain files that all instances of the web application commonly use. I am trying to work around the setting allow_url_fopen=0 which the host does not allow to be changed. So, something like this, after checking if the file exists, doesn't work. <?php $filename = "/some/external/path/external_file.php"; include($filename); Also tried with cURL to bypass allow_url_fopen=0. Any help would be appreciated. Thanks.
BitPoet Posted June 16, 2023 Posted June 16, 2023 Seems more like an open_basedir restriction to me than allow_url_fopen.
bernhard Posted June 16, 2023 Posted June 16, 2023 52 minutes ago, Warran said: We have a web application and I am trying to use external php files as includes within templates. This is so we can centralise certain files that all instances of the web application commonly use. It sounds like you are looking for sharing code/functionality across multiple instances. That's what ProcessWire modules are for. ? You put the logic in one module and all instances can use it. It's really just a few lines of code. Much simpler than in many other frameworks: https://processwire.com/docs/modules/development/
cwsoft Posted June 16, 2023 Posted June 16, 2023 @WarranDepending on what you want to achieve/include, AJAX requests may be used to load static texts (like cookie consent cards) as well.
Warran Posted June 28, 2023 Author Posted June 28, 2023 Thanks all I've been on holiday. Sorry for not replying sooner. cURL has worked now. It didn't work until the external file was a text file. Then I used curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); to get the contents and used filePutContents and a save path with a new extension of .php. <?php $externalFileURL = 'https://domain.com/files/filename.txt'; $ch = curl_init($externalFileURL); curl_setopt($ch, CURLOPT_URL, $externalFileURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $fileContents = curl_exec($ch); curl_close($ch); $savePath = $config->paths->templates . 'filename.php'; $files->filePutContents($savePath, $fileContents); include $savePath; ?> Thanks again
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now