Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CORSHandler.php 680B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. *
  8. */
  9. namespace Piwik\API;
  10. use Piwik\Url;
  11. class CORSHandler
  12. {
  13. /**
  14. * @var array
  15. */
  16. protected $domains;
  17. public function __construct()
  18. {
  19. $this->domains = Url::getCorsHostsFromConfig();
  20. }
  21. public function handle()
  22. {
  23. if (!empty($_SERVER['HTTP_ORIGIN'])) {
  24. $origin = $_SERVER['HTTP_ORIGIN'];
  25. if (in_array($origin, $this->domains, true)) {
  26. header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
  27. }
  28. }
  29. }
  30. }