473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

header()

hi,

why don't work this script?

<?php

if(!isset($PHP_AUTH_USER)) {
header ('WWW-authenticate: basic realm="Area Privata"');
header ("Status: 401 Unauthorized");
echo "Non sei autorizzato";
exit;
}
else {
echo "La Tua Password: ".$PHP_AUTH_PW."<br />";
echo "Il Tuo Username: ".$PHP_AUTH_USER."<br />";
}
?>

....if i put username and password the script
always open the authenticate window!

is the problem in my php.ini or/and htppd.conf ?

thank you,
Simone
Jul 17 '05 #1
12 5080
Simone wrote:
hi,

why don't work this script?

<?php
error_reporting(E_ALL);
if(!isset($PHP_AUTH_USER)) {

[...]

try that :)

then read about how PHP deals with variables from outside

http://www.php.net/manual/en/languag...s.external.php

paying particular attention to the "register_globals" references.
Happy Coding :-)

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #2
> error_reporting(E_ALL);

in my php.inin this directive is just on E_ALL...
paying particular attention to the "register_globals" references.


and this is often sett on off...

infact in my script if(!isset($PHP_AUTH_USER)) is written
if(!isset($_REQUEST['PHP_AUTH_USER'])) {...

the problem is not here, because my script don't generate error!
Simone
Jul 17 '05 #3
Simone <si*****************@libero.it> wrote:
error_reporting(E_ALL);


in my php.inin this directive is just on E_ALL...
paying particular attention to the "register_globals" references.


and this is often sett on off...

infact in my script if(!isset($PHP_AUTH_USER)) is written
if(!isset($_REQUEST['PHP_AUTH_USER'])) {...

the problem is not here, because my script don't generate error!


Why didn't you post the correct code in the first place?
And the problem *is* in fact there - check the manual:

http://uk.php.net/manual/en/features.http-auth.php

Not all mistakes generate an error.

JOn
Jul 17 '05 #4
> hi,

why don't work this script?

is the problem in my php.ini or/and htppd.conf ?

If you have set in httpd.conf or .htaccess that the apache is supposed to
ask for passwrod for that directory, then $_SERVER['PHP_AUTH_USER'] will be
empty, but $_SERVER['REMOTE_USER'] will contain info you are looking for.

rush
--
http://www.templatetamer.com/

Jul 17 '05 #5
this is my code:

<?php

if (!isset($_SERVER['PHP_AUTH_USER'])) {
header ('WWW-authenticate: basic realm="Area Privata"');
header ("Status: 401 Unauthorized");
echo "Non sei autorizzato";
exit;
}
else {
echo "Your Password: ".$_SERVER['PHP_AUTH_USER'] ."<br />";
}
?>

why doesn't show "Your Password..."?
where's my programming error?
Simone
Jul 17 '05 #6
this is my code:

<?php

if (!isset($_SERVER['PHP_AUTH_USER'])) {
header ('WWW-authenticate: basic realm="Area Privata"');
header ("Status: 401 Unauthorized");
echo "Non sei autorizzato";
exit;
}
else {
echo "Your Password: ".$_SERVER['PHP_AUTH_USER'] ."<br />";
}
?>

why doesn't show me "Your Password..."?
where's my programming error?
also if i use $_SERVEF['REMOTE_USER'] it's the same!
Simone
Jul 17 '05 #7
Simone wrote:
this is my code: <snip contents="php code"/> why doesn't show me "Your Password..."?
where's my programming error?
also if i use $_SERVEF['REMOTE_USER'] it's the same!


I created an .htaccess file in a new directory
I created an .htpasswd file in that directory using htpasswd
I changed httpd.conf to include
AllowOverride AuthConfig
for this specific directory
I copied your code to a file here
tested it and it worked ok!

Probably this isn't a PHP issue ... I think it's a web server
configuration thing

PS: the .htaccess file I created

AuthType Basic
AuthName "By Invitation Only"
AuthUserFile /var/www/normal/secure/.htpasswd
Require valid-user

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #8
"Simone" <si*****************@libero.it> schrieb:
this is my code:

<?php

if (!isset($_SERVER['PHP_AUTH_USER'])) {
header ('WWW-authenticate: basic realm="Area Privata"');
header ("Status: 401 Unauthorized");
echo "Non sei autorizzato";
exit;
}
else {
echo "Your Password: ".$_SERVER['PHP_AUTH_USER'] ."<br />";
}
?>

why doesn't show "Your Password..."?
where's my programming error?


Maybe nowhere. Is PHP running as a module or as a CGI program?

Regards,
Matthias
Jul 17 '05 #9
CGI program,
(but don't work on IIS 5 too!)

why?

(i'm beginnig ti study Professional Apache 2.0 - Peter Wainwright - Wrox,
is it good?)

Simone

Jul 17 '05 #10
[Quoting added]

"Simone" <si*****************@libero.it> wrote:
Is PHP running as a module or as a CGI program?


CGI program,
(but don't work on IIS 5 too!)

why?


Have a look at the first sentence in the PHP documentation at
http://www.php.net/features.http-auth:

| "The HTTP Authentication hooks in PHP are only available when it is
| running as an Apache module and is hence not available in the CGI
| version."

I think you'll have to use an other kind of authentication.

Regards,
Matthias
Jul 17 '05 #11
Simone <si*****************@libero.it> wrote:
CGI program,
(but don't work on IIS 5 too!)


From the manual:

<quote>
Also note that until PHP 4.3.3, HTTP Authentication did not work using
Microsoft's IIS server with the CGI version of PHP due to a limitation of
IIS. In order to get it to work in PHP 4.3.3+, you must edit your IIS
configuration "Directory Security". Click on "Edit" and only check
"Anonymous Access", all other fields should be left unchecked.

Another limitation is if you're using the IIS module (ISAPI), you may not
use the PHP_AUTH_* variables but instead, the variable HTTP_AUTHORIZATION
is available. For example, consider the following code: list($user, $pw) =
explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

IIS Note:: For HTTP Authentication to work with IIS, the PHP directive
cgi.rfc2616_headers must be set to 0 (the default value).
</quote>

JOn
Jul 17 '05 #12
thank you
Jul 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John | last post by:
Hi. I am having a few header problems at the moment with a login page. I don't have my headers at the top of the page where I've learned I need to have them. However, I also know I'm supposed...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
18
by: John Smith | last post by:
Hi all What does the group think of the practise of including one header file from inside another? I have some legacy code where this has been done, and it creates a dependency on a module...
6
by: Jason Collins | last post by:
There seems to be an inconsistency (bug?) in the way the Set-Cookie header is handled by the WebHeaderCollection. That is, the values of Set-Cookie, when an Expires is specified, contain the ","...
0
by: Dean Hallman | last post by:
Hello, I am developing a BHO that should add a custom HTTP header on a specific domain only. Don't want the header globally, otherwise I could just add a registry key. So, on...
4
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code...
1
by: Shalako | last post by:
I check my error log and see these entries: malformed header from script. Bad header= Missing gauge reports are ind: padata.pl /perl/pema/padata.pl did not send an HTTP header malformed...
5
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I have a sub in vb.net that adds extra headers to a gridview and it works very well. however, i tried to translate it to c# and i'm getting the header inserting itself over the first datarows and...
30
by: xiao | last post by:
HI~ EVERY ONE~ I have a small program here, when I tried to compile it , it always reminds that arrary.c: In function `main': arrary.c:39: error: `header' undeclared (first use in this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.