Solved

Cannot see REMOTE_USER variable in Apache/2.2.3 (CentOS) using PHP 5.1.6.

Posted on 2008-10-23
9
3,336 Views
Last Modified: 2012-05-05
Hi,

I'm usually an IIS, .NET windows type developer, but at the moment I'm trying to do some PHP.

I'm trying to get the REMOTE_USER server variable so that I can see who is logged on to the company Intranet and I'm using Apache/2.2.3 (CentOS) , PHP 5.1.6.

I've used the CheckPHP function to get all the config settings and I can see many of the server variables but not REMOTE_USER.

Can anyone help? Please bear in mind that I'm very new to linux, apache and PHP, and only really found a few console commands.

Many Thanks

Chris
0
Comment
Question by:chrispont
9 Comments
 
LVL 6

Expert Comment

by:hampus_b
ID: 22785208
The way to access remote_user is like this:

<?
echo $_SERVER['REMOTE_USER'];
?>


Try also to create a php-file with the following content:

<?

phpinfo();

?>

save it as info.php and point your browser to it.

Search for "Apache Environment" in the result. Does REMOTE_USER show up?
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22785212
Good morning,

Here is the list of Server Variables:
http://us2.php.net/manual/en/reserved.variables.server.php

For your environment, write a quick php script and put just this in it:

<?php
phpinfo();
?>

Run that and it'll show you all the variables available to you on your server.

I think the ones you are looking for are either

$_SERVER['REMOTE_USER']
$_SERVER['REMOTE_ADDR']  (for the ip)
or
$_SERVER['PHP_AUTH_USER']

Hope that all helps.
0
 

Author Comment

by:chrispont
ID: 22785297
Sorry guys, I've tried phpinfo(); and cannot see the REMOTE_USER there (athough I can see REMOTE_ADDR and this shows the IP address of the client, not the authenticated user name).

I've tried $_SERVER['REMOTE_USER'] in some scripts and this is always empty.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22785366
If you force the login using php's extension to HTTP_AUTH, you can output the username using $_SERVER['PHP_AUTH_USER']

for example, try this script:

<?php
if (!isset($_SERVER['PHP_AUTH_USER']))
{
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
}
else
{
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}


0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 10

Expert Comment

by:MadShiva
ID: 22785519
Hi !

You need to create a .htaccess and .htpasswd file.

The variable $_SERVER['PHP_AUTH_USER'] is used when you have put in place an authentication method.

Follow this tutorial and you would be able to get the user.

http://www.freewebmasterhelp.com/tutorials/htaccess/3


Best Regards
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22785819
Well, that'll get you the same thing as what I have proposed, just with more files. If you are already using php for your page, you can do the HTTP_AUTH via php and then use $_SERVER['PHP_AUTH_USER'] to get the username.
0
 
LVL 10

Expert Comment

by:MadShiva
ID: 22786064
Yes I don't have say that is different. Just trying to explain more how it's working. I don't care about get more points, just help people.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22786916
Right. Same here. :)

My point was just that he is used to IIS and not apache, so he may not want to deal with extra files (.htaccess, .htpasswd) in setting this up.
0
 
LVL 3

Accepted Solution

by:
DarkFish earned 500 total points
ID: 22806648
NTLM authentication, by default, is not available under a Linux, Apache & PHP together.

You need to install and configure mod_ntlm for Linux & Apache, which is available at:

http://modntlm.sourceforge.net/

mod_ntlm essentially works by retrieving the remote user's details from the workstation and forwarding them to the PHP script using headers.

In addition mod_ntlm can limit who can access your Intranet, and if they are not logging onto correctly you can essentially force them to authenticate using their domain details (this might require more code though, as you would need to authenticate against Active Directory.)

If you don't mind me saying, if you're running a Microsoft based network and wanting to use PHP, you might be better off using PHP on a Windows server as you have, by default, more domain based options and controls over who can view your website.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Passing variables to stored procedure 3 35
Form not operating correctly. 1 22
phpmailer in WHILE loop - weird results 10 27
How to convert my query to the proper format? 5 16
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

914 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

18 Experts available now in Live!

Get 1:1 Help Now