久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php如何實(shí)現(xiàn)跨域請(qǐng)求

      php實(shí)現(xiàn)跨域請(qǐng)求的方法:可以通過(guò)設(shè)置【header('Access-Control-Allow-Origin:*');】來(lái)實(shí)現(xiàn)允許所有域名訪問(wèn)。

      php如何實(shí)現(xiàn)跨域請(qǐng)求

      本文操作環(huán)境:windows10系統(tǒng)、php 7、thinkpad t480電腦。

      在PHP中如果我們需要實(shí)現(xiàn)跨域,可以通過(guò)設(shè)置Access-Control-Allow-Origin來(lái)實(shí)現(xiàn)。接下來(lái)我們舉個(gè)例子,方便大家更好地理解。

      假設(shè)現(xiàn)在的客戶(hù)端域名是client.runoob.com,而請(qǐng)求的域名是server.runoob.com。

      如果我們直接使用ajax訪問(wèn),就會(huì)出現(xiàn)以下錯(cuò)誤:

      XMLHttpRequest cannot load http://server.runoob.com/server.php. No 'Access-Control-Allow-Origin' header is present on the requested resource.Origin 'http://client.runoob.com' is therefore not allowed access.

      一、允許單個(gè)域名訪問(wèn)

      指定某域名(http://client.runoob.com)跨域訪問(wèn),則只需在http://server.runoob.com/server.php文件頭部添加如下代碼:

      header('Access-Control-Allow-Origin:http://client.runoob.com');

      二、允許多個(gè)域名訪問(wèn)

      指定多個(gè)域名(http://client1.runoob.com、http://client2.runoob.com等)跨域訪問(wèn),則只需在http://server.runoob.com/server.php文件頭部添加如下代碼:

      $origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';     $allow_origin = array(       'http://client1.runoob.com',       'http://client2.runoob.com'  );     if(in_array($origin, $allow_origin)){       header('Access-Control-Allow-Origin:'.$origin);       }

      三、允許所有域名訪問(wèn)

      允許所有域名訪問(wèn)則只需在http://server.runoob.com/server.php文件頭部添加如下代碼:

      header('Access-Control-Allow-Origin:*');

      推薦學(xué)習(xí):php培訓(xùn)

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)