change color after a page was visited using Bootstrap

Asked

Viewed 35 times

0

it seems that doing so has no effect:

a:visited{
   color: #red;
}

There is another possibility to know which page the person has visited?

I’m using php

1 answer

0

Using cookies it is possible to check whether a page has been visited.

For example:

setcookie("visitado", "1" /*, time() + 3600 */);

Where the third parameter that was omitted sets the cookie to expire in an hour, when omitted the cookie is only valid until the browser closes.

Remember that the cookie should be created before any output, so it is more appropriate to create it at the beginning of the code.

In your layout file you would do something like:

<a class="<?= key_exists("visitado", $_COOKIE) ? 'visited' : '' ?>">Página inicial</a>

And in your css file:

.visitado {
  color: red;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.