Solved

Write and reading a cookie on php

Posted on 2011-03-16
1
331 Views
Last Modified: 2012-05-11
Hi all,

When I click on an image the first time I need to write a cookie so that the the code does not appear it it's already been clicked.

For example:
If cookie value not exists {
 //show the image and write the cookie if clicked
} else {
 //do nothing
}

Can anyone help please?

Thanks



0
Comment
Question by:error77
1 Comment
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35148629
<?php 

if (!isset($_COOKIE['cookie_name']) {
	// Show the image
	setcookie(
		'cookie_name', // Name of cookie
		true, // Value of cookie
		strtotime('+1 month'), // Expiry date
		'/' // Path
	);
} else {
	// do nothing
}

?>

Open in new window


See this page for some more information about cookies:
http://php.net/manual/en/function.setcookie.php
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now