php8.5
Home/ Manual/ yaf / yaf_request_abstract/ Yaf_Request_Abstract::isOptions

Yaf_Request_Abstract::isOptions

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Determine if the request is a OPTIONS request

Description

Yaf_Request_Abstract::isOptions(): bool

Checks whether the request was sent with the OPTIONS method.

Parameters Parameters

Return Values

Returns true if the request method is OPTIONS, false otherwise.

Examples

Yaf_Request_Abstract::isOptions example

php
<?php
class ApiController extends Yaf_Controller_Abstract
{
    public function corsAction()
    {
        // Assuming the browser sends a CORS preflight request
        if ($this->getRequest()->isOptions()) {
            $this->getResponse()
                 ->setHeader("Allow", "GET, POST, OPTIONS")
                 ->setBody("");
            return false;
        }
    }
}
?>

See Also

  • Yaf_Request_Abstract::isGet
  • Yaf_Request_Abstract::isPost
  • Yaf_Request_Abstract::isPut
  • Yaf_Request_Abstract::isHead
  • Yaf_Request_Abstract::isDelete
  • Yaf_Request_Abstract::isPatch
  • Yaf_Request_Abstract::isCli
  • Yaf_Request_Abstract::isXmlHttpRequest

Source: reference/yaf/yaf_request_abstract/isoptions.xml · from the official PHP manual (php/doc-en)