<?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>DEV Community: Arif Hosen</title>
    <description>The latest articles on DEV Community by Arif Hosen (@arifhosen).</description>
    <link>https://dev.to/arifhosen</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%2F1024453%2F8c5880a4-caf1-4d56-9876-827e1724efa1.png</url>
      <title>DEV Community: Arif Hosen</title>
      <link>https://dev.to/arifhosen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arifhosen"/>
    <language>en</language>
    <item>
      <title>The Hassle-free way to find my address</title>
      <dc:creator>Arif Hosen</dc:creator>
      <pubDate>Fri, 10 Mar 2023 16:49:40 +0000</pubDate>
      <link>https://dev.to/arifhosen/the-hassle-free-way-to-find-my-address-1217</link>
      <guid>https://dev.to/arifhosen/the-hassle-free-way-to-find-my-address-1217</guid>
      <description>&lt;p&gt;Sometimes we need to fill up the address form that requires phone, city, postal code, etc. We struggle to remember our postal code. Every time&lt;br&gt;
manually searching for an address to fill out a form online is a hassle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My Address&lt;/strong&gt; Chrome extension shows clients’ address information including postal code and more based on their IP address. In the last blog, I wrote about the use case of IP address tracking. And I have developed a Chrome extension using IP tracking. For fun, I developed this extension using HTML, CSS, and JS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://drive.google.com/file/d/1NfnjXGZPT4BFN-hwyQvm7jFR2hLxKsky/view"&gt;&lt;strong&gt;Demo video&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To obtain the client’s IP address, I used jsonip, and to obtain the information about the IP address, ipapi have used.&lt;/p&gt;
&lt;h3&gt;
  
  
  manifest.json File
&lt;/h3&gt;

