Solved

PHP and NTLM in Apache

Posted on 2004-04-28
5
1,149 Views
Last Modified: 2010-10-28
I'm trying to get NTLM to work on the following cofiguration:

Windows 2000
Apache 2
php-4.3.1

I have installed the module "mod_auth_sspi" for apache, and the authentication seems to work fine, becuase
when I try to access the site using netscape I get asked for my NT credentials.
But I am having problems exctracting the username in my PHP code, I've tried the following code:
----------------------------------------------------------------------------------------------------
echo "Your username is: ".$SERVER["AUTH_USER"];
echo "<br>";
echo "The authentication type is: ".$_SERVER["AUTH_TYPE"];
echo "The digest of your password is: ".$_SERVER["HTTP_AUTHORIZATION"];
echo "<br>";
echo "The username of the server user is: ".$_SERVER["LOGON_USER"];
----------------------------------------------------------------------------------------------------
But I get no results.

Anyone know what might be wrong?
0
Comment
Question by:malikatwork
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:BrianPap22
ID: 10942894
put this in your page somewhere:


<pre>
<?php print_r($GLOBALS); ?>
</pre>

Pay particular attention to the $_SERVER section of the array.

(Also, <?php phpinfo(); ?> might be a good idea (must do it separately I think)).

BTW, the first line in your code says "$SERVER", which of course should be "$_SERVER".  That isn't what's causing your problem, but you may want to double-check that you don't have similar errors.  Putting "error_reporting(E_ALL);" at the top of your script is always a good idea for debugging purposes (make sure to remove it once the website goes live). This may help you to find some of those mis-typed variables.

Some more code might be nice.  But then again, there might not be anything wrong with your code at all. It might be an installation/configuration problem.
0
 
LVL 5

Expert Comment

by:apparition
ID: 10944388
This is the result I get when I tried
<pre>
<?php print_r($GLOBALS); ?>
</pre>

