blocked by CORS policy. I have axios network error

I faced the issue I can’t solve right now. I have an error axios, the code is not so long, but I have no idea where exactly to look. So I just wondered maybe someone could help me out ? The problem is somewhere in the client code, because I tried to test it with POSTMAN then I get status OK 200, but when I try to log in from UI then I get axios error.

const url = BACKEND_URL;
     console.log(`${url}/api_app`);
     const logo = require("../../images/logo-pinigine.png");

     const credentials = `${validUsername}:${validPassword}`;
     const encodedCredentials = encode(credentials);
     const instance = axios.create({
      baseURL: `${url}/api_app`,
      headers: {
      Authorization: `Basic ${encodedCredentials}`,
      Accept: "application/json",
     },
    });

    const handleLogin = async () => {
    if (isInputValid()) {
      if (isHuman) {
         try {
          var returnValue = 0;
          const res = await instance.post(`/app_actions.php`, {
            action: "find_user_by_email",
            email: email,
            password: password,
          });
          const data = res.data;

          if (data.success == 1) {
            returnValue = data.success;

            setRajonu_arr(data.data);
          } else {
            returnValue = data.success;
            toaster.show({
              message: data.msg,
              type: "error",
              position: "middle",
              duration: 2000,
            });
          }
        } catch (error) {
          console.log(error);
        }
        if (returnValue !== 0) {

          changeRajonaiModalVisible(true);
    }
  } else {
    toaster.show({
      message: "Pirma pažymėkite, kad nesate robotas.",
      type: "error",
      position: "middle",
      duration: 2000,
    });
  }
 }
};

<?php

header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE, PUT');
header('Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');

require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/System.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/functions.php');
$json = file_get_contents('php://input');
$data = json_decode(file_get_contents("php://input"));
//require_once($_SERVER['DOCUMENT_ROOT'] . '/ajax/helpers.php');
error_reporting(E_ALL);
// Set the username and password for authentication
global $mysqli;
//is bendrines weekly nustatymas kad ateitu
$validUsername = nustatymai_par_reiksme($mysqli, 'validApiUsername');
$validPassword = nustatymai_par_reiksme($mysqli, 'validApiPassword');
//print_r(" validUsername  ".$validUsername."  validPassword   ".$validPassword);

//$validUsername = 'username';
//$validAPIUsername = 'password';
// Check if the Authorization header is set
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: Basic realm="API Authentication"');
    exit;
}

// Verify the provided credentials
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];

//$username = $_GET['PHP_AUTH_USER'];
//$password = $_GET['PHP_AUTH_PW'];
if ($username !== $validUsername || $password !== $validPassword && isset($data->system_id)) {
    header('HTTP/1.1 401 Unauthorized');
    exit;
}

// Authentication successful, handle API requests
if (isset($_POST['action'])) {
    $action = $_POST['action'];

    // Call the appropriate function based on the action
    switch ($action) {
        case 'find_user_by_email':
            // Call function1
            find_user_by_email();
            break;
        default:
            // Invalid action, return an error response
            $response = ['error' => 'Invalid action'];
            echo json_encode($response);
            break;
    }
} else {
    // No action specified, return an error response
    $response = ['error' => 'No action specified'];
    echo json_encode($response);
}

function find_user_by_email()
{
    global $mssql, $mysqli;
    $return = [];
    $email = $_POST['email'];

    $System = new System();

    if (isset($email)) {
        $systems_rajonai = $System->getSystemRajonaiList($email);
        if (count($systems_rajonai) > 0) {
            $return['msg'] = 'rajonai gauti';
            $return['data'] = $systems_rajonai;
            $return['success'] = 1;
        } else {
            $return['msg'] = 'Tokio vartotojo E-Maitinimas sistemoje nėra';
            $return['success'] = 0;
        }
    } else {
        $return['msg'] = 'neivestas email';
        $return['success'] = 0;
    }
    echo json_encode($return);
}
?>

And I have this PHP file
I don’t know about php, this file was built for me

I expect to have status ok 200 from client side

I checked the other topics but wasn’t helpful, because there was the main problem that he should enable CORS in server side which I am already enabled also I am using credentials which is encoded and none of them was used. And I am using PHP differently than others, maybe there can be the issue aswell. And also I am using Authorization: Basic Auth, maybe I missed something there in client side.

New contributor

Ugnius Uscilas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật