X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fclass.api.php;h=77c1e986c826a8555bfe5e71a10d2b9f2b8fb1e7;hb=cd2d8d98cc4f9a9c8bb643dcc49b60a74c89f70b;hp=df6ef1283f4c0c4149987fcc73cec06f868743b3;hpb=dd77917bd932abedf8a8fbcb60ba75b8e199face;p=civicrm-core.git diff --git a/api/class.api.php b/api/class.api.php index df6ef1283f..77c1e986c8 100644 --- a/api/class.api.php +++ b/api/class.api.php @@ -75,6 +75,17 @@ * // is the json encoded result * echo $api; * ``` + * + * For remote calls, you may need to set the UserAgent and Referer strings for some environments (eg WordFence) + * Add 'referer' and 'useragent' to the initialisation config: + * + * ``` + * $api = new civicrm_api3 (['server' => 'http://example.org', + * 'api_key'=>'theusersecretkey', + * 'key'=>'thesitesecretkey', + * 'referer'=>'https://my_site', + * 'useragent'=>'curl']); + * ``` */ class civicrm_api3 { @@ -109,6 +120,8 @@ class civicrm_api3 { else { die("\nFATAL:param['api_key] missing\n"); } + $this->referer = !empty($config['referer']) ? $config['referer'] : ''; + $this->useragent = !empty($config['useragent']) ? $config['useragent'] : 'curl'; return; } if (!empty($config) && !empty($config['conf_path'])) { @@ -180,6 +193,10 @@ class civicrm_api3 { curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent); + if ($this->referer) { + curl_setopt($ch, CURLOPT_REFERER, $this->referer); + } $result = curl_exec($ch); // CiviCRM expects to get back a CiviCRM error object. if (curl_errno($ch)) {