How to know if the person has visited another site with cookies?

Asked

Viewed 123 times

3

Example, I have 2 different domains, I would like to know with cookies if he has visited before, or if ever clicked on certain thing on my other site, ie if he has visited my site before, clicked on one thing saved the cookies there, when it goes to another site do not need to see or click again.

I can do it in the same field, but in different I don’t know.

I set the cookie like this:

setcookie("cookiee","sim", time() + 172800,  $path = "/"); // 86400 = 1 dia, 172800 = 2 dias (SEGUNDOS)

And so I see:

<?php if (!isset($_COOKIE['cookiee'])): ?>
 Não tem
<?php else: ?>
 Tem
<?php endif; ?>
  • 5

    Dude, I think cookie is domain exclusive, so you can’t get access from another domain. I’m afraid you’ll have to use databases.

1 answer

6


Matthew, unfortunately, nay can access cookies from another page, or how to set cookies for another page.

What you can do is the following:
Let’s assume you have the mastery a.com and b.com. When the user opens a.com, keeps a cookie for a.com, and, open a page of b.com (for example, with an iframe). This page b.com (savecookie.php, for example), save the cookie to the page b.com.


Practical Example

a. com/index.php

<?php
setCookie("visited", "true", time() + (10 * 365 * 24 * 60 * 60); //O máximo de duração
?>
<iframe style="display:none" src="b.com/setcookie.php"></iframe>

b. com/setcookie.php

<?php
setCookie("visited", "true", time() + (10 * 365 * 24 * 60 * 60);
?>

Then you can consult the cookie of any of the pages. Tell me if I didn’t make myself clear.

Browser other questions tagged

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