php

embluk

·

Setting a Cookie in PHP

·

PHP

·

Total Size: 543 B

·

·

Created: 6 months ago

·

Edited: 6 months ago

<?php $cookie_name = "user"; $cookie_value = "John Doe"; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day

The following example creates a cookie named "user" with the value "John Doe". The cookie will expire after 30 days (86400 * 30). The "/" means that the cookie is available in entire website (otherwise, select the directory you prefer).

We then retrieve the value of the cookie "user" (using the global variable $_COOKIE). We also use the isset() function to find out if the cookie is set

0 bits

119 views

Are you sure you want to delete?