<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: deffrin joseph</title>
    <description>The latest articles on Forem by deffrin joseph (@deffrin).</description>
    <link>https://forem.com/deffrin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F391921%2F02d81db2-e246-4cdf-89e6-475a9e369873.jpeg</url>
      <title>Forem: deffrin joseph</title>
      <link>https://forem.com/deffrin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/deffrin"/>
    <language>en</language>
    <item>
      <title>For the first time I integrated OneSignal Push Notification with PHP</title>
      <dc:creator>deffrin joseph</dc:creator>
      <pubDate>Sat, 23 May 2020 09:15:33 +0000</pubDate>
      <link>https://forem.com/deffrin/for-the-first-time-i-integrated-onesignal-push-notification-with-php-5f85</link>
      <guid>https://forem.com/deffrin/for-the-first-time-i-integrated-onesignal-push-notification-with-php-5f85</guid>
      <description>&lt;p&gt;Push notifications are the first thing I see when I switch on my phone at morning. It helps us to get notifications from all apps at a single place and we will not miss them most of the time. &lt;/p&gt;

&lt;p&gt;It was my pleasure to be part of creating such a thing in an application. But it takes some time to do things that we haven't done before and learn the right way as well. &lt;/p&gt;

&lt;p&gt;We needed the Push Notification feature for an app that is being developed in both iOS and Android. My team-mates told me that it is possible to do that using OneSignal Push Notification service. So I tried to integrate using that. I searched Google and asked some of my friends about that. Finally I got a clear idea about how I need to integrate it with the serverside.&lt;/p&gt;

&lt;p&gt;First step starts with creating an account in OneSignal and then creating an app in that OneSignal account. From that app we can then send notification using either OneSignal's website interface or the REST API provided by OneSignal. Either way, OneSignal notifications will be delivered to the devices in the same manner. Also, using OneSignal we can send notification to the selected devices too.&lt;/p&gt;

&lt;p&gt;OneSignal uses Keys &amp;amp; IDs for integration. For creating the Rest API using PHP we only need to think about those two things. Other side of the integration is done at the client side which can be Android, iOS or Web.&lt;/p&gt;

&lt;p&gt;OneSignal provides us PHP code which makes our job pretty easy. The PHP code that OneSignal provides when run will send a curl request to the OneSignal REST API and that will send notifications to all devices or to a single device.&lt;/p&gt;

&lt;h4&gt;
  
  
  How we send Push Notification to specific devices?
&lt;/h4&gt;

&lt;p&gt;Here comes the need for a OneSignal Player Id which we get from the client side. OneSignal Player Id is the cool thing we use for sending notification to a particular device. We need to collect the OneSignal Player Id from the devices using a REST Api call to your server.&lt;/p&gt;

&lt;p&gt;Then we save the OneSignal Player ID in our database as associated with the loggined user. When we need to send a notification to a user we will select the associated OneSignal Player Id and will assign it to the &lt;em&gt;'include_player_ids'&lt;/em&gt; parameter and call the Create Notification REST API.&lt;/p&gt;

&lt;p&gt;Thus we can send notification to a particular device. If we need to send to multiple devices then all the associated player ids need to be assigned to the include_player_ids.&lt;/p&gt;

&lt;p&gt;For this type of notification we need &lt;em&gt;OneSignal App ID&lt;/em&gt; and &lt;em&gt;player ids&lt;/em&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to send to all devices?
&lt;/h4&gt;

&lt;p&gt;For sending notification to a particular group of devices subscribed with our OneSignal App we can use the feature called segments, like Active Users, Inactive Users and All etc. So for sending notifications to all users we can use the segment 'All' and that need to be assigned to the parameter called &lt;em&gt;'included_segments'&lt;/em&gt; and then call the Create Notification REST API.&lt;/p&gt;

&lt;p&gt;For this type of notification we need &lt;em&gt;Onesignal App ID&lt;/em&gt; and &lt;em&gt;Rest API Key&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The rest of the PUSH notification integration part needs to be done at the client side. And since I haven't done that, I can only read aloud from the documentation as you also does. Sorry for that.&lt;/p&gt;

