-1

I have tried the solution provided in stack overflow for this problem but could not really solve this problem.

I am working on the code written by someone else. The code is as follows

$web_user = $_SERVER["PHP_AUTH_USER"];
$file_name = $web_user.'_nefops_var_sel.tab';
$state['dumper_file_name'] = $file_name;
$long_file_name = '/tmp/'.$file_name;
$state['dumper_long_file_name'] = $long_file_name;
$handle = fopen($long_file_name,'w') or die("bad file open");
fwrite($handle,$labels);    
fclose($handle);

The error I am getting is A PHP Error was encountered

Severity: Notice
Message: Undefined index: PHP_AUTH_USER
Filename: models/export_data_model.php
Line Number: 26

Can someone help me with this.

Naftali
  • 144,921
  • 39
  • 244
  • 303
Siri
  • 29
  • 1
  • 2
  • 2

5 Answers5

3

The error you are receiving is letting you know that there is no such key for PHP_AUTH_USER in the server superglobal. This means base HTTP auth, sometimes used in CGI or defined in a webserver config like apache, isn't available/enabled.

PHP_AUTH_USER not set?

Note that the error level is a warning, so it isn't going to stop execution unless you have your error level set to strict.

Since you say that you are working on someone else's code, I would say this means the code was originally intended to use native webserver authentication rather than an authentication model defined in the code using a database. You're going to need to find an alternative if you are deploying this somewhere else, like creating your own authentication mechanism using a persistency layer.

Docs for HTTP auth under Apache: http://httpd.apache.org/docs/2.0/howto/auth.html

Community
  • 1
  • 1
DeaconDesperado
  • 9,977
  • 9
  • 47
  • 77
2

The PHP documentation for $_SERVER states for ['PHP_AUTH_USER']:

When doing HTTP authentication this variable is set to the username provided by the user.

So what this tells me, is that there is no HTTP authentication taking place.

I suggest you read up on HTTP authentication with PHP.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • I am starting to use PHP recently so do not understand most of the stuff. So when you say that during HTTP authentication the variables were set. Where can I check what they were set to.I mean is that the config.php file or the php.ini file? – Siri Jun 26 '12 at 20:58
0

You're getting a notice because you aren't checking if $_SERVER["PHP_AUTH_USER"] is set before referencing it. It's only a notice though, so it's not that critical.

Jon Owens
  • 76
  • 1
  • 6
-1

It tells you exactly what the error id in the error message.

$_SERVER["PHP_AUTH_USER"] does not exist.

Naftali
  • 144,921
  • 39
  • 244
  • 303
-1

If you installed Apache2 , try this command:

sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf
Obsidian
  • 3,719
  • 8
  • 17
  • 30
  • Can you explain what your solution is doing and why it resolves the issue? – d.j.yotta Jun 02 '22 at 20:51
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 03 '22 at 01:20