How to sanitize my cookie name

I’m setting a cookie after my Gravity Form is submitted. The name is based on the current page, so each page that has this form will have its own cookie. Some pages with urls ending such as /324234-2/ will not set the cookie and return a error message (Warning: Cookie names cannot contain any of the following ‘=,; trn1314), while others with more regular names will. I’m trying to sanitize this cookie names so that I don’t get any errors at all.

This is my function:

add_action( ‘gform_after_submission_6’, ‘contentCookie’, 10, 2);
function contentCookie($entry, $form) {
$from_page = rgar( $entry, ‘6’ );
setcookie( ‘unrestrict_’.$from_page, 1, strtotime( ‘+30 days’ ), COOKIEPATH, COOKIE_DOMAIN, false, false);

How do I sanitize my cookie name? Thank you!

Read more here:: How to sanitize my cookie name

Leave a Reply

Your email address will not be published. Required fields are marked *