What is setrawcookie() Function ?

The setrawcookie() function defines a cookie (without URL encoding) to be sent along with the rest of the HTTP headers. A cookie is often used to identify a user.

A cookie is a small file that the server embeds on the user's computer.

Syntax :

setrawcookie(name, value, expire, path, domain, secure);

  • name:

Required. Specifies the name of the cookie.

  • value:

Specifies the value of the cookie (Optional)

  • expire:

Specifies when the cookie expires (Optional) (ex: time 86400 *30)( 30 days)

  • path:

Specifies the server path of the cookie. (Optional)

  • domain:

Specifies the domain name of the cookie (Optional) (ex: google.com) (www.google.com, www is a sub domain)

  • secure:

Specifies whether or not the cookie should only be transmitted over a secure HTTPS connection. (ex: true or fales)

Example:

<?php

$cookie_name = "user"; // (user name)

$cookie_value = "testing"; // (value)

setrawcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");

?>

<?php

echo "Cookie is set.";

?>


Out put:

Cookie is set.

Sign In or Register to comment.