views:

47

answers:

2

Hi,

My web server has authentication enabled. When I access my web server i get a pop-up from browser for username and password. After logged in, I want to retrieve the username from the browser using javascript. I am not using any kind of form to get the username/password. So, I am not setting any cookies also. Can we use DOM method to access the username? or any other way?

Regards, Anandan

+1  A: 

As far as I know , you can't do that with javascript.

Check this link from php.net :

HTTP authentication with PHP : http://php.net/manual/en/features.http-auth.php

dejavu
Thanks. I will read about it.
Anandan
+1  A: 

I guess you're talking about a apache directory authentication (basic/digest) ? If so you can't do that directly using javascript. You need to provide session information (username) retrived at the server side and passed to your browser. i.e (php script passing a Json object)

Kami
yes. I am using basic auth. I will try the method you suggested. But is there any reason 'why we can't do it from java script?'
Anandan
You can't because javascript runs on the client side not on the server.
Kami