Jump to content

Recommended Posts

Posted

We have an intranet running on a Windows Server 2008 box, however the server has no AD on it (just a member server). Mostly the pages are html/php, however I am wanting to make some student/staff specific pages, so for instance when staff load the internet, their home page will differ (or have different access) to a student.

 

I can't seem to find an easy way (or just a way at all) to grab this info with php. What's the easiest way to get the username of the logged on user? I don't want to be messing around with login boxes, just something simple that works automatically (in the sense of needing no user input).

 

TIA.

Posted

Given your signature, I think that the answer is "you can't"

 

If you're using Internet Explorer rather than Firefox then turn on windows authentication for the web site and IE will pass the username to the site; I've not done this with PHP but a quick google suggests that $_SERVER['PHP_AUTH_USER'] will give you the info.

  • Thanks 1
Posted

Although my preference is firefox, in the school environment, we use internet explorer given security settings can be set centrally :)

 

Just checked what features we have installed on the server and although "basic authentication" is there, I didn't choose "windows authentication" when setting it up - I am guessing this is what we need? I'll install this and try that command above!

Posted

Basic authentication will always prompt for username and password; it's the most flexible in that it will "just work" with pretty much any browser. It really needs to be done with https (because the password is in clear text - watch it with Wireshark if you want to see!)

 

Integrated/Windows auth uses NTLM challenge/response. It's good for intranets because you know what browsers are being used and can control their settings (so if IE is standard it will "just work")

 

In theory, if you have a web site setup to use Windows and basic auth, the browser should use the most secure one (ie Windows auth) and fall back to basic if it can't do that. In reality, I've had problems with this (but it's a while since I've tried so it could be better now)

  • Thanks 1
Posted

Yup, well I installed windows authentication and fiddling around with some of the $_SERVER bits managed to get what I need. Just have to work out tokens now to get rid of the DOMAIN\ before USERNAME, but i'm guessing that shouldn't be too big a job.

 

Cheers for the advice(s).

Posted
//Presuming $user is the "domain/user"

$arr = explode("/", $user);
$domain = $arr[0];
$username = $arr[1];

 

It's in the format domain\user (slash the other way). When I change the / for \ I get a 500 error (FasgCGI module is mentioned in detailed info), which is most bizarre. My workaround is to just get the name by substr() and collecting data so many chars in (so that is starts where the username starts). Not ideal, but I can't see why using \ in substr gives me an error..

Posted

use of the \ usually implies you want to use the next character in the line, I think double \\ is the way around...

 

$arr = explode("\\", $user);

 

Using substr doesn't present too much of an issue that I could see, unless you wanted it to be cross domainable.

  • Thanks 1
Posted

Good stuff - that worked. Yes substr worked ok too, but I prefer code to be a simple as possible, and using explode seems a bit more easier to display just the bits you want.

 

Cheers for all the responses.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...