Page 1 of 1

Environment username to php form

Posted: Wed Dec 29, 2010 8:54 am
by rmiddleton
Having searched for a couple of days I have yet to find the answer to what should be a simple and common issue.
How do I put the "logged in username" into a php form field?
For testing I tried this from the online manual at: http://www.php.net/manual/en/reserved.v ... onment.php

Code: Select all

<?php
echo 'My username is ' .$_ENV["USER"] . '!';
?> 
which displays blank.
However, from a cmd prompt (Windows 7) echo %username% correctly displays the logged in user.
Similarly I would like to capture the IP.
I see these done at many sites, but seem to be unable to find the solution.
Shouldn't I be able to set a PHP variable equal to an Environment variable?

Re: Environment username to php form

Posted: Wed Dec 29, 2010 1:59 pm
by McInfo
Try

Code: Select all

getenv('USER')
Be aware that this is the user on the server, not the client.

A likely reason you are unable to access the environment variables through $_ENV is that maybe the variables_order directive in php.ini does not contain an "E". It is recommended that you use getenv() instead.