As per my requirement i want to logout the customer using PHP curl.
for that I used the following code in my custom controller action(execute)
$lastCustomerId = $this->_customerSession->getId();
$this->_customerSession->logout()->setBeforeAuthUrl($this->_redirect->getRefererUrl())
->setLastCustomerId($lastCustomerId);
$value = $this->getCookieManager()->getCookie('mage-cache-sessid');
if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
$metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
$metadata->setPath('/');
$this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
}
Then in my localhost i created curl.php with the following code
$logoutUrl = 'http://127.0.0.1/Magento2/frontendname/controllername/actionname';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $logoutUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
$curl_errno = curl_errno($ch);
if($curl_errno){
echo $curl_errno.'--in error'; exit;
}
print_r($result);
curl_close($ch);
When i run the curl file, it has hit the above logout page but the customer is not logout, but if i run the url directly on the browser the customer has logout.
Also tried this in controller
$pin = 'hitesh_12345678';
$customerData = $this->_customer->getCollection()->addAttributeToFilter('pin', array('eq' => $pin))->getFirstItem();
$customerId = $customerData->getData('entity_id');
if($this->_customerSession->getId() == $customerId)
{
$this->_customerSession->logout();
echo 'Customer logout successfully!'; exit;
} else {
echo "Customer is not login"; exit;
}
But none of the logout functionality is not working.
share your thoughts and ideas for logout using CURL functionality.
Thanks in advance for your better idea and support