?
Solved

Write and reading a cookie on php

Posted on 2011-03-16
1
Medium Priority
?
363 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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

801 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