1

Currently I am facing the problem that have been discussed already here: How to keep track of a unique and an existing visitor (keep track about unique user without registration etc.). The most suitable answer was: "Try _ga cookie". So my questestion is how can I do that on my PHP website?

I want something like this:

  1. User came to my website and performs some action
  2. I "look into his _ga cookie" and take some "identification code"
  3. I log about this action to the database
  4. When user will come again and he will want to perform action again, then I look into my log and I will realize that this is same user

My question is:

How to read user identification from _ga ?

1 Answer 1

1

Just get _ga cookie - it is a string with dot separated values. You are looking for third value...

  public static function getGaCode() {

    // Check fo cookie
    $name = "_ga";
    if (!isset($_COOKIE[$name])) {
      return null;
    }

    // Parse cookie _ga='<something>.<something>.<clientid>.<timestamp>';
    return explode(".", $_COOKIE[$name])[2];
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.