title: Get player_id from OneSignal on page load
body: <p>I am implementing web push notifications using <a href="https://onesignal.com/" rel="noreferrer">Onesigal</a> API.</p>
  
  <pre><code>    $fields = array(
          'app_id' =&gt; "07aae1f0-xxxx-xxxx-aa7a-21c79c5b6733",
          'include_player_ids'=&gt;['57dd3f80-xxxx-xxxx-adb0-294bfa69621a'],
          'contents' =&gt; array( "en"=&gt; "message" )
      );
  
      $fields = json_encode($fields);
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
                                                 'Authorization: Basic YTdmYTYxYzYtN...tNjVlNzJkNDFlZmMz'));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_HEADER, FALSE);
      curl_setopt($ch, CURLOPT_POST, TRUE);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
      curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem' );
      $response = curl_exec($ch);
      curl_close($ch);
  </code></pre>
  
  <p>Above code sends a push notification to the user if you know his <code>player_id</code>. But suppose if some user visits my site and subscribes to push notifications and leaves.Later again he visits (he is already subscribed) and favs.(adds to favorite) a currently out of stock product.<strong>So how can I get <code>player_id</code></strong> of this user which I can store in <code>"subs_fav"</code> table ?</p>
  
  <pre><code>id  player_id           product_id
  1   57dd3f80...a69621a  p097
  </code></pre>
  
  <p>When that product becomes available <code>pushFav()</code> function will run which would notify the user that the product is now available and they can buy it but for that we should know the player_id of the user who favd. this product. I want to know how to find this player_id so that I can send it <code>addToFav()</code> ajax call to store in <code>"sub_fav"</code> table</p>