Answers for "Enable CORS in cpanel"

0

Enable CORS in cpanel

# How to enable CORS in your hosting account
# If you are a developer and need CORS enabled to run your app you can enable it adding the following lines in the .htaccess file in your hosting account.

<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>


# Other option is also enable the headers in your script if you are using PHP, for example:

<?php
header("Access-Control-Allow-Headers: Authorization, Content-Type");
header("Access-Control-Allow-Origin: *");
header('content-type: application/json; charset=utf-8');
?>
Posted by: Guest on August-30-2020
0

Enable CORS in cpanel

# I have tried somany codes but this work for me in "funtion.php" of active theme

add_action('init', 'handle_preflight');
function handle_preflight() {
    $origin = get_http_origin();
    if ($origin === 'http://yourdomain.com') {
        header("Access-Control-Allow-Origin: http://yourdomain.com");
        header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
        header("Access-Control-Allow-Credentials: true");
        header('Access-Control-Allow-Headers: Origin, X-Requested-With, X-WP-Nonce, Content-Type, Accept, Authorization');
        if ('OPTIONS' == $_SERVER['REQUEST_METHOD']) {
            status_header(200);
            exit();
        }
    }
}
Posted by: Guest on July-08-2021

Browse Popular Code Answers by Language