To enable CORS in Joomla!, you need to add the standard CORS header(s). There are a few ways to add the header(s), which are covered in the following sections.
Since Joomla! version 11.4, the core method to set headers is setHeader
in the base class JapplicationWeb
, which can be used to set the Access-Control-Allow-Origin
header and can be used to set other headers.
The following example allows access from all domains with the wildcard:
setHeader('Access-Control-Allow-Origin', '*', true) : \JApplicationWeb
You may find discussions regarding the use of JResponse::setHeader
for CORS in Joomla!; however, it has been deprecated since Joomla! Version 11.4. Use setHeader
in the base class JApplicationWeb
instead.