Jump to content


Photo

How to access environmental variables from commandline php


  • Please log in to reply
2 replies to this topic

#1 johnsiilver

johnsiilver
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 October 2006 - 01:39 AM

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!

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 20 October 2006 - 01:58 AM

In Apache you can use, the SetEnv 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!

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 October 2006 - 01:59 AM

I've been trying to set an $_env[], $_session[], or a $global[] variable and have it read by the commandline script, but no luck.


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users