我爲了我的PHP代碼趕上DOS環境%USERNAME%
很多測試,我的操作系統是Windows 7我如何在PHP
這將使我php
程序知道當前登錄到網絡的用戶名。
這裏的一些測試運行在環境Wamp
和Xampp
。
任何幫助,將不勝感激。
<?php
session_start();
//1°test, not ok
//echo "user=". $username;
//2° test, not ok
//echo 'My username is ' .$_ENV["USER"] . '!';
//3°test in this case I get back "user-pc$" . It's not correct , the right username - logged in in Windows 7 operating system - is "user".
//infact I got "user" value running from command line "cmd" the "set username" command.
$user_name = getenv('USERNAME');
echo "username=".$user_name."<br>";
// running phpinfo I see as USERNAME "user-pc$" but unfortunately this is not the right value
phpinfo();
這裏的基本問題是,類似這樣的結果將基於Apache登錄的帳戶,並且對於wampserver或xampp將是'nt權限\系統'而不是'Valgo' – RiggsFolly
我的答案是否奏效? – Sharky