Hướng dẫn undefined index: php_auth_user

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

143k39 gold badges240 silver badges299 bronze badges

asked Jun 26, 2012 at 15:02

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

answered Jun 26, 2012 at 15:05

DeaconDesperadoDeaconDesperado

9,5798 gold badges44 silver badges77 bronze badges

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.

answered Jun 26, 2012 at 15:05

Hướng dẫn undefined index: php_auth_user

Jonathon ReinhartJonathon Reinhart

127k32 gold badges245 silver badges317 bronze badges

1

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.

answered Jun 26, 2012 at 15:07

Jon OwensJon Owens

761 silver badge6 bronze badges

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

$_SERVER["PHP_AUTH_USER"] does not exist.

answered Jun 26, 2012 at 15:04

NaftaliNaftali

143k39 gold badges240 silver badges299 bronze badges

1

If you installed Apache2 , try this command:

sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf

Hướng dẫn undefined index: php_auth_user

Obsidian

3,2708 gold badges16 silver badges29 bronze badges

answered Jun 2 at 12:26

Hướng dẫn undefined index: php_auth_user

2