Solved

Write and reading a cookie on php

Posted on 2011-03-16
1
317 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
Comment Utility
<?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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

771 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

10 Experts available now in Live!

Get 1:1 Help Now