.htaccess Login prompt - How do I get the users name
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- .htaccess Login prompt - How do I get the users na...
.htaccess Login prompt - How do I get the users name
16-04-2008 1:34 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
How do I get the name of the user that has just logged on so that my PHP news article page can display 14 April 2008 ~ A News Story ~ written by <username>
I've tried the obvious $_SERVER variables but I cannot get the user name to display.
http://www.jnmbc.co.uk/tameside will give you an example of the news articles that have been written (minus the author's name)
Re: .htaccess Login prompt - How do I get the users name
17-04-2008 8:50 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: .htaccess Login prompt - How do I get the users name
17-04-2008 5:25 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: .htaccess Login prompt - How do I get the users name
18-04-2008 8:25 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I've tried that one, it was one of the most obvious of the $_SERVER variables but alas, no joy!
A simple test that i tried was
<?php
$usr = $_SERVER['PHP_AUTH_USER'];
echo = "Hello $usr";
?>
The layout is as follows:-
The main part of the website is available for free vieweing by the entire world. Lets say a user clicked on the 'Admin' link. He would be directed to 'admin/protected/index.php'
Inside a folder called 'admin' there is the .htpasswd and .htaccess and a sub folder called 'protected'
All my user sensitive files and folders live in the 'protected' folder. (It's done this way because php files are not protected by the .ht* files.)
That means, everything from 'protected' downwards can only be viewed once the user has logged on.
When the user that just logged on arrives at index.php, he would be greeted with 'Hello Peter' and when he writes a news article, it would be displayed with him as the author.
ChrissyD. Thanks also for your response. I had tried PHPFreaks but again, they say the same as Peter and the $_SERVER variables.
http://www.php.net is a great source for PHP functions by the way
Re: .htaccess Login prompt - How do I get the users name
18-04-2008 9:01 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
jelv (a.k.a Spoon Whittler) Why I have left Plusnet (warning: long post!) Broadband: Andrews & Arnold Home::1 (FTTC 80/20) Line rental: Pulse 8 Home Line Rental (£14.40/month) Mobile: iD mobile (£4/month) |
Re: .htaccess Login prompt - How do I get the users name
18-04-2008 9:04 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Peter, Can you confirm if this could be the case?
Re: .htaccess Login prompt - How do I get the users name
18-04-2008 6:11 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
The way I managed to get it working was via a frame redirect on my homepages server. The .htaccess/.htpasswd files and login occurred on my www webspace and the framed .php file from the ccgi server had the PHP_AUTH_USER value set correctly. I doubt that is an option for you though.
Re: .htaccess Login prompt - How do I get the users name
20-04-2008 12:02 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
you could just do what everyone else does, (as most Content Management Systems work)
and have a MySQL Database with a User Table and make it all Dynamic so that calling information is easier.
Then have a separate Table which contains the News Items, and create admin pages to manipulate that.
It would als obe possible then for any other aspects of your webite if you created a table for permissions or even bundled that in the User table and make a means of working around that.
You can "Protect" PHP Files from being executed directly on requests,
it's just you haven't figured it out yet.

I can provide a solution to that one just it depends on which method you have your heart set.
If you really want to use .htpasswd / .htaccess alot - by no means am I a judge of correct methodology.
Jim,
Re: .htaccess Login prompt - How do I get the users name
21-04-2008 8:29 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Peter: You are right, the framed option isn't really one i fancy but thanks for confirming that the PHP_AUTH_USER value does not get set and thats why I cant read it.
Prod_Man: I did consider the users database table as an option and I don't particularly have my heart set on the .htaccess method but i do like it and beleive it to be quite secure.
I have previously written an asp web application with MS Access as a data source and for that i used a users table in the database and that was okay but I found the .htaccess method more suitable for my current project.
I may switch over to the table method though because of the problems detailed in this thread.
I am interested to hear the one about protecting PHP files. My PHP files are protected because they are in a folder that is protected by .htaccess/.htpasswd or have I missed something?
Please let me know on this one

Thanks
Re: .htaccess Login prompt - How do I get the users name
21-04-2008 11:11 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: .htaccess Login prompt - How do I get the users name
21-04-2008 11:22 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Scroll down to the very bottom - there you will find a link.
jelv (a.k.a Spoon Whittler) Why I have left Plusnet (warning: long post!) Broadband: Andrews & Arnold Home::1 (FTTC 80/20) Line rental: Pulse 8 Home Line Rental (£14.40/month) Mobile: iD mobile (£4/month) |
Re: .htaccess Login prompt - How do I get the users name
21-04-2008 1:40 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
It looks like a very good bit of kit. Maybe a bit big for my current needs but it's made me think about expanding on what i've got and including a blog.
I have downloaded it and if i don't use it on my current project, i suspect it will form a big part of my next project.
Thanks again
Re: .htaccess Login prompt - How do I get the users name
21-04-2008 9:22 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
your PHP files are (or at least should be, as I don't know of any exploits off hand)
Protected with reguards to .htaccess being processed by the Webserver. xD
Good to know you have knowledge of Server Side Scripting with ASP and Database stuff SQL already down.

I meant more protecting PHP execution, just with in it's own execution as scripts, it's not too hard.
It also comes with preventing SQL injection fairly effectively, this is especially with longin pages and it all works within PHP functionality.
It's alittle complicated to put in one Post but I can show the Method I've used if you PM me,
I can supply basic framework of Source for you to have a butchers.
As far as I know, this method hasn't been documented or used anywhere,
it certainly seems to protect against any SQL Injection i've tried,
and I should hope any random chances of crosssite scripting or code injection.
yes login may become slower with larger tables but I think it will save in the long run on Security.
Jim,
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- .htaccess Login prompt - How do I get the users na...