0

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
  • Which web server? Are you using a server-side framework? Commented Aug 3, 2010 at 7:21

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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)

2 Comments

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?'
You can't because javascript runs on the client side not on the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.