php access origin

 <?php
 header("Access-Control-Allow-Origin: *");

3.67
3
Krish 100200 points

                                    /**
 *  An example CORS-compliant method.  It will allow any GET, POST, or OPTIONS requests from any
 *  origin.
 *
 *  In a production environment, you probably want to be more restrictive, but this gives you
 *  the general idea of what is involved.  For the nitty-gritty low-down, read:
 *
 *  - https://developer.mozilla.org/en/HTTP_access_control
 *  - http://www.w3.org/TR/cors/
 *
 */
function cors() {

    // Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        // Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
        // you want to allow, and if so:
        header(&quot;Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}&quot;);
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }

    // Access-Control headers are received during OPTIONS requests
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            // may also be using PUT, PATCH, HEAD etc
            header(&quot;Access-Control-Allow-Methods: GET, POST, OPTIONS&quot;);         

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header(&quot;Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}&quot;);

        exit(0);
    }

    echo &quot;You have CORS!&quot;;
}

3.67 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
php Access-Control-Allow-Origin: * Allow-Origin php how to allow cross origin in php code allow cors origin php php add access-control-allow-origin header php add access-control-allow-origin cors access-control-allow-headers php access control allow origin php set access-control-origin php cross origin request php php allow cors header enable Access-Control-Allow-Origin php php header allow acess allow origin access-control-allow-origin https php allow cross origin in php header cors allow origin error php access-control-allow-origin in php header php cors origin php header code allow origin access controll allow origin php php allow crossorigin cross origin request header with php php get origin header php origin header php syntax origin how to allow cors through header in php php access-control-allow-origin header php cross origin handling header for cross origin in php allow origin with php access-control-allow-origin * php header access-control-allow-origin * php heade enable cross origin php header examples php allow cross origin origin php php server origin php access-control-allow-origin cors add cross origin header php php cross origin request allow allow origin in php cross origin allow all in php php allow control origin cors origin php php header access control allow origin set header allow origin php cors allow origin php how to allow cross origin requests in php php Access-Control-Allow-Origin to any allow cross origin only from app php php header cors allow all CORS access-control-allow-origin PHP cross origin in php allow access control origin header php php cross origin all how to enable Cross origin requests php allow all origin cors php access origin php php http_origin access control allow origin header in php access control allow origin localhost php php Access-Control-Allow-Origin localhost PHP origin allow all origins cors php allow cross origin requests php php file allow cross origin php header cors allow allow cors php header allow access origin php allow cors access-control-allow-origin php php allow cross origin requests php allow access-control-allow-origin php allow cross origin request header php access-control-allow-origin php cors allow origin php get origin Access-Control-Allow-Origin php header allow access-control-allow-origin php cross origin on php site add allow cross origin cors.php get origin php cors php allow allow cors header php allow cors from remote server php set cross origin header php get request origin php config cors.php access controll allow origin cross origin php get origin function php php cross origin php get request origin HTTP_ORIGIN php php allow_url_fopen php set access-control-allow-origin php allow access control origin header allow acess origin in php add php cors header how to allow cors php php header(&quot;Access-Control- php header access-control-allow-origin * php allow origin header add access control allow origin header php access to xmlhttprequest at from origin in php cors config php php access origin header access-control-allow-headers php accept cors header php php cors headrs iframe allow cross origin php php cross domain allow how to change access control allow origin same in php php access control allow content type cors header iframe allow cross origin header php enable cors how to set access control allow origin allow cors Access-Control-Allow-Origin php setting how to add cors where to set Access-Control-Allow-Origin: php redirect access-control-allow-origin add Access-control-allow-origin javascript link header(&quot;Access-Control-Allow-Origin: *&quot;) php in which file do add cors allow access orgin all header for php allow access orgin header for php php cross origin website cors snippet allow-control-allow-origin html cors enable in php php and cors how to set access-control-allow-origin cros enable cross site allow origin header php header set access-control-allow-origin php cors script php controller cors origin php cross origin header cors javascript where to add access-control-allow-origin php add header access-control-allow-origin allow origin header cors cors server to server access-control-allow-origin * php enable cors with php allow headers cors php strict-origin-when-cross-origin php enabling ors on php server php set header access-control-allow-origin php add cors header how to set php no cors php disable cross domain request Access-Control-Allow-Origin: * php access-control-allow-origin php header ajax access-control-allow-origin php header php cors allow all raw php enable cors header allow cross origin php * no-cors.php php script for CORS use php to get around CORS php to get around cors policy CORS in php file strict-origin-when-cross-origin in php php allow cors to other sites php set cors enable cors in php file allow cross broswer header php no cors php headers php add header cross origin php access allow origin header allo cors origin php CORS Issue php php include access has been blocked by cors policy php Access-Control-Allow-Origin&rsquo; not allowed php access control allow origin php strict-origin-when-cross-origin php allow Same Origin header(&quot;Access-Control-Allow-Origin: *&quot; meaning in php login allow cors from the backend php how to remove cors error in php aloow acees php php allow cross origin php set up headers access-ccontrol access-control-allow-origin' header php php stop cors cors error php php post origin hpw to add alloe cross origin header in php access origin allow code php file php enable cross origin allow cross origin php all header resolve cors issue in php php cros origin php set access control allow origin example access control origin php php cors header access control allow origin php header allow access cross origin php how to solve cors error in php php header cors php header cros php enable cors php header cross origin php access-control-allow-origin php allow cors from domain set cors header php allow cross site php header acep al origin php php headers allow origin how to set cors headers in php adding cors in php Cross-Origin Request in php php code allow cors access php allow Access-Control-Allow-Headers php allow all origins php header allow cors allow cross origin in php php block cross origin request Acces-Control-Allow-Origin php php create rest api cors php allow origin Access-Control-Allow-Origin on php &lt;? php header (''Assecs-control) php cross origin allow all cross origin header php access control origin header php php allow cros cors for php add php CORS headers to api server access control allow origin header php php cross domain policy allow cross origin php php allow cors origin header php allow origin add access control headers php php allow cors request php cors 'access-control-allow-origin' set header access-control-allow-origin php header cross origin using php Allow post methosd for cross origin PHP php cors to a domain access allow origin header php no 'access-control-allow-origin' header php php header access-control-allow-origin cors issue when calling php script php send cors header solve cors problem in php cors header php cors policy error in php php crossorigin header cors php php cors header add enable CORS for php php set cross origin header php allow cross origin domain CORS on PHP php enable cors headers header allow origin php access-control-allow-origin php list urls add cors to my php file crossorigin in a php server php access origin enable all cors php php cors nlocl allow origin header allow cross origin php php cors policy how to disable cors in php php no 'access-control-allow-origin' header how to add access-control-allow-origin header in php cors allow origin php header header access control php php cors php allow cors solve cors php php cors allow allow access control origin php cors php allow cors php server enable cors from php php access-control-allow-origin php cross policy enable cors php allow cors php all allow cors in php php 'Access-Control-Allow-Origin fix cors php server php cors headers enable cors in php php access-control-allow-headers allow origin cors php turn off cors check php turn off cors php additiing cors header in php header access-control-allow-origin php header cross origin php create function to download file php with cors allow cors php Access-Control-Allow-Origin php Access-Control-allow-origin in php active CORS in php php cors enable access-control-allow-origin header php php header allow cross origin
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source