Solved

Write and reading a cookie on php

Posted on 2011-03-16
1
356 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

737 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