2

Does anyone know why I cant get cookies from the remote server with the code below?

<?php 

    $inputCookie    =   JFactory::getApplication()->input->cookie;
    $value          =   $inputCookie->get($name = 'hotsiteX', $defaultValue = null);
    $mark = 0;

    if ( is_null($value)  ): ?>

        "html code"
        <?php $mark = 1;
              $inputCookie->set($name = 'hotsiteX', $value = 'accessed', $expire = time() + (100));         

    endif; ?>

?>

$cookieValue is always empty, I checked and its already set on my browser, besides, it also works perfectly on localhost.

I already tried !isset($_COOKIE) and print($_COOKIE), its always empty at the remote server.

4

Below should work for you. This was taken from [This Answer][1]

//GET JOOMLA COOKIES
$inputCookie  = JFactory::getApplication()->input->cookie;

//GET SPECIFIC COOKIES DATA
$value        = $inputCookie->get($name = 'MyCookieName', $defaultValue = NULL);

//CONDITIONAL STATEMENT TO RETRIEVE OR SET A COOKIE
if(is_null($value)){
    //SET YOUR COOKIE IF IT DOES NOT ALREADY EXIST
    $inputCookie->set($name = 'MyCookieName', $value = 'TestCookieVal', $expire = 0);
    echo 'NO COOKIE EXISTS, CREATING NEW COOKIE';
}else{
    //DO SOMETHING WITH YOUR COOKIE DATA IF IT ALREADY EXISTS
    echo $value;
    echo 'COOKIE EXISTS';
}
  • now can print the $value and see that it has the cooked i that i put, but when i try to verify its value, it always returns that its empty. empty($value) always return true. – Syan Souza Mar 16 '16 at 16:30
  • empty() is looking to see if the $value either does not exist or is false. Check your $value with something like this: ((isset($value) && $value === 'myvalue')?'true':'false') – Terry Carter Mar 16 '16 at 17:38
  • Ok, i'll try it. Do you have any ideia why it works on localhost but not on the remote server. – Syan Souza Mar 16 '16 at 18:10
  • Not a clue on that one. Possibly server setup? – Terry Carter Mar 16 '16 at 18:19
  • I realized that the method $inputCookie->get returns empty or null if i didnt use the method $inputCookie->set before printing it. – Syan Souza Mar 16 '16 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.