?
Solved

PHP and NTLM in Apache

Posted on 2004-04-28
5
Medium Priority
?
1,245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 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