# Php auth & fast\_cgi

**URL:** <https://www.ruby-forum.com/t/php-auth-fast-cgi/204493>\
**Category:** NGINX\
**Created:** [March 14, 2011, 11:59am UTC](https://www.ruby-forum.com/t/php-auth-fast-cgi/204493 "2011-03-14T11:59:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 14, 2011, 11:59am UTC](https://www.ruby-forum.com/t/php-auth-fast-cgi/204493/1 "2011-03-14T11:59:58Z")

</div>

A colleague of mine told me that these two lines in php doesn’t seem to  
work on an nginx + fastcgi installation. Any thoughts?

header(‘WWW-Authenticate: Basic realm=“SocialWhale Controller”’);

$\_SERVER[‘PHP\_AUTH\_USER’]  
$\_SERVER[‘PHP\_AUTH\_PW’];

## –

Alex

---

<div class="post-metadata">

**Author:** ![Alexander\_Economou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Alexander\_Economou](https://www.ruby-forum.com/u/Alexander_Economou)\
**Post date:** [March 14, 2011, 12:40pm UTC](https://www.ruby-forum.com/t/php-auth-fast-cgi/204493/2 "2011-03-14T12:40:48Z")

</div>

On Mon, Mar 14, 2011 at 12:58:35PM +0200, Alexander Economou wrote:

Hi there,

> A colleague of mine told me that these two lines in php doesn’t seem to  
> work on an nginx + fastcgi installation. Any thoughts?

They seem to work fine for me. Any expansion?

What does your colleague do, what does your colleague see, and what  
does your colleague expect to see? And, if it’s not obvious, what’s the  
difference between the last two?

> header(‘WWW-Authenticate: Basic realm=“SocialWhale Controller”’);
> 
> $\_SERVER[‘PHP\_AUTH\_USER’]  
> $\_SERVER[‘PHP\_AUTH\_PW’];

# authcheck:
\<?php if ($\_SERVER['PHP\_AUTH\_USER'] == "x" && $\_SERVER['PHP\_AUTH\_PW'] == "x") { echo "Well done, right credentials\n"; } else { header('WWW-Authenticate: Basic realm="SocialWhale Controller"'); } ?\>

===

I expect “curl -i [http://localhost/authcheck](http://localhost/authcheck)” to show me a HTTP 401,  
and “curl -i -u x:a [http://localhost/authcheck](http://localhost/authcheck)” to show me a HTTP 401,  
and “curl -i -u x:x [http://localhost/authcheck](http://localhost/authcheck)” to show me a HTTP 200.

And that’s what I see.

nginx.conf ensures that the php fastcgi server processes the request,  
of course.

All the best,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Alexander\_Economou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Alexander\_Economou](https://www.ruby-forum.com/u/Alexander_Economou)\
**Post date:** [March 14, 2011, 2:20pm UTC](https://www.ruby-forum.com/t/php-auth-fast-cgi/204493/3 "2011-03-14T14:20:35Z")

</div>

The problem seemed to be that after the initial auth , the credentials  
could not change (diff user/pass).

Thanx alot Francis for the fast reply and sorry for the crappy problem  
description but that was the only input i had. My colleague (the web  
dev) , seems to have found a solution to his problem.

Cheers

- 

Alex

On 03/14/2011 01:39 PM, Francis D. wrote:

> does your colleague expect to see? And, if it’s not obvious, what’s the
> 
> and “curl -i -u x:a [http://localhost/authcheck](http://localhost/authcheck)” to show me a HTTP 401,  
> and “curl -i -u x:x [http://localhost/authcheck](http://localhost/authcheck)” to show me a HTTP 200.
> 
> And that’s what I see.
> 
> nginx.conf ensures that the php fastcgi server processes the request,  
> of course.
> 
> All the best,
> 
> f

## –

Alexander Loukas Economou  
Systems & Network  
Administrator  
gsm : 6986 298 859  
email : [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
