<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC4%2FCookies-Part-1%2FEnglish</id>
		<title>PHP-and-MySQL/C4/Cookies-Part-1/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC4%2FCookies-Part-1%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C4/Cookies-Part-1/English&amp;action=history"/>
		<updated>2026-05-13T02:36:55Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C4/Cookies-Part-1/English&amp;diff=872&amp;oldid=prev</id>
		<title>Pravin1389: moved PHP-and-MySQL/C4/Cookies-(Part 1)/English to PHP-and-MySQL/C4/Cookies-Part-1/English</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C4/Cookies-Part-1/English&amp;diff=872&amp;oldid=prev"/>
				<updated>2012-12-01T15:05:07Z</updated>
		
		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php/PHP-and-MySQL/C4/Cookies-(Part_1)/English&quot; class=&quot;mw-redirect&quot; title=&quot;PHP-and-MySQL/C4/Cookies-(Part 1)/English&quot;&gt;PHP-and-MySQL/C4/Cookies-(Part 1)/English&lt;/a&gt; to &lt;a href=&quot;/index.php/PHP-and-MySQL/C4/Cookies-Part-1/English&quot; title=&quot;PHP-and-MySQL/C4/Cookies-Part-1/English&quot;&gt;PHP-and-MySQL/C4/Cookies-Part-1/English&lt;/a&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 15:05, 1 December 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Pravin1389</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C4/Cookies-Part-1/English&amp;diff=570&amp;oldid=prev</id>
		<title>Chandrika: Created page with '{|Border=1 !Time !Narration |- |0:00 |Welcome to this tutorial on php cookies.   |- |0:04 |Cookies are a very important part when creating special websites where you store inform…'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C4/Cookies-Part-1/English&amp;diff=570&amp;oldid=prev"/>
				<updated>2012-11-29T06:53:49Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{|Border=1 !Time !Narration |- |0:00 |Welcome to this tutorial on php cookies.   |- |0:04 |Cookies are a very important part when creating special websites where you store inform…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{|Border=1&lt;br /&gt;
!Time&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
|0:00&lt;br /&gt;
|Welcome to this tutorial on php cookies.  &lt;br /&gt;
|-&lt;br /&gt;
|0:04&lt;br /&gt;
|Cookies are a very important part when creating special websites where you store information about a user.&lt;br /&gt;
|-&lt;br /&gt;
|0:11&lt;br /&gt;
|The definition of a cookie is a set of data stored on your computer or the user's computer by the web server.&lt;br /&gt;
|-&lt;br /&gt;
|0:18&lt;br /&gt;
|This means, that when we go to a website, our details are stored and are used when we visit it again, provided we select an option like 'Remember me'.&lt;br /&gt;
|-&lt;br /&gt;
|0:30&lt;br /&gt;
|So you don't have to keep logging in. &lt;br /&gt;
|-&lt;br /&gt;
|0:32&lt;br /&gt;
|But if you didn't check a button like 'remember me', you will probably be dealing with sessions which close as soon as the user closes the browser.&lt;br /&gt;
|-&lt;br /&gt;
|0:42&lt;br /&gt;
|So sessions are killed straight away however cookies are stored for later use.  &lt;br /&gt;
|-&lt;br /&gt;
|0:50&lt;br /&gt;
|So lets begin right away and see how to create a cookie.&lt;br /&gt;
|-&lt;br /&gt;
|0:53&lt;br /&gt;
|You do this by using the setcookie function.&lt;br /&gt;
|-&lt;br /&gt;
|0:55&lt;br /&gt;
|The function takes 5 parameters but I will use just 3.&lt;br /&gt;
|-&lt;br /&gt;
|1:00&lt;br /&gt;
|The first vital one I will use is the name of the cookie which I will set to 'name'.&lt;br /&gt;
|-&lt;br /&gt;
|1:05&lt;br /&gt;
|The second one is the data that needs to be stored inside this cookie and I'll type Alex here.&lt;br /&gt;
|-&lt;br /&gt;
|1:12&lt;br /&gt;
|Now the next one's a bit more tricky.&lt;br /&gt;
|-&lt;br /&gt;
|1:15&lt;br /&gt;
|Its the time in which it expires.&lt;br /&gt;
|-&lt;br /&gt;
|1:18&lt;br /&gt;
|Now this needs to be set in seconds.&lt;br /&gt;
|-&lt;br /&gt;
|1:21&lt;br /&gt;
|And to represent this I am going to create a variable called 'exp' for expire and this will be equal to the time.&lt;br /&gt;
|-&lt;br /&gt;
|1:28&lt;br /&gt;
|Let me add some value here.&lt;br /&gt;
|-&lt;br /&gt;
|1:31&lt;br /&gt;
|At the moment I am adding zero.&lt;br /&gt;
|-&lt;br /&gt;
|1:33&lt;br /&gt;
|So if I echo this out and get rid of this cookie function for now.&lt;br /&gt;
|-&lt;br /&gt;
|1:39&lt;br /&gt;
|I'm just echoing out the time here just to show you what it does.&lt;br /&gt;
|-&lt;br /&gt;
|1:43&lt;br /&gt;
|So lets refresh.  So you can see quite a lot of digits here.&lt;br /&gt;
|-&lt;br /&gt;
|1:47&lt;br /&gt;
|Now this is the unique time-stamp. &lt;br /&gt;
|-&lt;br /&gt;
|1:50&lt;br /&gt;
|And the unique time-stamp is the number of seconds before January the 1st 1970.&lt;br /&gt;
|-&lt;br /&gt;
|1:56&lt;br /&gt;
|So January the 1st at 12 am ummmm...... in the year 1970.&lt;br /&gt;
|-&lt;br /&gt;
|2:02&lt;br /&gt;
|So you can see it here - I think the number of seconds in here equates to a date in the future.&lt;br /&gt;
|-&lt;br /&gt;
|2:10&lt;br /&gt;
|So for example, at this moment you can see this 88, now 89 and as I keep refreshing, by every second this increases.&lt;br /&gt;
|-&lt;br /&gt;
|2:20&lt;br /&gt;
|So yes, this is quite useful way of adding a specific value here.&lt;br /&gt;
|-&lt;br /&gt;
|2:28&lt;br /&gt;
|Now we need to find out the time in seconds of a day because I want this cookie to expire in a day.&lt;br /&gt;
|-&lt;br /&gt;
|2:34&lt;br /&gt;
|So I multiply 24 by 60 to get the number of minutes in a day. &lt;br /&gt;
|-&lt;br /&gt;
|2:39&lt;br /&gt;
|And then multiply the answer by  60 to get the number of seconds in a day which is 86,400.  &lt;br /&gt;
|-&lt;br /&gt;
|2:47&lt;br /&gt;
|So if I replace zero with 86400, we have the variable &amp;quot;expire&amp;quot; that now holds the time in the future by a day. &lt;br /&gt;
|-&lt;br /&gt;
|2:56&lt;br /&gt;
|To save time, I am copying this and I will add my expire variable here.&lt;br /&gt;
|-&lt;br /&gt;
|3:02&lt;br /&gt;
|So this function will set our cookie called 'name' with a value of 'Alex' and it will expire in a day - read in seconds using the time function here.&lt;br /&gt;
|-&lt;br /&gt;
|3:13&lt;br /&gt;
|So lets refresh this page and hey! we can see we have no errors which means it has worked. &lt;br /&gt;
|-&lt;br /&gt;
|3:19&lt;br /&gt;
|Now what I'll do is I'll use block commenting to comment out all of these. &lt;br /&gt;
|-&lt;br /&gt;
|3:23&lt;br /&gt;
|And below this I'll echo out this cookie.&lt;br /&gt;
|-&lt;br /&gt;
|3:26&lt;br /&gt;
|But the reason I have commented this is because you don't need to set a cookie every time the user comes into the page. &lt;br /&gt;
|-&lt;br /&gt;
|3:33&lt;br /&gt;
|If you are using a log in script and you let the user log into your website, you would need to issue this only once and then the cookie will be stored.&lt;br /&gt;
|-&lt;br /&gt;
|3:41&lt;br /&gt;
|And you could use it within this time that we have set here.&lt;br /&gt;
|-&lt;br /&gt;
|3:46&lt;br /&gt;
|So what I'll do is I'll set echo and I'll use a dollar sign, sorry, underscore cookie. &lt;br /&gt;
|-&lt;br /&gt;
|3:52&lt;br /&gt;
|Inside here is the name of the cookie so I'll type 'name'. Refresh and you can see 'Alex'.&lt;br /&gt;
|-&lt;br /&gt;
|3:59&lt;br /&gt;
|You can check it out.  Even if I close my browser, restart my computer and came back into this page, it will still read Alex because its been stored into the computer.&lt;br /&gt;
|-&lt;br /&gt;
|4:11&lt;br /&gt;
|Okay now if had to set another cookie, let's say, I set another cookie here and this will be 'age' and my age is 19.&lt;br /&gt;
|-&lt;br /&gt;
|4:24&lt;br /&gt;
|And my expiry time I'll just keep as this.  &lt;br /&gt;
|-&lt;br /&gt;
|4:29&lt;br /&gt;
|So lets just put this up here. &lt;br /&gt;
|-&lt;br /&gt;
|4:31&lt;br /&gt;
|We can replace the block commenting with line-comment to keep it neat.&lt;br /&gt;
|-&lt;br /&gt;
|4:36&lt;br /&gt;
|So for our expiry time I'll set another cookie in here. &lt;br /&gt;
|-&lt;br /&gt;
|4:41&lt;br /&gt;
|And that’ll have the same expiry time.  Lets see if I can get it right. &lt;br /&gt;
|-&lt;br /&gt;
|4:46&lt;br /&gt;
|Okay so we'll get rid of this.&lt;br /&gt;
|-&lt;br /&gt;
|4:48&lt;br /&gt;
|We’ve set another cookie with the same expiry time.&lt;br /&gt;
|-&lt;br /&gt;
|4:51&lt;br /&gt;
|Lets refresh. Okay that has been set.&lt;br /&gt;
|-&lt;br /&gt;
|4:55&lt;br /&gt;
|So what I'll do is comment this out and here I will echo it out.&lt;br /&gt;
|-&lt;br /&gt;
|5:01&lt;br /&gt;
|So you see we can set more than one cookie in a page. Lets refresh that and we can get 19.&lt;br /&gt;
|-&lt;br /&gt;
|5:07&lt;br /&gt;
|Now we can also set a cookie in a single sentence. &lt;br /&gt;
|-&lt;br /&gt;
|5:11&lt;br /&gt;
|For that I'll type echo underscore cookie, name and the concatenate &amp;quot;is&amp;quot; and then concatenate my age.&lt;br /&gt;
|-&lt;br /&gt;
|5:27&lt;br /&gt;
|Therefore we will have a sentence saying Alex is 19 just from the cookies that we've stored. &lt;br /&gt;
|-&lt;br /&gt;
|5:34&lt;br /&gt;
|And again if I close my browser or restart my computer or come back two hours later, this information will still be there stored on this computer ready to be used by this page.&lt;br /&gt;
|-&lt;br /&gt;
|5:44&lt;br /&gt;
|So you can see that they are really very useful to use and really easy to create as well and easy to echo out the user. &lt;br /&gt;
|-&lt;br /&gt;
|5:53&lt;br /&gt;
|Now there's a function we can use called 'print r' or 'print underscore r'. &lt;br /&gt;
|-&lt;br /&gt;
|5:58&lt;br /&gt;
|And we can echo out 'dollar underscore cookie' here. We can align it a bit later...&lt;br /&gt;
|-&lt;br /&gt;
|6:05&lt;br /&gt;
|Refresh this and you can see we've got an array here and we have a different value. &lt;br /&gt;
|-&lt;br /&gt;
|6:12&lt;br /&gt;
|We have got name and that is equal to Alex and we've got an age which is equal to 19. &lt;br /&gt;
|-&lt;br /&gt;
|6:22&lt;br /&gt;
|So these are cookies and they have been set and these are the values of the cookies.&lt;br /&gt;
|-&lt;br /&gt;
|6:27&lt;br /&gt;
|This can be very useful if you want to echo this out to yourself. &lt;br /&gt;
|-&lt;br /&gt;
|6:31&lt;br /&gt;
|Okay now there is another function which I will cover in the second part of this tutorial and I'll use an 'if' statement to find out if a cookie is set or not. &lt;br /&gt;
|-&lt;br /&gt;
|6:41&lt;br /&gt;
|And I'll also show you how to unset a cookie.&lt;br /&gt;
|-&lt;br /&gt;
|6:45&lt;br /&gt;
|So join me in part 2 and thanks for watching.  This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye.&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>