?
Solved

Write and reading a cookie on php

Posted on 2011-03-16
1
Medium Priority
?
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 2000 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

650 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