感觉每次都会用到索性就记录下。
字符集的:
header("Content-type: text/html; charset=utf-8");
设置跨域的:
1、允许单个域名访问
指定某域名(http://client.runoob.com)跨域访问,则只需在http://server.runoob.com/server.php文件头部添加如下代码:
header('Access-Control-Allow-Origin:http://www.sanshu.cn');
2、允许多个域名访问
指定多个域名(http://www.sanshu.cn、http://aaa.sanshu.cn等)跨域访问,则只需在文件头部添加如下代码:
$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : ''; $allow_origin = array( 'http://www.sanshu.cn', 'http://aaa.sanshu.cn' ); if(in_array($origin, $allow_origin)){ header('Access-Control-Allow-Origin:'.$origin); }
3、允许所有域名访问
允许所有域名访问则只需在php文件头部添加如下代码:
header('Access-Control-Allow-Origin:*');