-
-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
env vars not loading inside iframe #167
Comments
If you load the iframe url directly (i.e. not in an iframe), do you see the same error? Most likely, your file_using_env_vars.php isn't loading the phpdotenv to parse your .env file. |
@rquadling That's an error in the example. I use Yii2, so there's no actual HTML pages. It's all processed by the framework's MVC. .env works everywhere, except in iframes. When I load the URL directly it works. It only doesn't work when it's loaded in the iFrame, but it does work if the iFrame is refreshed later manually or using Javascript. |
I think you are seeing the putenv() issue that PHP has. |
@rquadling Very interesting. This definitely explains some of the other issues I've had. I'll use my framework's global variables to load my configurations instead. |
I have a PHP project running on Yii2 (configured to use
https
on localhost, no certiciate). I'm using a.env
file with thevlucas/phpdotenv
package to load my config variables.When I have a page containing an iframe, and the iframe wants to access env vars, all env vars return 0. When I reload the iFrame using Javascript after the page has completely loaded, the env vars are loaded properly into the iframe.
For example:
index.php:
file_using_env_vars.php:
<?=getenv('SITE_NAME')?>
The site name is displayed if the php file is loaded directly in the browser, or if it's (re)loaded using Javascript after a few seconds. It never displays properly if the iframe is loaded normally using
src
.The text was updated successfully, but these errors were encountered: