Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Created August 14, 2012 23:43
Show Gist options
  • Save larzconwell/3353920 to your computer and use it in GitHub Desktop.
Save larzconwell/3353920 to your computer and use it in GitHub Desktop.
<?php
// Get the "API_SECRET" variable from our shell session
$api_secret = getenv('API_SECRET');
// Same as above, but using a Superglobal
$api_secret = $_ENV['API_SECRET'];
// You can use phpinfo to show all the environmental variables you can use.
phpinfo(INFO_ENVIRONMENT);
/*
To set environmental variables you can do:
Linux/BSD:
API_SECRET=SOMESUPERSECRETKEYHERE
Note: you may need to export the key by prepending `export` to the above
Windows:
set API_SECRET=SOMESUPRTSECRETKEYHERE
*/
?>
@larzconwell
Copy link
Author

Once you do this, you don't have to worry about pushing secret keys to Git, you just have to create the environmental variables in the same shell session as when you run the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment