Hello friends, I am trying to create a basic authentication in a Codeigniter 4 rest api , but the following answers:
Undefined index: PHP_AUTH_USER
This is my code:
<?php
namespace App\Controllers;
use CodeIgniter\RESTful\ResourceController;
class WebServiceCitasController extends ResourceController
{
protected $modelName = 'App\Models\WebservicecitasModel';
protected $format = 'json';
public function index()
{
$usuario_ws=$_SERVER['PHP_AUTH_USER'];
$password_ws=$_SERVER['PHP_AUTH_PW'];
if($usuario_ws=='admin'&& $password_ws=="123456789"){
return $this->genericResponse($this->model->listarCitas(),"",200);
}else{
return $this->genericResponse("Error, no te haz autenticado","",200);
}
}
}
I solved it by applying the ternary poerador so that it assigns it to me empty and so the ws responds to me.