CodeIgniter Forums
Weird behavior of htauth and $this->input->server('PHP_AUTH_USER', True); - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Weird behavior of htauth and $this->input->server('PHP_AUTH_USER', True); (/showthread.php?tid=48821)



Weird behavior of htauth and $this->input->server('PHP_AUTH_USER', True); - El Forum - 01-30-2012

[eluser]Unknown[/eluser]
Hi All
Thank you for great software and a great community!

I am working on a small htauth-controller.
The below simple code is placed in one of my controllers.

The following code works...:
Code:
public function authenticate()
{
  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 $this->input->server('PHP_AUTH_USER', True)."\n";
   echo $this->input->server('PHP_AUTH_PW', True)."\n";

  }
}

...And correctly returns:
mortenlp
testP4sw0rd

However the following code:
Code:
public function authenticate()
{
  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 $this->input->server('PHP_AUTH_USER', True)."\n";
   echo $this->input->server('PHP_AUTH_PW', True)."\n";

  }
}
Returns:
"Text to send if user hits Cancel button"

The requests are exactly identical.

Do you know what this might be caused by?
Best wishes
Morten Pedersen
Denmark