javascript - Push Notification Custom Save Browser id in Database

125

hi i am newbie to php and javascript and i am working on a project of Push Notification for my website which will push a notification to the user when a news related to specific category is published on my website i am using following code and curl with the help of google documentation

<html>
<head>

  <title>Push Notification codelab</title>

  <link rel="manifest" href="manifest.json">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>

<body>

  <h1>Push Notification codelab</h1>

  <p>This page must be accessed using HTTPS or via localhost.</p>

  <script src="js/main.js"></script>

  <button id="send">Send</button>

  <script>
    $("#send").click(function() {
      $.get("curl.php", function(data) {
        console.log(data);

      });
    });

  </script>
</body>
</html>

now i am wondering how to store a user's browser id or something so that it can send a notification to specific browser for specific category news.i am really looking forward to you guys to help me out for this problem.

673

Answer

Solution:

there is nothing so-called as browser id, but you can generate a unique and store that in the_COOKIE, best combination of creating an unique id would beMD5(USER_AGENT . SALTMIX_STR . IPADDR), this combination will generate a unique id for each browser and you can store that in cookie usingPHP eg.$_COOKIE["BROWSER_KEY"] = 'YOUR_UNIQUE_KEY'

EXAMPLE

<?php
$generateUniqueKey  = md5($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR']."[email protected]#zYp04)+");
$_COOKIE["BROWSER_KEY"] = $generateUniqueKey; //Sets a key
echo $_COOKIE["BROWSER_KEY"]; //retrieves the set key
?>

People are also looking for solutions to the problem: php - CakePHP install with Composer version 3.1.*

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.