{ // check user is authorized…
// expects Base64 encoded version of ‘jdoe:password’
$headers = apache_request_headers();
{ // checking that Authorization data has been supplied
if (empty($headers[‘Authorization’])) { // no credentials
$info->status = ‘failure’;
$info->error->code = 47;
$info->error->text = ‘Basic HTTP authentication required’;
$this->response($info, 401);
}
}
{ // checking to see if the Authorization string is valid
$this->load->database();
$sql = ‘SELECT COUNT(id) AS records FROM users ‘;
$sql .= ‘WHERE basic_http_auth = "’.$headers[‘Authorization’].’";’;
//$this->response($sql, 200);
$query = $this->db->query($sql);
$data = $query->row();
if ($data->records == “0”) {
$info->status = ‘failure’;
$info->error->code = 48;
$info->error->text = ‘Invalid credentials supplied’;
$this->response($info, 401);
}
My lecturer is using this to authorize users to post reviews or delete them
I need to build something similar but i have no idea how his one works.
Looking online this is done in so many different ways
what would i need to do to have this working for my user data base where the fields/colums are also
id(which is autoincremented),username,password,email.