Prevent error message, Check if $_COOKIE exist, if not create cookie

3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 1, 2016   (RSS)

By ross - November 1, 2016

Hi Zicky

I have a solution for you to try. It involves restructuring your code a bit:

// get current ticket id from cookie
$currentTicketID = @$_COOKIE['ticket_id'];

// if there is no cookie already set
// create new cookie
if (!$currentTicketID) {
    $digits = mt_rand();
    //echo $digits; //prints random numbers
    $number_of_days = 30 ;
    $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days ;
   
    setcookie( 'ticket_id', $digits, $date_of_expiry );
}

Give that a shot and let me know how you make out.

Thanks.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By Mikey - November 1, 2016

Thanks for the help Ross!!!

Works like a charm.

Zicky