{"id":57326,"date":"2021-09-06T21:01:03","date_gmt":"2021-09-06T13:01:03","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=57326"},"modified":"2021-09-06T16:42:47","modified_gmt":"2021-09-06T08:42:47","slug":"build-url-shorterner-php","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/","title":{"rendered":"Building a URL Shortener with PHP"},"content":{"rendered":"<p>Having your <a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/how-to-create-url-shortener-with-your-domain\/\" rel=\"noopener\">page URL shorter<\/a> has several benefits. First, it reduce the number of characters which would be handy for sharing on chats or social media that impose character limits like Twitter and Facebook.<\/p>\n<p>You can also <strong>use short URL to mask a URL like those for affiliates that contains special parameters<\/strong>. And you can also track the number of visits from these URLs which can be useful tracking of a campaign or for analytics.<\/p>\n<p>There are a number of service both or paid where you can shorten URLs easily. Bit.ly for example is one of the most prominents in this category. But did you know that <strong>you can actually build your own URL shortener?<\/strong><\/p>\n<p>Building your own means that you are in control of all the data. You can also use your own domain. Or, add customize functionalities or custom integration which might not be possible to have in the paid service. If you feel adventurous, follow along this article; we\u2019ll show you how.<\/p>\n<div class=\"ref-block ref-block--post\" id=\"ref-post-1\">\n\t\t\t\t\t<a href=\"https:\/\/www.hongkiat.com\/blog\/url-shortening-services-the-ultimate-list\/\" class=\"ref-block__link\" title=\"Read More: 10+ Best Free URL Shortening Services\" rel=\"bookmark\"><span class=\"screen-reader-text\">10+ Best Free URL Shortening Services<\/span><\/a>\n<div class=\"ref-block__thumbnail img-thumb img-thumb--jumbo\" data-img='{ \"src\" : \"https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250x160\/url-shortening-services-the-ultimate-list.jpg\" }'>\n\t\t\t\t\t\t\t<noscript>\n<style>.no-js #ref-block-post-1272 .ref-block__thumbnail { background-image: url(\"https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250x160\/url-shortening-services-the-ultimate-list.jpg\"); }<\/style>\n<\/noscript>\n\t\t\t\t\t\t<\/div>\n<div class=\"ref-block__summary\">\n<h4 class=\"ref-title\">10+ Best Free URL Shortening Services<\/h4>\n<p class=\"ref-description\">\n\t\t\t\t\t\tIn this post we have 40 of them, most of which you probably have not heard of. Some...\t\t\t\t\t\t<span>Read more<\/span><\/p>\n<\/div>\n<\/div>\n<h2>Requirements<\/h2>\n<p>Before starting this tutorial, we would assume that you\u2019d already be familiar with web development process and comfortable <strong>working with the stacks like the PHP and MySQL<\/strong> to some degree. Also, you will also need the following:<\/p>\n<h3>1. Hosting Account<\/h3>\n<p>It does not matter where you host it as long as it could run PHP and MySQL. I would suggest to get one that <strong>provides cPanel and SSH access<\/strong> since we would like to have it set up directly on the host rather the computer localhost.<\/p>\n<h3>2. Domain<\/h3>\n<p>You can pick any TLD; the the shortest the domain the better.<\/p>\n<h3>3. Supporting Tools<\/h3>\n<p>It\u2019ll also be nice if it also provides supporting tools like <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/getcomposer.org\/\">Composer<\/a> and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/git-scm.com\/\">Git<\/a> as we would need them to pull some PHP libraries.<\/p>\n<p>Now we\u2019ll start putting all these together to get our custom Short URL application up and running.<\/p>\n<h2>Step 1: Getting a hosting account<\/h2>\n<p>Get a hosting account. For this tutorial we are going to host our Short URL application using <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hostarmada.com\/\"><strong>HostArmada<\/strong><\/a>.<\/p>\n<figure><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hostarmada.com\/\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/hostarmada.jpg\" alt=\"hostarmada\" width=\"1800\" height=\"1265\"><\/a><\/figure>\n<p>Since we don\u2019t need that high-specification, we choose Host Armada\u2019s <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hostarmada.com\/cloud-ssd-shared-hosting\/\"><strong>Web Warp<\/strong><\/a> hosting option. The hosting runs on Nginx, with:<\/p>\n<ul>\n<li>30 GB of SSD,<\/li>\n<li>4 Cores CPU, and<\/li>\n<li>4 GB RAM.<\/li>\n<\/ul>\n<p>It also <strong>includes free SSL certificate<\/strong> for each domain we added on the account, and it only cost $4.69\/month.<\/p>\n<p>On top of that it provides the base infrastucture that we need to run the application such as the cPanel with the SSH access, Git and Composer out of the box so we can start building our application rightaway instead of installing the tools.<\/p>\n<h2>Step 2: Point your domain<\/h2>\n<p>After you\u2019ve got the hosting, you\u2019d need a domain and point it to your hosting. This is done through the <strong>DNS manager which usually should be provided by the domain registrar<\/strong> where you register the domain or the hosting.<\/p>\n<p>Basically you\u2019d need to <strong>point the domain to the IP address provided by the hosting provider<\/strong>. But each provider would have slightly different panel as well as instruction to follow, so pick and follow one of the these references that would work with your provider.<\/p>\n<ul>\n<li><strong>cPanel<\/strong>: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hostarmada.com\/tutorials\/getting-started\/cpanel\/how-to-manage-the-dns-zones-for-your-domains-in-cpanel\/\">How to manage the DNS Zones for your Domains in cPanel?<\/a><\/li>\n<li><strong>VPS<\/strong>: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.digitalocean.com\/products\/networking\/dns\/how-to\/add-domains\/\">How to Add Domains<\/a><\/li>\n<li><strong>Cloudflare<\/strong>: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/support.cloudflare.com\/hc\/en-us\/articles\/360019093151-Managing-DNS-records-in-Cloudflare\">Managing DNS in Cloudflare<\/a><\/li>\n<\/ul>\n<p>Keep in mind that DNS resolution may take about 24-48 hours after you\u2019ve made the change to the IP. You can check the progress with tools like <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.whatsmydns.net\/\">WhatsMyDNS<\/a>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/whatsmydns.jpg\" alt=\"whats my dns\" width=\"750\" height=\"480\"><\/figure>\n<h2>Step 3: Logging in to SSH<\/h2>\n<p>SSH is a channel to <strong>run some application through command line<\/strong>. In this tutorial, we are going to run some command-lines like <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/git-scm.com\/\">Git<\/a> and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/getcomposer.org\/\">Composer<\/a>.<\/p>\n<p>In cPanel, you can <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/hostarmada.com\/kb\/ssh-and-linux\/how-can-i-connect-via-ssh-on-hostarmada\/\">follow this article<\/a> to setup SSH connection on macOS or Windows. If you find encounter issues on connecting to SSH, reach out to your hosting provider .<\/p>\n<h2>Step 4: Downloading Polr<\/h2>\n<p>Next you need to <strong> download <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/polrproject.org\/\">Polr<\/a><\/strong>. It is an open-source PHP library that allows us to run and host your own URL shortener.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/polr.jpg\" alt=\"polr\" width=\"1242\" height=\"696\"><\/figure>\n<p>It provides the APIs and administration to manage the URLs, users, and some other customisations. We are going to <strong>download this library to the root directory<\/strong> (typically this directory is named <code>public_html<\/code>).<\/p>\n<p>Run the following command:<\/p>\n<pre>git clone https:\/\/github.com\/cydrobolt\/polr.git --depth=1 .<\/pre>\n<h2>Step 4: Configure the server<\/h2>\n<p>We are going to configure the host and Polr installation so it can run well and accessible from the domain. To do this, we\u2019d first need to <strong>ensure that our host run on at least PHP7.2<\/strong>.<\/p>\n<p>In cPanel, you can easily check and select it from <strong>Software &gt; Select PHP version<\/strong>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/select-php-versions.jpg\" alt=\"php version\" width=\"750\" height=\"480\"><\/figure>\n<p><strong>4.1: Configure the Root Directory<\/strong><\/p>\n<p>We also need to <strong>point the root directory to public<\/strong> that comes with the Polr library. This is the directory where the <strong>index.php<\/strong> file resides. This file will need to execute when the website get a request.<\/p>\n<p>In cPanel, we can set it from <strong>Domains &gt; Domains<\/strong>. Check the directory that the <strong>Document Root<\/strong> is pointing. In our case, this path directory is at <code>~\/public_html\/public<\/code>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/root-directory.jpg\" alt=\"root directory\" width=\"750\" height=\"480\"><\/figure>\n<p><strong>4.2: Configure the Database<\/strong><\/p>\n<p>We need to create a new database to store the data like the ID, the URL, and the short URL itself. In cPanel, we can create a new database and attach a user from the <strong>MySQL Database Wizard<\/strong>. You simply need to fill in the input and follow the direction.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/db-user.jpg\" alt=\"db user\" width=\"750\" height=\"480\"><\/figure>\n<p>Note down the following as you will need it later:<\/p>\n<ul>\n<li>Database name.<\/li>\n<li>Database user and the user password.<\/li>\n<\/ul>\n<h2>Step 5: Polr setup and installation<\/h2>\n<p>We can begin installing the library to our host. For this, run the composer command below to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/getcomposer.org\/doc\/01-basic-usage.md#installing-dependencies\">install the library dependencies<\/a>.<\/p>\n<pre>composer install<\/pre>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/composer-install.jpg\" alt=\"composer install\" width=\"750\" height=\"480\"><\/figure>\n<p>\u2026rename the file <code>.env.setup<\/code> to <code>.env<\/code><\/p>\n<pre>mv .env.setup .env<\/pre>\n<p>Load the domain and <code>\/setup<\/code> on the browser. On this page, you will see a form where you need to input the required information.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/polr-setup.jpg\" alt=\"polr setup\" width=\"750\" height=\"480\"><\/figure>\n<p>There are a number of inputs. But the most important ones are those in the <strong>Database Configuration<\/strong> and <strong>Application Settings<\/strong>.<\/p>\n<p>Fill in the following information to connect to the database and the user.<\/p>\n<ul>\n<li><strong>Database Host:<\/strong> <code>localhost<\/code><\/li>\n<li><strong>Database Port:<\/strong> <code>3306<\/code><\/li>\n<li><strong>Database Username:<\/strong> <code>hongkiat_urluser<\/code> (Change this with the one you set on <strong>Step 4<\/strong>)<\/li>\n<li><strong>Database Password:<\/strong> <code>*****<\/code> (Change this with the one you set on <strong>Step 4<\/strong>)<\/li>\n<li><strong>Database Name:<\/strong> <code>hongkiat_urluser<\/code> (Change this with the one you set on <strong>Step 4<\/strong>)<\/li>\n<\/ul>\n<p>Once done, fill in the following in the main settings of the short URL application.<\/p>\n<ul>\n<li><strong>Application Name:<\/strong> (fill this with anything)<\/li>\n<li><strong>Application Protocol:<\/strong> (whether your application would run on HTTP or HTTPS. note that HTTPS requires SSL cert to be installed.)<\/li>\n<li><strong>Application URL:<\/strong> (add the domain you\u2019ve setup earlier in this tutorial)<\/li>\n<\/ul>\n<p>You can proceed with setting up the rest of the optional inputs as you like. Click the <strong>Install<\/strong> button on that <code>\/setup<\/code> page to install the application.<\/p>\n<p>That\u2019s all. The installation should be quick. Load the homepage when it\u2019s done. You should see the input to shorten the URL as seen in the following screenshot.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/polr-homepage.jpg\" alt=\"polr homepage\" width=\"750\" height=\"281\"><\/figure>\n<h2>Testing<\/h2>\n<p>To see if our short URL application works, we\u2019ll try to add a URL, for example <code>https:\/\/www.hongkiat.com\/blog\/windows-11-features\/<\/code> and hit that <strong>Shorten<\/strong> button on the homepage.<\/p>\n<p>Below, we can see that our application generated the short URL with our custom domain. It can <strong>also generate the QR code for the short URL<\/strong> if you intend to share the URL physically.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/generated-shorturl.jpg\" alt=\"generated shorturl\" width=\"750\" height=\"357\"><\/figure>\n<p>On top of that, you can also <strong>customize the short URL<\/strong> to generate instead of letting the application generating for you with random ID or character. To do this, click this <strong>Link Option<\/strong> and set the URL ending. Make sure to check if it\u2019s still available and hit the <strong>Shorten<\/strong> button.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/link-option.jpg\" alt=\"link option\" width=\"750\" height=\"357\"><\/figure>\n<h2>Wrapping up<\/h2>\n<p>Creating your own short URL application requires some technical know-how. It also takes time to setup. But as soon as you get through this you can potentially save money in the long run and have all the benefits that you can\u2019t otherwise get on a paid SaaS.<\/p>\n<p>You have all the data and you can <strong>use your own brandable domain without additional cost<\/strong>. If you\u2019re a PHP developer you can build custom feature and utilise all the APIs without restrictions.<\/p>\n<p>So, finally, I hope this tutorial can help you on building your own Short URL.<\/p>","protected":false},"excerpt":{"rendered":"<p>Having your page URL shorter has several benefits. First, it reduce the number of characters which would be handy for sharing on chats or social media that impose character limits like Twitter and Facebook. You can also use short URL to mask a URL like those for affiliates that contains special parameters. And you can&hellip;<\/p>\n","protected":false},"author":113,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3398],"tags":[4212],"topic":[],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Build URL Shortener with PHP - Hongkiat<\/title>\n<meta name=\"description\" content=\"Having your page URL shorter has several benefits. First, it reduce the number of characters which would be handy for sharing on chats or social media\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building a URL Shortener with PHP\" \/>\n<meta property=\"og:description\" content=\"Having your page URL shorter has several benefits. First, it reduce the number of characters which would be handy for sharing on chats or social media\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-06T13:01:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/hostarmada.jpg\" \/>\n<meta name=\"author\" content=\"Thoriq Firdaus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@tfirdaus\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thoriq Firdaus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/\"},\"author\":{\"name\":\"Thoriq Firdaus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\"},\"headline\":\"Building a URL Shortener with PHP\",\"datePublished\":\"2021-09-06T13:01:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/\"},\"wordCount\":1323,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/build-url-shorterner-php\\\/hostarmada.jpg\",\"keywords\":[\"URL Shortening\"],\"articleSection\":[\"Internet\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/\",\"name\":\"How to Build URL Shortener with PHP - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/build-url-shorterner-php\\\/hostarmada.jpg\",\"datePublished\":\"2021-09-06T13:01:03+00:00\",\"description\":\"Having your page URL shorter has several benefits. First, it reduce the number of characters which would be handy for sharing on chats or social media\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/build-url-shorterner-php\\\/hostarmada.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/build-url-shorterner-php\\\/hostarmada.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/build-url-shorterner-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building a URL Shortener with PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\",\"name\":\"Thoriq Firdaus\",\"description\":\"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.\",\"sameAs\":[\"https:\\\/\\\/thoriq.com\",\"https:\\\/\\\/x.com\\\/tfirdaus\"],\"jobTitle\":\"Web Developer\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/thoriq\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Build URL Shortener with PHP - Hongkiat","description":"Having your page URL shorter has several benefits. First, it reduce the number of characters which would be handy for sharing on chats or social media","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/","og_locale":"en_US","og_type":"article","og_title":"Building a URL Shortener with PHP","og_description":"Having your page URL shorter has several benefits. First, it reduce the number of characters which would be handy for sharing on chats or social media","og_url":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2021-09-06T13:01:03+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/hostarmada.jpg","type":"","width":"","height":""}],"author":"Thoriq Firdaus","twitter_card":"summary_large_image","twitter_creator":"@tfirdaus","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Thoriq Firdaus","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/"},"author":{"name":"Thoriq Firdaus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807"},"headline":"Building a URL Shortener with PHP","datePublished":"2021-09-06T13:01:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/"},"wordCount":1323,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/hostarmada.jpg","keywords":["URL Shortening"],"articleSection":["Internet"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/","url":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/","name":"How to Build URL Shortener with PHP - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/hostarmada.jpg","datePublished":"2021-09-06T13:01:03+00:00","description":"Having your page URL shorter has several benefits. First, it reduce the number of characters which would be handy for sharing on chats or social media","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/hostarmada.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/build-url-shorterner-php\/hostarmada.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/build-url-shorterner-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Building a URL Shortener with PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807","name":"Thoriq Firdaus","description":"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.","sameAs":["https:\/\/thoriq.com","https:\/\/x.com\/tfirdaus"],"jobTitle":"Web Developer","url":"https:\/\/www.hongkiat.com\/blog\/author\/thoriq\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-eUC","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/57326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/113"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=57326"}],"version-history":[{"count":1,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/57326\/revisions"}],"predecessor-version":[{"id":57327,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/57326\/revisions\/57327"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=57326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=57326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=57326"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=57326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}