S
S
sanya1642015-01-10 03:09:21
JavaScript
sanya164, 2015-01-10 03:09:21

How to add and check for cookies?

I have a website that displays a click object when accessed.
The main object is also hidden by default.
After clicking on click, click is hidden and main is shown.

#main {
  display: none;
}

function FuncImages() {
  document.getElementById("main").style.display = "block";
  document.getElementById("click").style.display = "none";
}

<div id = "main">Данные</div>
<div id = "click" onclick = "FuncImages()">Здесь картинка</div>

How to make when clicking on click, main is displayed, and the next 5 hours after reloading the page or browser, click is not shown, but main is shown.
I know what can be done through cookies, but I do not understand them.
To whom it is not difficult, describe in more detail how to implement it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Matvey Mamonov, 2015-01-11
@sanya164

PHP:
This is a setup.
PHP:

if (isset($_COOKIE["name"])) {
  // Какие-то действия
}

This code checks if (isset function) the cookie "name" exists. $_COOKIE[] is a global array that contains all the cookies that exist on your site. And to get the value of a cookie, just access it: $_COOKIE["name"].
To output, just precede it with print.

N
Nikita Baev, 2015-01-10
@drugoi

Didn't you ask the same question yesterday? → How to check for cookies and perform a specific action?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question