&lt;p&gt;OneSignal provides Firebase integration and native SDK for Android, JavaScript SDK for Web and also there is native support for iOS too. The Android and iOS devices will receive the Push Notifications and also can get all the notifications previously received as a list after the integration.&lt;/p&gt;

</description>
      <category>onesignal</category>
      <category>php</category>
      <category>pushnotification</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>There are other http status codes too..!</title>
      <dc:creator>deffrin joseph</dc:creator>
      <pubDate>Fri, 22 May 2020 03:09:04 +0000</pubDate>
      <link>https://forem.com/deffrin/there-are-other-http-status-codes-too-42n7</link>
      <guid>https://forem.com/deffrin/there-are-other-http-status-codes-too-42n7</guid>
      <description>&lt;p&gt;When my father sees a 404 page on my computer he knows that it is some kind of an error. He usually sees that on his smartphone sometimes when the internet goes off or something else. Even my father doesn't know it is a HTTP status code for Page not found, he knows that 404 is related to that kind of problem someway.&lt;/p&gt;

&lt;p&gt;Yes, http status codes are meant to give us detail about the status of http requests.&lt;/p&gt;

&lt;p&gt;I came to know more about the usability of this when I started doing API development. The Http status code I was more familiar with are 404, 500, 301, 200 , 403 , etc. I never thought there are lots of other status codes too. But when I started seeing a status code '202 Accepted' in an API response I came to think more about the purpose of it for client-server communication. '202 Accepted' means the request has been accepted and the processing is being done.&lt;/p&gt;

&lt;p&gt;We need to think that not all successful(in some sense) requests are '200 OK'. According to the result of a request the status code need to be chosen. Example, for validation errors the status code must be '422 Unprocessable Entity' and when a request fails due to the lack of a payment plan the status code need to be '402 Payment Required'.&lt;/p&gt;

&lt;p&gt;Status codes speaks by itself and can thus make api communication more meaningful. Read the wikipedia page for more info. &lt;a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes"&gt;https://en.wikipedia.org/wiki/List_of_HTTP_status_codes&lt;/a&gt;&lt;/p&gt;

</description>
      <category>http</category>
    </item>
    <item>
      <title>How I avoided spam form submits in my side project.</title>
      <dc:creator>deffrin joseph</dc:creator>
      <pubDate>Thu, 21 May 2020 12:46:29 +0000</pubDate>
      <link>https://forem.com/deffrin/how-i-avoided-spam-form-submits-in-my-side-project-20c5</link>
      <guid>https://forem.com/deffrin/how-i-avoided-spam-form-submits-in-my-side-project-20c5</guid>
      <description>&lt;p&gt;One of the first tasks that I had done when I started my programming career was creating contact forms for websites. That was the time when I heard about captcha which are used to prevent spam form submits. We were using php scripts for generating captcha and later we used Google recaptcha. &lt;/p&gt;

&lt;p&gt;I shifted many companies after the first one and I never experimented on any other solution.&lt;/p&gt;

&lt;p&gt;But in one of my personal side project that I created I was receiving many spam form submits through the Sign-up page. So I done an experiment which went successful till now. I will not say this is an ideal solution. But in my case it worked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Injecting the html form via Javascript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We normally load the html with form element  which also contains the Text Inputs and Submit button. Instead of this we need to include the form element only after the page is loaded via Javascript. So the bots trying to spam our website can't get the form when they randomly crawl the website. This will not work if the spam bot uses an headless browser or something else for rendering the website and submitting the form afterwards.&lt;/p&gt;

&lt;p&gt;I tested this in one of my site called Cherukatha.com(&lt;a href="https://cherukatha.com/"&gt;https://cherukatha.com/&lt;/a&gt;) for the signup page.&lt;/p&gt;

&lt;p&gt;What do you think. I am open to your thoughts, ideas and suggestions. :-)&lt;/p&gt;

</description>
      <category>sideprojects</category>
      <category>html</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
