I'm trying to set up a cookie in Joomla from an external website using cURL. The process flow is as below:
- User does an action in external.com
- external.com cURL a URL in joomla.com
- joomla.com sets the cookie
- When user visits joomla.com, the cookie will be in their browser and it will be used to show/hide pages.
Unfortunately, I can't seem to be able to set a persistent cookie. Here's what I did:
[joomla.com] Created a custom component, with a custom controller and a custom task. Below the code on the controller:
public function createCookie() { $app = JFactory::getApplication(); $app->input->cookie->set( "TEST", "TestContent", time() + "3600", $app->get('cookie_path', '/'), $app->get('cookie_domain'), $app->isSSLConnection() ); }
[external.com] Created a cURL call to hit the task created at point 1.
$cURLConnection = curl_init(); curl_setopt($cURLConnection, CURLOPT_URL, 'https://joomla.com/index.php?option=com_test&task=testclass.createCookie'); curl_setopt($cURLConnection, CURLOPT_HEADER, false); curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cURLConnection, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYPEER, false); $curlExec = curl_exec($cURLConnection); curl_close($cURLConnection);
If I visit the joomla.com website after the cURL call, the cookie is not there, it's like it has never been created. If I visit the page directly, the cookie gets created.
My question is: How can I create a cookie in Joomla from an external cURL call?