0

I'm trying to get the %username% in my intranet site to automatically log in the users but I'm not able to get this env. variable.

I changed the "variables_order = "GPCS"" to "variables_order = "EGPCS"" in my PHP.ini.

I displayed the _ENV variables in my code : global $_ENV; var_dump($_ENV); and i get this :

array(11) { ["APACHE_RUN_DIR"]=> string(16) "/var/run/apache2" ["APACHE_PID_FILE"]=> string(28) "/var/run/apache2/apache2.pid" ["JOURNAL_STREAM"]=> string(11) "8:405225026" ["PATH"]=> string(60) "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ["INVOCATION_ID"]=> string(32) "3e8569ce22454bd5b51b1ee4d8902385" ["APACHE_LOCK_DIR"]=> string(17) "/var/lock/apache2" ["LANG"]=> string(1) "C" ["APACHE_RUN_USER"]=> string(8) "www-data" ["APACHE_RUN_GROUP"]=> string(8) "www-data" ["APACHE_LOG_DIR"]=> string(16) "/var/log/apache2" ["PWD"]=> string(1) "/" }

But when I try this echo getenv("username");, I get nothing , do you know why ?

Thank you !

Beko
  • 37
  • 5
  • Well, as you can clearly see when you dumped `$_ENV` there is no field called "username" in there, so `getenv()` will also give you nothing. That means the value you are looking for sin't loaded. – Tobias F. Feb 06 '20 at 11:00
  • Is this any way to enable it ? – Beko Feb 06 '20 at 11:13
  • 1
    `%username%` is probably only set in interactive terminal windows, not background processes like the webserver. – Barmar Feb 06 '20 at 11:25
  • You can use [`putenv()`](https://www.php.net/manual/en/function.putenv.php). But it will only exist for the duration of the current request. – N'Bayramberdiyev Feb 06 '20 at 11:35
  • Does this answer your question? [How to check what user php is running as?](https://stackoverflow.com/questions/7771586/how-to-check-what-user-php-is-running-as) – Daniel Protopopov Feb 06 '20 at 12:12
  • Generally when you run php interactively (through a web server), the username equals to the user under whom the web server is ran (usually it’s www-data on NIX servers). When you run PHP under console, you can use POSIX functions posix_getpwuid / posix_geteuid. – Daniel Protopopov Feb 06 '20 at 12:13
  • After hours of research, I founded a script which work ! https://forum.hardware.fr/hfr/Programmation/PHP/php-sso-ldap-sujet_138217_1.htm – Beko Feb 06 '20 at 13:01

0 Answers0