PHP and NTLM in Apache

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?
malikatworkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BrianPap22Commented:
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
apparitionCommented:
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
BrianPap22Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
malikatworkAuthor Commented:
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
malikatworkAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.