Category Archives: Apache

How to enable cross-origin resource sharing using php

I was working on parsing KML data file from different resources which had different urls and Cesiumjs was unable to read/parse, that is how i come to know enabling cross-origin resource sharing.
It is also called CORS. Here is more details .

Following these steps you can enable “CORS”.
1. First check if you have apache module installed, using php.

  

2. Use command line to check if you have “Access-Control-Allow-Origin: *”

Command is - curl -I http://yourwebsite.com

3. If you don’t see this line “Access-Control-Allow-Origin: *” in curl -I output you need to add and enable it in either in PHP file ot .htacces file.

HTTP/1.1 302 Found
Date: Sat, 19 Sep 2015 00:31:41 GMT
Server: Apache
Access-Control-Allow-Origin: *
Set-Cookie: PHPSESSID=k1ejs4ra2gsu2id387h472one2; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: https://phpmind.com/index.php
Content-Type: text/html; charset=UTF-8
Set-Cookie: BIGipServer~DART-Dev~DART=1241032896.20480.0000; path=/

4. Now its time to add code and enable your missing part!

In .htaccess

 

    Header set Access-Control-Allow-Origin "*"

In PHP file

header("Access-Control-Allow-Origin: *"); // for all

header('Access-Control-Allow-Origin: http://www.rnai.technology'); // For particular URL
header('Access-Control-Allow-Origin: http://phpmind.com');
header('Access-Control-Allow-Origin: http://maps.google.com');

After that you need to test using

Command is - curl -I http://yourwebsite.com

You must see Access-Control-Allow-Origin: *” with headers.

Share

How to check which apache modules are installed using php?

If you don’t have command line access use this code to see which apache modules are installed.

  

This will show a list like that.
By the way this not my server 🙂

Array
(
[0] => core
[1] => prefork
[2] => http_core
[3] => mod_so
[4] => mod_auth_basic
[5] => mod_auth_digest
[6] => mod_authn_file
[7] => mod_authn_alias
[8] => mod_authn_anon
[9] => mod_authn_dbm
[10] => mod_authn_default
[11] => mod_authz_host
[12] => mod_authz_user
[13] => mod_authz_owner
[14] => mod_authz_groupfile
[15] => mod_authz_dbm
[16] => mod_authz_default
[17] => util_ldap
[18] => mod_authnz_ldap
[19] => mod_include
[20] => mod_log_config
[21] => mod_logio
[22] => mod_env
[23] => mod_ext_filter
[24] => mod_mime_magic
[25] => mod_expires
[26] => mod_deflate
[27] => mod_headers
[28] => mod_usertrack
[29] => mod_setenvif
[30] => mod_mime
[31] => mod_dav
[32] => mod_status
[33] => mod_autoindex
[34] => mod_info
[35] => mod_dav_fs
[36] => mod_vhost_alias
[37] => mod_negotiation
[38] => mod_dir
[39] => mod_actions
[40] => mod_speling
[41] => mod_userdir
[42] => mod_alias
[43] => mod_substitute
[44] => mod_rewrite
[45] => mod_proxy
[46] => mod_proxy_balancer
[47] => mod_proxy_ftp
[48] => mod_proxy_http
[49] => mod_proxy_ajp
[50] => mod_proxy_connect
[51] => mod_cache
[52] => mod_suexec
[53] => mod_disk_cache

Share