sonners Posted October 17, 2006 Share Posted October 17, 2006 Ok when I say I am a novice - I really do mean I am clueless.Q.I have a folder with access restricted using .htpassd.The user types in username and password into the window box.They go to a shtml page. How do I get the username that they type in to appear on the shtml page as "Hello, username"I have tried all these scripts and none work:<?php$usera = $_SERVER["PHP_AUTH_USER"];echo 'Current user is'.$usera.;?><?php$userb = $_SERVER['REMOTE_USER'];echo 'Current user is'.$userb.;?><?phpif (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401 Unauthorized'); echo 'Text to send if user hits Cancel button'; exit;} else { echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>"; echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";}?> Quote Link to comment https://forums.phpfreaks.com/topic/24218-user-authentication/ Share on other sites More sharing options...
HuggieBear Posted October 17, 2006 Share Posted October 17, 2006 My advice would be to do this...1. Create a serverparams.php page that looks like this:[code]<?phpforeach ($_SERVER as $k => $v){ echo "$k - $v<br>\n";}?>[/code]2. Upload that to an area within your secured folder.3. Open the serverparams.php file in your browser, you'll be asked to login.4. Check that the PHP_AUTH_USER and REMOTE_USER actually contain values.Let me know the outcome.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24218-user-authentication/#findComment-110133 Share on other sites More sharing options...
sonners Posted October 17, 2006 Author Share Posted October 17, 2006 HuggieB - thanks so much for your reply!I did what you said and PHP_AUTH_USER PHP_AUTH_PWREMOTE_USER all have values that are correct. Quote Link to comment https://forums.phpfreaks.com/topic/24218-user-authentication/#findComment-110225 Share on other sites More sharing options...
HuggieBear Posted October 18, 2006 Share Posted October 18, 2006 In that case, just use the following...[code]<?php$username = $_SERVER['PHP_AUTH_USER']; // Notice the single quotesecho "Welcome {$username}<br>\n";?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24218-user-authentication/#findComment-110433 Share on other sites More sharing options...
sonners Posted October 18, 2006 Author Share Posted October 18, 2006 thanks HuggieBear - that works perfect. It looks like my syntax was all wrong!I had to include the php file as an SSI to get the php to render but it works. Txs again!s Quote Link to comment https://forums.phpfreaks.com/topic/24218-user-authentication/#findComment-110573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.