&lt;p&gt;The manifest.json file provides information about the configuration and features of an extension, including metadata such as the name, description, and version.&lt;br&gt;
The ‘action’ key in the manifest has two properties: ‘default_icon’, which specifies the icon for the action, and ‘default_popup’, which determines the HTML page that appears as a popup when the user clicks the icon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "manifest_version": 3,
  "name": "My Address",
  "version": "1.0",
  "description": "My Address extension provide your country name, calling code, postal code, timezone. We visit abandant website for registration, sometimes we need to provide information about us and we search for our postal code, calling code etc. My Address extension can solve your problem.",
  "icons":{
    "16": "images/icon1.png",
    "32": "images/icon1.png"
  },
  "action": {
    "default_popup": "myAddress.html",
    "default_icon": {
        "16": "images/icon1.png",
        "32": "images/icon1.png"
    }
  },
  "content_scripts": [
    {
      "js": ["scripts/content.js"],
      "matches": [
        "https://developer.chrome.com/docs/extensions/*",
        "https://developer.chrome.com/docs/webstore/*"
      ]
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  content.js File
&lt;/h3&gt;

&lt;p&gt;The content.js file contains the JavaScript code for the extension. During development, I used internal js, which resulted in an error when loading the folder unpacked. This error was due to a violation of Chrome extension rules. After fetching the jsonip API, the ipInfo function was called, which in turn called the ipapi to retrieve information. The retrieved content was assigned to an HTML element, and this element was appended to a container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let ip;
// get public ip address of client
fetch('https://jsonip.com/')
    .then(res =&amp;gt; res.json())
    .then(async function ipCall(data) {
        ip = await data.ip;
        ipInfo(ip);
    })
// get client's public ip information
function ipInfo(ip) {
    const url = `https://ipapi.co/${ip}/json/`;
    fetch(url)
        .then(res =&amp;gt; res.json())
        .then(data =&amp;gt; {
            console.log('hello', data)

            // create element
            let country = document.createElement("li");
            let city = document.createElement("li");
            let postal = document.createElement("li");
            let region = document.createElement("li");
            let countryCode = document.createElement("li");
            let countryCallingCode = document.createElement("li");
            let img = document.createElement("img");


            //  assign content
            country.innerText = "Country: " + data.country_name;
            city.innerText = "City: " + data.city;
            postal.innerText = "Postal Code: " + data.postal;
            region.innerText = "Region: " + data.region;
            countryCode.innerText = "Country Code: " + data.country_code;
            countryCallingCode.innerText = "Country Calling Code: " + data.country_calling_code;
            img.src = `https://ipapi.co/static/images/flags/${(data?.country_code).toLowerCase()}.png`;

            //   append list to container
            let flag = document.getElementById("flag");
            flag.appendChild(img);
            let listContainer = document.getElementById("details-list-container");
            listContainer.appendChild(country);
            listContainer.appendChild(city);
            listContainer.appendChild(postal);
            listContainer.appendChild(region);
            listContainer.appendChild(countryCode);
            listContainer.appendChild(countryCallingCode);

            let loader = document.getElementById("loader");
            loader.style.display = "none";
        })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;myAddress.html:&lt;/strong&gt; It contains structure and css.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;My Address&amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
        .address-body {
            /* padding: 15px; */
            min-width: 300px;
            background-color: #3C4B57;
            color: aqua;
            min-height: 300px;
            border-radius: 5px;
        }

        .flag-container {
            text-align: center;
        }

        ul {
            list-style-type: none;
            font-size: 16px;
            font-weight: 700;
            /* text-align: center; */
        }

        /* loader */
        html {
            height: 100%;
        }

        body {
            background-image: radial-gradient(circle farthest-corner at center, #3C4B57 0%, #1C262B 100%);
        }

        .loader {
            position: absolute;
            top: calc(50% - 32px);
            left: calc(50% - 32px);
            width: 64px;
            height: 64px;
            border-radius: 50%;
            perspective: 800px;
        }

        .inner {
            position: absolute;
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            border-radius: 50%;
        }

        .inner.one {
            left: 0%;
            top: 0%;
            animation: rotate-one 1s linear infinite;
            border-bottom: 3px solid #EFEFFA;
        }

        .inner.two {
            right: 0%;
            top: 0%;
            animation: rotate-two 1s linear infinite;
            border-right: 3px solid #EFEFFA;
        }

        .inner.three {
            right: 0%;
            bottom: 0%;
            animation: rotate-three 1s linear infinite;
            border-top: 3px solid #EFEFFA;
        }

        @keyframes rotate-one {
            0% {
                transform: rotateX(35deg) rotateY(-45deg) rotateZ(0deg);
            }

            100% {
                transform: rotateX(35deg) rotateY(-45deg) rotateZ(360deg);
            }
        }

        @keyframes rotate-two {
            0% {
                transform: rotateX(50deg) rotateY(10deg) rotateZ(0deg);
            }

            100% {
                transform: rotateX(50deg) rotateY(10deg) rotateZ(360deg);
            }
        }

        @keyframes rotate-three {
            0% {
                transform: rotateX(35deg) rotateY(55deg) rotateZ(0deg);
            }

            100% {
                transform: rotateX(35deg) rotateY(55deg) rotateZ(360deg);
            }
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body class="address-body"&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;div class="flag-container"&amp;gt;
            &amp;lt;h2&amp;gt;My Address&amp;lt;/h2&amp;gt;
            &amp;lt;div id="flag"&amp;gt;

            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;ul id="details-list-container"&amp;gt;

        &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;!-- loader --&amp;gt;
&amp;lt;div id="loader" class="loader"&amp;gt;
    &amp;lt;div class="inner one"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="inner two"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="inner three"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;script src="./scripts/content.js"&amp;gt;

&amp;lt;/script&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Note
&lt;/h3&gt;

&lt;p&gt;During development, use external js. Internal js violate the chrome extension rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;The blog discusses the challenges of remembering postal codes and manually searching for address information online. The post presents a solution in the form of the “My Address” Chrome extension, which uses IP tracking to retrieve clients’ address information, including their postal code. The blog goes into detail about the development of the extension using HTML, CSS, and JS, and explains how jsonip and ipapi.com were used to obtain IP address information. The blog also explains the role of the manifest.json and content.js files in configuring and managing the extension.&lt;/p&gt;

&lt;h3&gt;
  
  
  Github### &lt;a href="https://github.com/Arif-Hosen/my_address_chrome_extension"&gt;source code&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;This article is written for learning purposes. So please if I made any mistake, let me know and any feedback will be highly appreciated.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>chromeextension</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Find the location of an IP and Use Case</title>
      <dc:creator>Arif Hosen</dc:creator>
      <pubDate>Tue, 21 Feb 2023 15:49:12 +0000</pubDate>
      <link>https://dev.to/arifhosen/find-the-location-of-an-ip-and-use-case-4nmc</link>
      <guid>https://dev.to/arifhosen/find-the-location-of-an-ip-and-use-case-4nmc</guid>
      <description>&lt;p&gt;&lt;a href="https://ipapi.co" rel="noopener noreferrer"&gt;&lt;strong&gt;ipapi.co&lt;/strong&gt;&lt;/a&gt; provides the location of an IP address. It is an open API. We can use this on the server side and client side. There are abundant use case of this API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTPS Request:&lt;/strong&gt;&lt;br&gt;
GET &lt;a href="https://ipapi.co/%7Bip%7D/%7Bformat%7D/" rel="noopener noreferrer"&gt;https://ipapi.co/{ip}/{format}/&lt;/a&gt;&lt;br&gt;
The endpoints parameter are -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;ip- an ip address which is used to get location.&lt;/li&gt;
&lt;li&gt;format — response data format. ex- json.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
We can get the IP -&lt;br&gt;
City, Region, Country, Country Code, Short country name, Country capital, Country area, Postal code, Latitude, Longitude, Time zone, Country calling code, Currency, Organization and more.&lt;/p&gt;

&lt;p&gt;We can also retrieve the specific field. &lt;a href="https://ipapi.co/103.134.21.89/city/" rel="noopener noreferrer"&gt;https://ipapi.co/103.134.21.89/city/&lt;/a&gt; The response is the city name of the specified IP address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//ip_tracker.php file - submitting ip address form and set the IP to session stroage
    &amp;lt;script&amp;gt;
        $(document).ready(function() {
            $('#search').click(function() {
                const ip = $('#ip-address').val();
                sessionStorage.setItem("ip",ip);
                // console.log("IP = ", ip);
            })
        })
  &amp;lt;/script&amp;gt;

//ip_details.php file - getting ip from session stroage, call API and display reponse
&amp;lt;script&amp;gt;
        // get ip value from session storage
        const ip = sessionStorage.getItem('ip');
        const url = `https://ipapi.co/${ip}/json/`;

        // api call and append to a container
        let ipDetails = fetch(url)
        .then(res=&amp;gt;res.json())
        .then(data=&amp;gt;{
            $('#ip').text(`IP: ${data.ip}`)
            $('#details-list-container').append( $(` 
            &amp;lt;li&amp;gt;City: ${data.city}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Region: ${data.region}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Country: ${data.country_name}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Country Area: ${data.country_area}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Postal Code: ${data.postal}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Calling Code: ${data.country_calling_code}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Longitude: ${data.longitude}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Latitude: ${data.latitude}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Org: ${data.org}&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;Hostname: ${data.hostname}&amp;lt;/li&amp;gt;
            `))
        });
    &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Client’s IP Address:&lt;/strong&gt;&lt;br&gt;
It is usually used on the client side(browser). It returns the client IP’s location. So we do not need to specify IP to the endpoints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTP Request:&lt;/strong&gt;&lt;br&gt;
GET &lt;a href="https://ipapi.co/%7Bformat%7D/" rel="noopener noreferrer"&gt;https://ipapi.co/{format}/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We retrieve only public IP locations using this API. We don’t retrieve Private IP locations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;br&gt;
It is easy to use. Now, the question is what is the use case of this open API service? Doing some research I have found some use cases -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In our application, we have a form that is used for my application requirement to build a user profile and has the field of country, city, mobile, postal code, etc. of the user. Here we can easily use this API for a better experience for the user. When the user opens the form, API is called with the user IP address and those fields will be selected according to user IP locations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Our application provides different services in different cities. According to the user IP location, we can show only those services on our service section which are available in that city.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I have mentioned those use cases and planning to build an extension. Apart from this, you will find abundant use cases. If you read this blog, please mentioned your thought on use case in the comment box.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice Project:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://drive.google.com/file/d/1G431uj51Rh8GJHrWj5-CMsLXmlQuZkjG/view" rel="noopener noreferrer"&gt;Project Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Hub:&lt;/strong&gt; &lt;a href="https://github.com/Arif-Hosen/ip_tracker" rel="noopener noreferrer"&gt;Git Hub Link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This article is written for learning purposes. So please if I made any mistake, let me know and any feedback will be highly appreciated.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Auto Load in PHP (Shortly Understanding)</title>
      <dc:creator>Arif Hosen</dc:creator>
      <pubDate>Fri, 10 Feb 2023 17:50:14 +0000</pubDate>
      <link>https://dev.to/arifhosen/auto-load-in-php-shortly-understanding-357n</link>
      <guid>https://dev.to/arifhosen/auto-load-in-php-shortly-understanding-357n</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsv6odcoiivvswvrh2qwe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsv6odcoiivvswvrh2qwe.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
This article is written for learning purpose. So please if I made any mistake, please let me know and any feedback will be highly appreciated.&lt;/p&gt;

&lt;p&gt;When we learn about autoloading, Firstly, we need to understand PSR.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PSR:&lt;/strong&gt; PHP Standard Recommendation — is a set of standards that ensure working with PHP is easier. Example: PSR1- Coding standard, PSR7- HTTP request standard, PSR4- Autoloading standard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PSR4:&lt;/strong&gt; Provides the ability to include classes based on their file path. Like, you define BMW, and Mercedes classes in a different file and their namespace is Car. To load those files we need to include 2 files twice. Using PSR4 we can include files with autoloading. So, we don’t need include files of classes again again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;auto load&lt;/strong&gt; — Sometimes we need multiple files of classes in a file, here we can use autoload.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps of using auto load-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: If you have installed composer. Run ‘composer init’ to the top directory of your project folder.&lt;br&gt;
Step 2: Add the “autoload” property in the “composer.json” file, and add the “psr-4” property — its property is namespaces of classes and the value is file directory (where the auto load will find the namespaces).&lt;br&gt;
&lt;code&gt;&amp;gt; Example:&lt;br&gt;
“autoload”: {&lt;br&gt;
“psr-4”: {&lt;br&gt;
“Car\\”: “oop/autoload/car/”&lt;br&gt;
}&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Step 3: Run “composer dump-autoload”&lt;br&gt;
Step 4: Include the “vendor/autoload.php” file where you need those classes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; When you include “vendor/autoload.php”, be careful about your current directory. For — “vendor/autoload.php” is in 3 steps upper directory from your current directory, here you use- (include_once “../../../vendor/autoload.php”).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git repo:&lt;/strong&gt;&lt;a href="https://dev.tourl"&gt; https://github.com/Arif-Hosen/learn_php/tree/main/oop/autoload/car&lt;/a&gt;&lt;/p&gt;

</description>
      <category>welcome</category>
    </item>
  </channel>
</rss>