Array
(
    [HTTP_POST_VARS] => Array
        (
        )

    [_POST] => Array
        (
        )

    [HTTP_GET_VARS] => Array
        (
        )

    [_GET] => Array
        (
        )

    [HTTP_COOKIE_VARS] => Array
        (
        )

    [_COOKIE] => Array
        (
        )

    [HTTP_SERVER_VARS] => Array
        (
            [REDIRECT_STATUS] => 200
            [HTTP_HOST] => localhost:8080
            [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040206 Firefox/0.8
            [HTTP_ACCEPT] => application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
            [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
            [HTTP_ACCEPT_ENCODING] => gzip,deflate
            [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
            [HTTP_KEEP_ALIVE] => 300
            [HTTP_CONNECTION] => keep-alive
            [HTTP_REFERER] => http://localhost:8080/
            [PATH] => C:\\program files\\lotus\\notes\\;C:\\program files\\lotus\\notes\\data\\;C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;C:\\IMNnq_NT;C:\\j2sdk1.4.1_01; C:\\j2sdk1.4.1_01\\bin; C:\\j2sdk1.4.1_01\\bin;C:\\SQLLIB\\BIN;C:\\SQLLIB\\FUNCTION;C:\\SQLLIB\\SAMPLES\\REPL;C:\\SQLLIB\\HELP;c:\\wcsdevenv\\bin;C:\\apache-ant-1.5.4\\bin;C:\\j2sdk1.4.1_01\\bin;C:\\Program Files\\lotus\\notes
            [SystemRoot] => C:\\WINNT
            [COMSPEC] => C:\\WINNT\\system32\\cmd.exe
            [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
            [WINDIR] => C:\\WINNT
            [SERVER_SIGNATURE] =>
Apache/2.0.45 (Win32) mod_auth_sspi/1.0.0 Server at localhost Port 80


            [SERVER_SOFTWARE] => Apache/2.0.45 (Win32) mod_auth_sspi/1.0.0
            [SERVER_NAME] => localhost
            [SERVER_ADDR] => 127.0.0.1
            [SERVER_PORT] => 80
            [REMOTE_ADDR] => 127.0.0.1
            [DOCUMENT_ROOT] => C:/phpWeb
            [SERVER_ADMIN] => marefin@muscletech.com
            [SCRIPT_FILENAME] => C:\\phpWeb\\logintest2.php
            [REMOTE_PORT] => 2211
            [REDIRECT_URL] => /logintest2.php
            [GATEWAY_INTERFACE] => CGI/1.1
            [SERVER_PROTOCOL] => HTTP/1.1
            [REQUEST_METHOD] => GET
            [QUERY_STRING] =>
            [REQUEST_URI] => /logintest2.php
            [SCRIPT_NAME] => /logintest2.php
            [PATH_TRANSLATED] => C:\\phpWeb\\logintest2.php
            [PHP_SELF] => /logintest2.php
            [argv] => Array
                (
                )

            [argc] => 0
        )

    [_SERVER] => Array
        (
            [REDIRECT_STATUS] => 200
            [HTTP_HOST] => localhost:8080
            [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040206 Firefox/0.8
            [HTTP_ACCEPT] => application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
            [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
            [HTTP_ACCEPT_ENCODING] => gzip,deflate
            [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
            [HTTP_KEEP_ALIVE] => 300
            [HTTP_CONNECTION] => keep-alive
            [HTTP_REFERER] => http://localhost:8080/
            [PATH] => C:\\program files\\lotus\\notes\\;C:\\program files\\lotus\\notes\\data\\;C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;C:\\IMNnq_NT;C:\\j2sdk1.4.1_01; C:\\j2sdk1.4.1_01\\bin; C:\\j2sdk1.4.1_01\\bin;C:\\SQLLIB\\BIN;C:\\SQLLIB\\FUNCTION;C:\\SQLLIB\\SAMPLES\\REPL;C:\\SQLLIB\\HELP;c:\\wcsdevenv\\bin;C:\\apache-ant-1.5.4\\bin;C:\\j2sdk1.4.1_01\\bin;C:\\Program Files\\lotus\\notes
            [SystemRoot] => C:\\WINNT
            [COMSPEC] => C:\\WINNT\\system32\\cmd.exe
            [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
            [WINDIR] => C:\\WINNT
            [SERVER_SIGNATURE] =>
Apache/2.0.45 (Win32) mod_auth_sspi/1.0.0 Server at localhost Port 80


            [SERVER_SOFTWARE] => Apache/2.0.45 (Win32) mod_auth_sspi/1.0.0
            [SERVER_NAME] => localhost
            [SERVER_ADDR] => 127.0.0.1
            [SERVER_PORT] => 80
            [REMOTE_ADDR] => 127.0.0.1
            [DOCUMENT_ROOT] => C:/phpWeb
            [SERVER_ADMIN] => marefin@muscletech.com
            [SCRIPT_FILENAME] => C:\\phpWeb\\logintest2.php
            [REMOTE_PORT] => 2211
            [REDIRECT_URL] => /logintest2.php
            [GATEWAY_INTERFACE] => CGI/1.1
            [SERVER_PROTOCOL] => HTTP/1.1
            [REQUEST_METHOD] => GET
            [QUERY_STRING] =>
            [REQUEST_URI] => /logintest2.php
            [SCRIPT_NAME] => /logintest2.php
            [PATH_TRANSLATED] => C:\\phpWeb\\logintest2.php
            [PHP_SELF] => /logintest2.php
            [argv] => Array
                (
                )

            [argc] => 0
        )

    [HTTP_ENV_VARS] => Array
        (
            [REDIRECT_STATUS] => 200
            [HTTP_HOST] => localhost:8080
            [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040206 Firefox/0.8
            [HTTP_ACCEPT] => application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
            [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
            [HTTP_ACCEPT_ENCODING] => gzip,deflate
            [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
            [HTTP_KEEP_ALIVE] => 300
            [HTTP_CONNECTION] => keep-alive
            [HTTP_REFERER] => http://localhost:8080/
            [PATH] => C:\\program files\\lotus\\notes\\;C:\\program files\\lotus\\notes\\data\\;C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;C:\\IMNnq_NT;C:\\j2sdk1.4.1_01; C:\\j2sdk1.4.1_01\\bin; C:\\j2sdk1.4.1_01\\bin;C:\\SQLLIB\\BIN;C:\\SQLLIB\\FUNCTION;C:\\SQLLIB\\SAMPLES\\REPL;C:\\SQLLIB\\HELP;c:\\wcsdevenv\\bin;C:\\apache-ant-1.5.4\\bin;C:\\j2sdk1.4.1_01\\bin;C:\\Program Files\\lotus\\notes
            [SystemRoot] => C:\\WINNT
            [COMSPEC] => C:\\WINNT\\system32\\cmd.exe
            [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
            [WINDIR] => C:\\WINNT
            [SERVER_SIGNATURE] =>
Apache/2.0.45 (Win32) mod_auth_sspi/1.0.0 Server at localhost Port 80


            [SERVER_SOFTWARE] => Apache/2.0.45 (Win32) mod_auth_sspi/1.0.0
            [SERVER_NAME] => localhost
            [SERVER_ADDR] => 127.0.0.1
            [SERVER_PORT] => 80
            [REMOTE_ADDR] => 127.0.0.1
            [DOCUMENT_ROOT] => C:/phpWeb
            [SERVER_ADMIN] => marefin@muscletech.com
            [SCRIPT_FILENAME] => C:\\phpWeb\\logintest2.php
            [REMOTE_PORT] => 2211
            [REDIRECT_URL] => /logintest2.php
            [GATEWAY_INTERFACE] => CGI/1.1
            [SERVER_PROTOCOL] => HTTP/1.1
            [REQUEST_METHOD] => GET
            [QUERY_STRING] =>
            [REQUEST_URI] => /logintest2.php
            [SCRIPT_NAME] => /logintest2.php
            [PATH_TRANSLATED] => C:\\phpWeb\\logintest2.php
        )

    [_ENV] => Array
        (
            [REDIRECT_STATUS] => 200
            [HTTP_HOST] => localhost:8080
            [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040206 Firefox/0.8
            [HTTP_ACCEPT] => application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
            [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
            [HTTP_ACCEPT_ENCODING] => gzip,deflate
            [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
            [HTTP_KEEP_ALIVE] => 300
            [HTTP_CONNECTION] => keep-alive
            [HTTP_REFERER] => http://localhost:8080/
            [PATH] => C:\\program files\\lotus\\notes\\;C:\\program files\\lotus\\notes\\data\\;C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;C:\\IMNnq_NT;C:\\j2sdk1.4.1_01; C:\\j2sdk1.4.1_01\\bin; C:\\j2sdk1.4.1_01\\bin;C:\\SQLLIB\\BIN;C:\\SQLLIB\\FUNCTION;C:\\SQLLIB\\SAMPLES\\REPL;C:\\SQLLIB\\HELP;c:\\wcsdevenv\\bin;C:\\apache-ant-1.5.4\\bin;C:\\j2sdk1.4.1_01\\bin;C:\\Program Files\\lotus\\notes
            [SystemRoot] => C:\\WINNT
            [COMSPEC] => C:\\WINNT\\system32\\cmd.exe
            [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
            [WINDIR] => C:\\WINNT
            [SERVER_SIGNATURE] =>
Apache/2.0.45 (Win32) mod_auth_sspi/1.0.0 Server at localhost Port 80


            [SERVER_SOFTWARE] => Apache/2.0.45 (Win32) mod_auth_sspi/1.0.0
            [SERVER_NAME] => localhost
            [SERVER_ADDR] => 127.0.0.1
            [SERVER_PORT] => 80
            [REMOTE_ADDR] => 127.0.0.1
            [DOCUMENT_ROOT] => C:/phpWeb
            [SERVER_ADMIN] =>admin@test.com
            [SCRIPT_FILENAME] => C:\\phpWeb\\logintest2.php
            [REMOTE_PORT] => 2211
            [REDIRECT_URL] => /logintest2.php
            [GATEWAY_INTERFACE] => CGI/1.1
            [SERVER_PROTOCOL] => HTTP/1.1
            [REQUEST_METHOD] => GET
            [QUERY_STRING] =>
            [REQUEST_URI] => /logintest2.php
            [SCRIPT_NAME] => /logintest2.php
            [PATH_TRANSLATED] => C:\\phpWeb\\logintest2.php
        )

    [HTTP_POST_FILES] => Array
        (
        )

    [_FILES] => Array
        (
        )

    [_REQUEST] => Array
        (
        )

    [GLOBALS] => Array
 *RECURSION*
)
0
 
LVL 4

Accepted Solution

by:
BrianPap22 earned 55 total points
ID: 10944894
Well as you can see, the $_SERVER["AUTH_TYPE"] and other variables you were using do not exist as far as the server is concerned.  Seems like a configuration problem to me, possibly with NTLM.
0
 

Author Comment

by:malikatwork
ID: 10949512
These are the changes I made to my http.conf file.

==============
.................
LoadModule sspi_auth_module modules/mod_auth_sspi.so

#
# Configuration for mod_auth_sspi
<IfModule mod_auth_sspi.c>
    <Location /protected/>
        AuthName "A Protected Place"
        AuthType SSPI
        SSPIAuth On
        SSPIAuthoritative On
        SSPIOfferBasic On
        SSPIBasicPreferred On
        require valid-user
    </Location>
</IfModule>
................................................

<Directory "c:/phpweb">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
        # SSPI authentication
        AuthName "My secure area"
        AuthType SSPI
        SSPIAuth On
        SSPIAuthoritative On
        require valid-user
</Directory>
.......................................................................

I'm not sure what I did wrong.
0
 

Author Comment

by:malikatwork
ID: 11063364
The HTTP Authentication hooks in PHP are only available when it is running as an Apache module, as result it was not working for me.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now