Php Flow » Php

PHP: How to Set a Raw Cookie?

Today i was searching how to set raw coookie in php.PHP provide setrawcookie() method to set raw cookie in php.In this tutorial i will tell you with simple example which shows how to set a raw cookie.

setrawcookie() is exactly the same as setcookie() except that the cookie value will not be automatically urlencoded when sent to the browser.

This function is same as setcookie() method and accept same number of parameters.You can see the php reference manual of
setcookie() function, more details can be found below.
Manual Rawcookie

In the following example we are passing 3 parameters.

1) cookie name – its the name by which cookie will be identified.
2) cookie value – its the value stored in cookie.
3) expiration time – the time till the cookie will be available, after that it will be destroyed.

1
<?php setrawcookie( "cookiename", "cookievalue", time()+3600); ?>

How to get rawcookie value:

1
2
3
4
5
6
7
if(isset($_COOKIE['cookiename']))
	$cookieVal = $_COOKIE['cookiename'];
else
	echo "cookies is not set!";

echo "Your cookie value - ". $cookieVal;
?>
Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook. parvez1487(at)gmail(dot)com

Random Posts

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>