Skip to main content
Known Participant
October 25, 2010
Question

dynamically assigning cookies in PHP?

  • October 25, 2010
  • 1 reply
  • 761 views

HI all.. I know enough of the DW8 behaviors to retrieve a mySQL table record, and place field values on the page.. but what I need to do is assign a cookie on that page... where the cookie name value is pulled from a mySQL record. This means manually coding it no doubt, but I can't figure out the context of the statement to assign a dynamic value to a cookie. Help???

This topic has been closed for replies.

1 reply

October 26, 2010

have you looked here:

http://www.w3schools.com/php/func_http_setcookie.asp

<?php

$value = $your_recordset_row['recordset_value'];

// send a cookie that expires in 72 hours
setcookie("Cookie_Name",$value, time()+3600*72);
?>

AdrianLeAuthor
Known Participant
October 26, 2010

This is the problem.. even in your example the cookie name is hard coded to "Cookie_name" .. but this is the value I need to populate from a dynamic value...

Participating Frequently
October 26, 2010

I dont know the first thing about php, but would have to guess it would be as simple as:

<?php

$value = $your_recordset_row['recordset_value'];

$cookieName = $your_recordset_row['recordset_cookieName'];

// send a cookie that expires in 72 hours
setcookie("$cookieName",$value, time()+3600*72);
?>