Skip to content
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

Closed
iadj opened this issue Mar 9, 2016 · 4 comments
Closed

env vars not loading inside iframe #167

iadj opened this issue Mar 9, 2016 · 4 comments

Comments

@iadj
Copy link

iadj commented Mar 9, 2016

I have a PHP project running on Yii2 (configured to use https on localhost, no certiciate). I'm using a .env file with the vlucas/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:

...
<!--full page content-->
...
<iframe src="file_using_env_vars.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.

@rquadling
Copy link

If you load the iframe url directly (i.e. not in an iframe), do you see the same error?
Is .html treated as .php by your server? If not, how can index.html process PHP code?

Most likely, your file_using_env_vars.php isn't loading the phpdotenv to parse your .env file.

@iadj
Copy link
Author

iadj commented Mar 10, 2016

@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.

@rquadling
Copy link

I think you are seeing the putenv() issue that PHP has.

#109
#76 (comment)

@iadj
Copy link
Author

iadj commented Mar 10, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@rquadling @GrahamCampbell @iadj and others