Jump to content

Archived

This topic is now archived and is closed to further replies.

johnsiilver

How to access environmental variables from commandline php

Recommended Posts

I was hoping someone might be able to point me in the right direction.

I have a webbased php script that exec()'s some php commandline scripts.  These scripts log onto various machines and do work, and I would like to avoid passing the password on the commandline, which could be seen by someone doing a 'ps -ef'.  I've been trying to set an $_env[], $_session[], or a $global[] variable and have it read by the commandline script, but no luck.

Anyone know how to do this?  Thanks!

Share this post


Link to post
Share on other sites
In Apache you can use, the [b]SetEnv[/b] directive, other servers also support it, but in different ways. You can also set it via htaccess, so as to restrict who can access that environment variable! You can't set a $_ENV['var'] in PHP and expect it to be available from other scripts, it doesn't work that way. PHP can only write to the $_ENV array in it's local context, only the server has global scope! Unless you use the prepend file option within PHP, via htaccess, per directory option!

me!

Share this post


Link to post
Share on other sites
[quote]I've been trying to set an $_env[], $_session[], or a $global[] variable and have it read by the commandline script, but no luck.[/quote]

Maybe because they are $_ENV[], $_SESSION[] and $GLOBALS[] respectfully.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.