Paytm Payment Gateway Integration in PHP - Example

On 1/22/2018 Be the first to comment!

Hi! In this tutorial, we will see how to integrate paytm payment gateway in php. Mobile wallets have become immensely popular in recent years and paytm is highly trusted among online customers. Many people use it every day for doing online recharges, DTH & other bill payments. It reduces the risk of exposing customer's banking credentials and credit card details to hackers. Therefore, Paytm is a good solution for online payments on your Website and Mobile Apps.

Integrating the paytm gateway in your application is quite easy and below I'll show how to do it with php.

paytm payment gateway integration php

Paytm Payment Gateway PHP Integration:

If your application is based on php, then you don't have to go from scratch. You can quickly integrate paytm into the application using the paytm kit for php. It covers all the basics, you just have to download and use it in the following way.

Step-1) Download Paytm Kit

Download Paytm Payment Kit for PHP and extract its contents. Then move the 'PaytmKit' folder to your working directory.

Step-2) Register for Paytm Sandbox Account

Next, you must register for merchant sandbox account with paytm and collect the necessary details to use with the API. Visit this link and provide your mobile number, email id and password and register an account. You will be provided with merchant id, key etc. Store them in a text file to use it later.

Step-3) Configure the Settings

Now you must configure the payment gateway settings with the data you received in Step-2. Open 'PaytmKit' > 'lib' > 'config_paytm.php' file and update the following details.

define('PAYTM_ENVIRONMENT', 'TEST'); //change this to 'PROD' to use it in production environment
define('PAYTM_MERCHANT_KEY', 'YOUR_MERCHANT_KEY'); //Change this to the merchant key downloaded from the portal
define('PAYTM_MERCHANT_MID', 'YOUR_MERCHANT_ID'); //change this to merchant id received from paytm
define('PAYTM_MERCHANT_WEBSITE', 'WEBSITE_NAME'); //change this to website name received from paytm

Step-4) Create Payment Form

Finally create a payment form to make transactions. Here we need to pass the form action to file 'pgRedirect.php' located inside the 'PaytmKit' folder. This will take care of verifying the checksum and other details and process the payment via the paytm wallet.

<!doctype html>
<html>
<head>
<title>PHP Patym Gateway Integration Demo</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="container">
    <div class="col-xs-6 col-xs-offset-3">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="text-center">Paytm Payment Gateway Demo</h3>
            </div>
            <div class="panel-body">
            <form action="pgRedirect.php" method="post">
                <div class="form-group">
                    <input type="text" class="form-control" id="ORDER_ID" name="ORDER_ID" size="20" maxlength="20" autocomplete="off" tabindex="1" value="<?php echo  "ORDS" . rand(10000,99999999)?>">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" id="CUST_ID" name="CUST_ID" maxlength="12" size="12" autocomplete="off" tabindex="2" value="CUST001">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" id="INDUSTRY_TYPE_ID" name="INDUSTRY_TYPE_ID" maxlength="12" size="12"  autocomplete="off" tabindex="3" value="Retail">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" id="CHANNEL_ID" name="CHANNEL_ID" maxlength="12" size="12" autocomplete="off" tabindex="4" value="WEB">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" id="TXN_AMOUNT" name="TXN_AMOUNT" autocomplete="off" tabindex="5" value="1">
                </div>
                <div class="form-group">
                    <input type="submit" name="submit" value="CheckOut" class="btn btn-success btn-lg">
                </div>
            </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>

This is just a usual php form, but remember to pass all the required parameters as I did. And for designing UI, I have used bootstrap css here, but you can happily skip it if you don't want.

php paytm payment demo

You can refer the official documentation for more details about Paytm gateway API.

Read Also:

That explains about paytm payment gateway integration in php. Using the kit really simplifies the task and allows you quickly add the paytm payment option to your web/mobile applications. I hope you like this tutorial. Please share it on social media if you find it useful.

PHP CodeIgniter Tutorials for Beginners Step By Step: Learn From Scratch

On 1/21/2018 19 Comments so far

Hi, Welcome to our PHP CodeIgniter Tutorial Series. These step by step tutorials are intended for beginners who want to start learning php codeigniter from scratch. It will start right away from setting up the codeigniter framework working environment and move on to more advanced topics covering codeigniter framework libraries, helpers and active record class for database communication. Another nice perk with this series is you will get to know about the popular twitter bootstrap css framework while learning.

Why You Should Learn CodeIgniter Framework?

CodeIgniter Framework is developed by EllisLab and now it is taken by British Columbia Institute of Technology. It is the simplest and light-weight PHP framework which lets you create robust web applications in no time. It is greatly appreciated for its speedy performance and smaller learning curve and suitable for highly scalable applications. And even though php codeigniter framework loosely follows Model-View-Controller pattern it doesn’t force it on you. While controller classes are required for application development, the models and view files are purely optional.

The Model-View-Controller pattern isolates the application logic from the user interface and the database communication.

Twitter Bootstrap CSS is used in this tutorial series for designing the user interface for codeigniter application and there are some dedicated articles covering the usage of bootstrap framework with codeigniter application. But you are encouraged to write down your own style sheets if you prefer.

Using Twitter Bootstrap with CodeIgniter saves the hassle of writing CSS stylesheets of your own and lets you focus on development. Later you can customize bootstrap styles to suit your need. That is the best part of using MVC pattern as the presentation layer (i.e., view) is separate, you can change the look and feel of the app anytime without disturbing the rest of it.

php-codeigniter-tutorials-for-beginners-step-by-step

PHP CodeIgniter Tutorial for Beginners Step By Step

These CodeIgniter Tutorials are compiled in a way so that it starts from basics to advanced level in a sequential order and you can follow them in the same order to start digging into the framework.

How to Install and Setup PHP CodeIgniter Framework in XAMPP (Localhost)

There is only one way to master new technology quickly and it is to get your hands dirty and start to fiddle with examples. So the first and foremost step in the process of learning codeigniter is to setup the working environment. If you don’t have one and want to start from nil then follow this basic codeigniter tutorial. Likewise it will guide you to,

  • Download & Install CodeIgniter Application in XAMPP Server
  • Setup the basic configuration Details
  • Configure Database Connections
  • Accessing codeigniter url structure

PHP CodeIgniter Framework follows special url structure which is quite intriguing for newbies and this beginners tutorial will lay it out clearly for you to understand it better. By the end of this article you will have the codeigniter development environment up and ready. Read Complete Tutorial Here

How to Remove index.php from CodeIgniter URL using htaccess File

So you are up and ready for the challenge? As we already know codeigniter follows MVC (Model-View-Controller) pattern and demands a structured workflow and unique url structure to access the files. In CodeIgniter, any web page be a static or dynamic one needs controller and view files and the model file is required only in case of database communication.

CodeIgniter generates well-optimized search engine friendly URLs like for e.g., ‘http://mydomain.com/pets/dogs/’.

In general its URL structure looks like this,

<base_url>/index.php/<controller_name>/<controller_function_name>

Even though it uses search engine friendly urls, nobody would have missed the awkward presence of ‘index.php’ in between those codeigniter’s urls. Did you wonder how to get clean urls without ‘index.php’ at the middle of them? Yes it’s possible to get rid of it. This codeigniter tutorial will show you an easy trick to rewrite the urls with htaccess file in an efficient way and boom!!! You get clean urls that search engines love. Read Complete Tutorial Here

How to Connect to Multiple Databases in CodeIgniter

CodeIgniter is constantly upgrading to the industry changes and the older versions 2.x included database drivers like mysql, mysqli, pdo, postgre etc by default. But working with MSSQL Database Management system requires you to manually install the drivers but the latest codeigniter v3.0 includes mssql driver too.

Sticking on to the development standards of codeigniter active records library will provide data abstraction which lets you to migrate your codeigniter application easily to some other database management system later.

At times you may want to connect and work with two different databases in a single application and it is not uncommon for a developer. CodeIgniter is flexible and allows you to communicate with multiple databases at a time. Working with multiple databases in codeigniter is simpler and you have to configure the db settings properly and the active records class will take care of the rest. This tutorial will walk you through step by step to connect multiple databases in codeigniter. Read Complete CodeIgniter Tutorial Here

How to integrate Twitter Bootstrap with PHP CodeIgniter Framework

So you love twitter bootstrap framework and you are a web developer who don’t want to reinvent the wheel but to readily jumpstart into work with the help of bootstrap’s built-in css components and plug-ins. What if you want to take advantage of bootstrap’s responsive layout’s and readymade css in your codeigniter application? Wonder how to use twitter bootstrap in codeigniter framework? This codeigniter tutorial gives you the answers. It will you walk through the steps to integrate bootstrap with php codeigniter framework and let you combine the power of two robust frameworks for responsive application development.

Bootstrap’s powerful JavaScript library is built over jQuery and you will need to include jQuery files for it to work. Well! This post teaches you everything about using bootstrap and codeigniter together. Read Complete CodeIgniter Tutorial Here

Note: The above tutorial will deal only with codeigniter and bootstrap integration part but if you want to know how to build codeigniter forms using bootstrap components then read further through this article for advanced topics in the section.

How to Create Login Form in CodeIgniter, MySQL and Twitter Bootstrap

User registration and login system is one of the basic requirements of any membership driven application and as a web developer often you will find yourself building one. This codeigniter tutorial discusses about building a simple login form in codeigniter with username and password fields and verifies the input user credentials against the one stored in the database.

You will also get a basic idea of working with database, using codeigniter session library and building codeigniter forms using bootstrap css. Read Complete Login System Tutorial Here

Easy Image and File Upload in CodeIgniter with Validations

CodeIgniter provides vast number of libraries and helper classes for rapid web development. ‘Upload’ library is one among them that makes the file uploading process in Codeigniter a breeze. If you want to include file uploading functionality in codeigniter, say a way to upload user avatar or a video then never worry.

This codeigniter tutorial will teach you how efficiently you can implement the file uploading functionality and cut down the development time. Additionally it allows users to set the file uploading preferences which lets you take full control of the uploading task. By customizing these settings one can easily define the file uploading path, allowed file extensions for upload (e.g., only images), maximum file size and much more. Read Complete Tutorial Here

How to Send Email in CodeIgniter via SMTP Server

As mentioned above, codeigniter’s built-in helpers and libraries aids robust application development and ‘email’ library is one among them. This little gem of library supports a variety of mail protocols and makes the email sending process lot easier. Moreover you can configure the email preferences like mail protocol, smtp authorization, html or plain text mail etc. These email preferences can be defined either globally or at the time of sending mails (like inside controllers).

This tutorial shows you a simple example to configure codeigniter mail settings and send email with attachments using smtp protocol. It uses the Gmail Server, but you can use any third party smtp servers. Just get the smtp settings from the service provider and use it instead of the Gmail settings given in the post and you are done. Read Complete CodeIgniter Tutorial Here

CodeIgniter Database CRUD Tutorials for Beginners

CRUD is one of the primitive functions of a Database Management System. It’s an acronym for the four fundamental operations Create, Read, Update and Delete performed on databases. In SQL statements, they refer to INSERT (Create), SELECT (Read), UPDATE (Update) and DELETE (Delete) commands. Knowing the Database CRUD procedure is essential in application development particularly when you need to work with databases. These codeigniter tutorials, discusses about implementing basic database CRUD operations in codeigniter and MySQL Database in detail.

CRUD: Insert Data into Database using CodeIgniter

INSERT is the first Database CRUD process and this CodeIgniter Database Tutorial will teach you How to Insert Form Data into MySQL Database using CodeIgniter, Bootstrap CSS framework and jQuery UI. It’ll walk you through step-by-step, creating a form in codeigniter and insert those form data into database. To design the codeigniter form used in this example, we use twitter bootstrap css framework and it’s one of my all time favorite and saves time from creating style sheets of our own. Read Complete Database Insert Tutorial Here

CRUD: Read and Display Database Data in CodeIgniter

READ is the second Database CRUD operation which fetches the data from database. This CodeIgniter Tutorial discusses about implementing Database READ process in codeigniter. It will walk you through steps about reading data from MySQL Database and display it in a neat HTML Tabular format using bootstrap css. Using bootstrap will save you time from creating custom stylesheets for formatting the displayed data. Read Complete Database Read Tutorial Here

CRUD: Update Database Records in CodeIgniter

UPDATE is the third operation in CRUD and this article demonstrates about updating database record from a html form using codeigniter framework. CodeIgniter’s database update query will let you perform update operation on databases. Here the update process is accomplished by populating the details of a specific database record in form fields and updated to DB when the user edits the details and submits the form. Read Complete Database Update Tutorial Here

CRUD: Delete Database Records in CodeIgniter

DELETE is the last database operation in CRUD and it is used to delete record(s) from database. To implement this delete process in codeigniter you should use its active record delete query which allows deleting one to more records from database table easily. Well! This codeigniter tutorial will teach you everything about implementing the delete process. Read Complete Database Delete Tutorial Here

How to Create CodeIgniter Pagination with Twitter Bootstrap Styles

Pagination refers to the set of numbered links that allows you to navigate from page to page to view a large set of data. For example let’s say you want to fetch and display set of data from database and it contains several hundreds of records. In that case pagination will be very useful to display the database result set in chunks and let the user to skim through the page links which is similar to Google search results.

And this tutorial will teach you about incorporating pagination links using codeigniter’s ‘pagination’ library. However these codeigniter pagination links are pretty plain in nature but we can easily spice them up to decent looking using twitter bootstrap styles. Read Complete CodeIgniter Pagination Tutorial Here

CodeIgniter Contact Form Tutorial with Email Sending Option

Contact forms are an essential component of modern day websites and they provide a way of communication between the site users and the website owner. Incorporating a contact form is relatively easy and this codeigniter tutorial will show you about building a simple and effective contact form with codeigniter, validate the user input and send email using the smtp server. We will build a contact form to collect name, email id, subject and message from the user and send it to the website owner’s email address. Read Complete Contact Form Tutorial Here

Over To You

I hope this codeigniter tutorial for beginners has laid out some strong foundation for absolute newbies to learn from zero. I do intend to update this article regularly whenever I add up some new tutorials about codeigniter. So keep visiting :)

Further Reference: CodeIgniter Manual

Best Kali Linux Compatible Wireless Adapters/Dongles 2018

On 1/21/2018 1 Comment so far

Here are the best kali linux compatible wireless adapters and usb dongles for 2018. Kali Linux is a Linux distribution mainly used for Penetration Testing, accessing N/W Security & Ethical Hacking. The process of choosing a wireless adapter or usb dongle to work with Kali Linux is not an easy task. It's just because the Operating system doesn't support all kinds of wifi adapters.

For example Pentesting requires a card to go into monitor mode and do packet injection which all cards can't do it. The Card's chipset and drivers is what determines if an adapter is compatible with kali or not.

Below I have listed out the most popular chipsets for Kali linux and Wireless adapters compatible with them. They work well for Penetration testing too.

Popular Kali Linux Compatible Chipsets:

  • Atheros AR9271
  • Ralink RT3070
  • Ralink RT3572

Best Kali Linux Compatible Wireless Adapters:

1. Alfa AWUS036NHA (Atheros AR9271 Chipset Compatible)

Check Price @ Amazon

Alfa-AWUS036NHA

Alfa AWUS036NHA is a best wifi adapter for pentesting. For penetration testing, Atheros AR9271 is a good chipset and you can go for Alfa AWUS036NHA card if you plan to run Kali as VM. Just get the job done without hassle.

  • Compatible with any 802.11b, 802.11g or 802.11n routers using 2.4Ghz band
  • Supports multiple input multiple output
  • High speed transfer TX data rate of up to 150 mbps
  • Includes 4" detachable antenna of 5 dbi which can be upgraded up to 9 dbi.
  • Works with 64/128-bit wep, wpa, wpa2, tkip, aes security protocols.
  • Supports Windows 2000, XP 32/64, vista 32/64 & Windows 7 Platform. So compatible with Kali Linux running as VM on these hosts.

Get It Now From Amazon »

2. TP-Link TL-WN722N (AR9271 Chipset Compatible)

Check Price @ Amazon

best wifi card for kali linux

Another great USB Desktop Wireless Adapter for cheapest price. TP-Link TL-WN722N uses AR9271 Chipset and has great range of up to 150Mbps. The card is easy to set up and works perfectly with Kali Linux.

  • Supports Wireless speed of up to 150Mbps
  • Works both on Infrastructure and Ad-Hoc Mode
  • Includes a detachable 4dbi omni directional antenna
  • Supports WPS & USB 2.0
  • Compatible with Windows XP, Windows Vista, Windows 7, 8, 8.1 platforms

Get It Now From Amazon »

3. Alfa AWUSO36NH (RT3070 Chipset Compatible)

Check Price @ Amazon

best alfa wifi adapter for kali

One of the best wireless dongle for pentesting. This 2 Watt 802.11n compatible Wi-fi dongle is quite powerful and supports Ralink RT3070 Chipset. It has very good range and perfect for packet monitoring.

  • Compatible with any 2.4GHz routers of 802.11n, 802.11b/g/n wireless standards
  • Includes removable 4" - 5 dBi antenna and can be be upgraded up to 9dBi
  • Supports 64/128-bit WEP, WPA, WPA2, TKIP, AES Protocols
  • Compatible with Windows 2000, XP 32/64, Vista 32/64, Windows 7, Linux (2.4.x/2.6.x),and Mac (10.4.x/10.5.x)

Get It Now From Amazon »

4. Alfa AWUS036NEH (RT3070 Chipset)

Check Price @ Amazon

Alfa-AWUS036NEH

This Wi-Fi Dongle is similar to Alfa AWUSO36NH in specs and covers long range. Alfa AWUS036NEH is exceptional for penetration testing and is good at packet injection and monitoring.

  • Works well with any 802.11b/g and 'N' routers
  • Includes removable 4" 5dBi antenna (upgradable up to 9dBi)
  • Supports packet injection & monitor mode
  • Protocols supported - 64/128-bit WEP, WPA, WPA2, TKIP, AES
  • Compatible with Windows 2000, 32/64 bit XP, Vista, Windows 7, Linux (2.4.x/2.6.x), Mac (10.4.x/10.5.x) Power PC& PC.

Get It Now From Amazon »

5. Panda PAU05 (RT3070 Chipset)

Check Price @ Amazon

Panda-PAU05

Panda 300mbps wireless n usb adapter is very reasonably priced and works with 802.11g/n standard and offers a data speed of up to 300 Mbps. It is exceptionally good considering the price but make sure to download and install the latest driver (alone) for Windows 7 and leave the rest of the setup to Windows itself.

  • Compatible with any 802.11g or 802.11n 2.4Ghz wireless routers
  • Wireless speed of up to 300Mbps
  • Works with both infrastructure and ad-hoc modes
  • Security protocol compliant: 64/128bit WEP, WPA, WPA2, 802.1x and 802.11i, Cisco CCS V1.0, 2.0 and 3.0
  • Supports 32/64-bit Windows 8/7/Vista, Mac OS 10.4/10.5/10.6/10.7/10.8/10.9 and latest version of 32/64-bit Mint, Ubuntu, Fedora, openSUSE, etc.

Get It Now From Amazon »

6. Alfa AWUS051NH (Ralink RT3572 Chipset)

Check Price @ Amazon

Alfa-AWUS051NH

Alfa AWUS051NH is little expensive but has amazing signal reception and works well on Kali Linux and in 5Ghz Monitor mode.

  • It is compatible with 802.11n draft 3.0, 802.11a/b/g wireless standards
  • Work with 2.4GHz and 5.8GHz band and MIMO (Multiple Input Multiple Output)
  • Supports wireless transfer RX data rate of up to to 300 Mbps
  • Allows wireless data encryption with 64/128-bit WEP, WPA, WPA2, TKIP, AES Protocols
  • Compatible with Windows 2000, 32/64 bit XP & Vista, Linux (2.4.x/2.6.x), Mac (10.4.x/10.5.x) Power PC& PC.

Get It Now From Amazon »

What Makes a Wireless Adapter Compatible with Kali?

Kali is a popular Linux Distro commonly used by security and penetrating testing professionals. Not all wireless adapters are made to work with Kali Linux. Only the drivers and chipsets decides if they are compatibile with the OS or not.

In addition, if you run it as a VM, the USB adapter must also be compatible with the host operating system.

Any of the above recommended devices will be good for pentesting, but you are called to decide which one is right for your configuration.

Long-range adapters with big dBi antenna are great for distance but not exactly compact. On the other hand smaller ones with built-in antenna are good for staying low profile.

Over To You:

So these are the best wireless adapters and usb dongles for kali linux. Though all these adapters works well with Kali, just make sure if it is the right one for your environment. For example if you wish to run Kali on Virtual box in Windows 7 host then make sure the card is compatible with Windows 7 OS. Also you must be cautious about the coverage range. Antenna with bigger dBi would be better for longer range. This helps you avoid future trouble. If you find this useful please share it with others to give them good suggestion.

Also Read:

CodeIgniter | Remove index.php from URL using htaccess

On 1/21/2018 28 Comments so far

Hi, we’ll see how to remove index.php from url in codeigniter. Even though codeigniter uses search engine friendly urls, nobody would have missed the awkward presence of 'index.php' in between those codeigniter's urls. Have you ever wondered how to get rid of it to get more clean urls in your codeigniter application? Say your app has an url something like http://www.example.com/index.php/contact and you want it to look like http://www.example.com/contact. Yes, you can do it. In codeigniter removing index.php from url should be done by rewriting urls in htaccess file.

How to Remove index.php from URL in CodeIgniter using .htaccess?

Recommended Read: How to Create Login Form in CodeIgniter, MySQL and Twitter Bootstrap

Recommended Read: CodeIgniter/MySQL Tutorial - Read and Display data with Twitter Bootstrap

Step 1: Enable Mod Rewrite Option in your APACHE Server

To rewrite urls in the htaccess file, the mod_rewrite option should be enabled in the apache server. Goto apache's "httpd.conf" file and search for the line,

LoadModule rewrite_module modules/mod_rewrite.so

If the above line is preceded with # (in which case, the module is disabled), then remove the # (hash) symbol to enable url rewriting.

Step 2: Create '.htaccess' File

Next create the .htaccess file at the root directory. To create the htaccess file, open your favourite text editor and create a new text file. Save it as ".htaccess" (make sure you type the filename within quotes to avoid the file to be saved as text file) in the root directory.

htaccess file codeigniter

Now copy paste this code to the htaccess file and save it.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

If you run your codeigniter app as a subdirectory instead of root domain like, http://example.com/cisite/ instead of http://example.com/ then the above code won't work. You have to tweak it little to tell that your site runs as a subdirectory. Add this code to the htaccess file instead of the above one.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Step 3: Modify CodeIgniter Config Settings

Open config.php file under application >> config folder and search for the line,

$config['index_page'] = 'index.php';

Remove index.php from it to look like this,

$config['index_page'] = '';

Now restart apache and check the url. eg., http://www.example.com/contact instead of http://www.example.com/index.php/contact

Recommended Read: How to Upload Files in PHP Securely

Recommended Read: How to Insert JSON into MySQL using PHP

If it doesn't work, you may be having problem with uri protocol. In that case find $config['uri_protocol'] ='AUTO' setting in config file and replace with $config['uri_protocol'] = 'REQUEST_URI'.

Restart apache server again and you can check the codeigniter site to see that index.php has been removed from codeigniter url.

Best Wireless Adapters for Desktops/Laptops in 2018 - Buying Guide

On 1/20/2018 Be the first to comment!

Slow Internet connection sucks! Even when you have reliable ISP, good modem, router and everything, a bad wireless adapter will spoil the party. No one wants to compromise the Internet speed and connectivity in the middle of work or gaming. A good quality wifi adapter will drastically improve the INTERNET performance and give you peace of mind. Moreover, if Wi-Fi network is shared among household members, then a Best Desktop Wireless Adapter goes a long way providing fast and secure internet connection.

best usb wireless adapters 2017 reviews

If you are looking to buy a USB Wireless Adapter then make sure the adapter easily talks to the router and works best for desktop PC, laptop and tablet. Knowing a few things about Wi-Fi will help you pick the right wireless adapter for your needs.

What Is A USB Wireless Adapter & How Does It Work?

A USB wireless adapter is a small device that quickly sets up wireless connectivity to your desktop or laptop via the router. It is plugged into the USB port of the computer and adds up Wi-Fi ability to non Wi-Fi computer.

The Wireless Adapters are also called as Wi-Fi dongles and come in all shape and size. Also they vary in the types of protocol they use for transferring wireless signals.

These days Desktops and Laptops come with built-in Wi-Fi cards but it's not the case with older computers. On the other hand, you might want to upgrade your laptop's wifi or fix a broken wireless card. In either case, a good external USB wireless adapter will make your computer wifi ready.

Top 10 USB Wireless Adapters in 2017 Reviews

1. NETGEAR AC1200 WiFi USB Adapter (A6210)

netgear ac1200

Netgear AC1200 USB WiFi Adapter is a high-end dongle with excellent wifi performance. The adapter works on dual band supporting 2.4GHz and 5Ghz wireless setup.

It works with USB 3.0 and delivers high data rates with the latest 802.11ac protocol. And the high-gain antennas give good distance coverage. No bigger than a flash drive the adapter is compact-looking and snugly fits into the computer's USB without blocking adjacent ports. It comes with NETGEAR genie for easy installation and supports all Windows OS versions. There is also a desktop dock for flexible placement of the adapter.

  • 802.11ac High Gain USB 3.0 Dual Band adapter
  • Works with 802.11a/b/g/n and ac devices
  • USB 3.0 interface and compatible with USB 2.0
  • High-gain antennas + Desktop Dock
  • Beam forming+ technology
  • Compatible with Windows Operating System

Check Price on Amazon


2. ASUS USB-AC68 Dual-Band AC1900 with Included Cradle

asus usb-ac68

If you are looking for a high-speed wireless adapter then ASUS USB-AC68 dual-band dongle is your best option. It uses the newest technology chipset Realtek RTL8814AU and the fastest wifi dongle in the market.

It comes with two foldable external antennas to cover large distance and it does. There is also an USB cradle which you can extend when required.

The dual band dongle has max speed of up to 1900 Mbps which is split among 2.4 GHz and 5 GHz range. 600Mbps transfer rate at 2.4GHz and 1300Mbps at 5GHz frequency.

This USB Wifi adapter has impressive speed and wireless connectivity. But note that this is not a budget device. If you have specific need for fastest wifi then go for ASUS USB-AC68 without second thought. There's no support Linux OS so if you look for one to use in Linux go for other recommendations in this list.

  • 802.11ac Dual band USB Adapter
  • Robust 3x4 MIMO Antenna design
  • Dual 3-position foldable external antennas
  • Up to 600 Mbps speed on 2.4GHz band, 1300 Mbps on 5GHz band
  • ASUS AiRadar beamforming
  • Includes USB 3.0 cradle

Check Price on Amazon


3. TP-LINK AC600 (Archer T2UH)

tp-link ac600

TP-Link Archer T2UH USB Wireless Adapter is an entry-level 802.11ac adapter suitable for regular day-to-day use. The adapter works on dual band so it will pick up signals on both 2.4GHz and 5GHz frequency.

The dongle's speed and wireless connectivity is good for personal use. It comes with external antenna which you can twist and tweak to gain better wifi signals. Also there is a 3-foot usb cable that let you place the adapter near the router for maximum throughput.

TP-Link Archer T2UH USB Adapter utilizes USB 2.0 and has speed cap at 480Mbps which is the only downside to it. Even then this rate is not at all less for home.

It supports Windows and Mac machines and overall a decent adapter from a reputable brand.

  • High-gain external antenna for long distance
  • WiFi speed up to 600Mbps with simultaneous 5GHz and 2.4GHz bands
  • WPS button for secured encryption
  • Includes 3 Feet USB cable for adapter placement
  • Compatible with Windows 8.1, 8, 7, XP, Linux, Mac OS X 10.7-10.10

Check Price on Amazon


4. BrosTrend AC1200 WiFi Adapter Dual Band

brostrend ac1200

BrosTrend AC1200 USB Wi-Fi Adapter is an 802.11AC Dual Band dongle that works on both 2.4GHz and 5GHz frequency range. It supports USB 3.0 and works at a data rate of 867 Mbps at 5GHz and 300 Mbps at 2.4GHz band.

Being just three inches long, the adapter is extremely portable has cap for storage. It snugly fits to the desktop or laptop without taking up much space.

The device is plug and play and is compatible with Windows 10 OS and it's earlier versions.

In general, BrosTrend AC1200 is a great fit for all networks and the protocol 802.11ac is backward compatible. In addition, although designed to work with USB 3.0, it is compatible with USB 2.0 and 1.0.

  • Wireless 802.11ac Dual band (2.4/5GHz)
  • Easy plug-and-play setup
  • 8812AU Chipset
  • Slim and Portable
  • USB 3.0, backward compatible with USB 2.0/1.0
  • Supports Windows 10, 8, 7, XP & MAC 10.6 to 10.10

Check Price on Amazon


5. Alfa Long-Range Dual Band AC1200 Wireless Adapter

alfa long range dual band adapter

The Alfa AC1200 is a dual band long-range adapter with support for the latest 802.11ac protocol. It has very good antennas for long distance coverage and there is no problem working on the 5GHz frequency.

This dongle is not exactly portable, but it has good wifi connectivity and speed even at distance. It's a USB 3.0 adapter and achieves excellent data transfer rates at 5GHz range. Unless you do not have USB 3.0 port on your computer there will be no bottleneck in speed.

So if you need a USB adapter that works long distance and supports the new 5GHz band, Alfa AC1200 is the best option.

  • Supports 802.11ac / 802.11N / 802.11a/b/g Wifi Standards
  • High-speed data: 300Mbps on Wireless-N, 867Mbps on Wireless-AC
  • Operates on Dual band (2.4GHz / 5GHz)
  • 2 Removable 5dBi rubber duck external antennas
  • Supports WEP 64-Bit, WEP 128-Bit, WPA-PSK & WPA2-PSK
  • Windows 10, 8.1, 8, 7, Vista, XP, Mac & Linux compatible

Check Price on Amazon


6. Panda Wireless PAU06 300Mbps N USB Adapter

panda pau06

Panda's Wireless-N Network Adapter is a low-cost solution for upgrading your desktop / laptop wifi. It operates on the 2.4GHz network and has a maximum speed of up to 300Mbps.

It is an 802.11n dongle so speed is optimum but has wide range and works well from long distance. There is also a screw in antenna at the back of the device for good range.

The adapter is backward compatible with 802.11g 2.4GHz network and does not work on 5GHz band. It supports Windows (XP, Vista, 7, 8, 8.1 and 10), MAC and Linux OS.

  • Operates on 802.11n and 802.11g 2.4GHz wireless networks
  • WPS button wireless setup
  • Maximum speed up to 300 Mbps
  • Low power consumption in laptop/portable devices
  • 64b/128bit WEP, WPA and WPA2 (TKIP+AES)
  • Compatible with 32/64 bit Windows XP, Vista, 7, 8, 8.1, 10, Mac OS Mint, Ubuntu, openSUSE, etc.

Check Price on Amazon


7. NET-DYN Mini USB WiFi Adapter

net-dyn mini adapter

NET-DYN USB WiFi Adapter is a fast, easy and inexpensive solution for adding wireless connectivity to your PC or fixing your laptop's broken Wi-Fi. The mini adapter comes with internal antennas and remains low profile connected to the computer's USB. And the good thing is that it does not block the nearby ports so you can connect it directly to the computer without the need for an extension cable.

It is a Wireless-N USB 2.0 adapter so the speed is good enough for personal use. The dongle operates in the 2.4GHz range and has maximum data rate of up to 300Mbps.

Overall it's a cheap and reliable USB Wifi adapter and works great on Windows 10 and Mac and earlier versions of Windows like Windows 8.1, 8, 7, Vista and XP.

  • 802.11n / b / g Wi-Fi adapter and works in 2.4 Frequency range
  • Compatible with Windows 10, 8.1, 8, 7, Vista, XP, 2000 and Mac 10.9 and 10.10
  • Compatible with all WLAN routers (WPA / WPA2 / WEP)
  • Built-in omni directional internal antenna
  • Supports USB 2.0 and old 1.1

Check Price on Amazon


8. Dodocool AC600 Dual Band WiFi Adapter

dodocool ac600

Dodocool is another very low cost dual band 802.11ac adapter. Since it is a dual-band dongle it fits on any network.

Although it supports the newest 802.11ac wifi protocol, it is backward compatible with older wireless networks such as Wireless-n/g networks.

The device is small in size and fits easily on to the laptops USB port without getting in your way. As for setup, it works well with Windows 10 plug-and-play - and also compatible with previous versions like Windows 8.1, 8, 7 etc.

Since Dodocool AC600 is a mini adapter it lacks big antennas that come with large wifi adapters. So that limits the adapter to short range.

Overall the USB wireless adapter is easy to setup wifi to your computer and get the job done on budget.

  • 802.11ac Compatible Dual Band AC 600 Adapter
  • Support for both 2.4GHz and 5GHz bands
  • Up to 433 Mbps speed at 5GHz & 150 Mbps at 2.4GHz
  • Plug and play easy wifi setup
  • Works with 802.11 ac/a/b/g/n routers
  • Compatible with Windows XP, Vista, 7, 8, 8.1, 10, Mac OS X

Check Price on Amazon


9. OURLiNK 1200Mbps USB 3.0 Mini 802.11ac Adapter

ourlink 1200mbps

OURLiNK 802.11ac adapter from Glam Hobby is a very small and low-cost dongle that works on 2.4GHz and 5Gz wireless networks. It has a simple and easy configuration and connects your Windows 10 machine to wifi in a matter of seconds.
It is a USB 3.0 adapter and easily reaches 100Mbps speed which is great for such a small device. It also supports Mac OS and earlier Windows versions like XP, Vista, 7, 8 and 8.1.

The USB adapter's connection is impressive and covers a good range from 25 to 30 feet away. Overall, it is ideal for online gaming and no-buffer HD streaming.

  • 802.11ac 1200 Mbps Wireless Dual-band adapter
  • Speed up to 867Mbps on 5GHz + 300Mbps on 2.4GHz N/w
  • Superspeed USB 3.0 Port Interface
  • Innovative compact body design
  • Compatible with Windows 10, 8.1, 8, 7, XP and Mac OS

Check Price on Amazon


10. TP-Link Archer T1U Wireless Nano USB Adapter (AC450)

tp link archer t1u

The TP-LINK Archer T1U is another good entry-level Wifi USB adapter and works with the 802.11ac standard.

The adapter is small and discreet so that you can connect it to the PC and leave it there. It only works on the newer 5 GHz range and there's no support for the old 2.4 GHz. So if distance is a problem, go for any of the dual-band adapters that are given in this list.

As for compatibility, Archer T1U works with most of the operating system, including windows 10. In addition the dongle uses USB 2.0 so speed would be optimal and good for home/personal use only.

  • Supports 802.11ac/a/n wireless standard
  • Works only on the new 5GHz band
  • Up to 433 Mbps data transfer rates
  • Encryption standards: WEP, WPA/WPA2, and WPA-PSK/WPA2-PSK
  • Compatible with Windows (XP, Vista, 7, 8, 8.1, 10), Linux & Mac OS X

Check Price on Amazon


USB Extension Cord

While some of the USB Wifi adapters are small and discreet, most of the powerful dongles will be slightly bigger and can block the adjacent ports of your computer. Plus you may also need to position the adapters in the direction of router for better signal. There is a simple fix for this problem. Using an USB extension cord will help you keep wireless adapters far away from the computer/laptop and in the direction of router. And the near by ports will not be blocked.


Best USB Wireless Adapters for Gaming

1. TP-Link AC1200 Wireless Dual Band USB Adapter (Archer T4U V1)

tp-link ac1200

TP-Link is a reliable brand among wireless equipments. The Archer T4U V1 is an 802.11ac dual band adapter and supports any type of network.

The dongle offers ultrafast wireless speeds up to 1200 Mbps combining both 2.4GHz and 5GHz frequencies. It gives data rates of up to 867Mbps at 5GHz and 300Mbps at 2.4GHz bands.

The USB adapter works on USB 3.0 and supports SoftAP so you can use it as a Wi-Fi hotspot and share the Internet connection of your PC among other devices. If you live in a crowded city then it is recommended to use 5GHz to enjoy enhanced online gaming.

Another good thing is it comes with 1 meter USB extension cable so the nearby ports will not be blocked when connected to the computer or laptop.

  • Delivers ultra-fast 1200 Mbps speed With 802.11ac standard
  • Dual band adapter works on both 2.4 / 5 GHz bands
  • WPS Button for quick setup of wireless connection
  • 1 meter USB 3.0 Extension Cable
  • USB 3.0 support

Check Price on Amazon


2. Alfa AC1200 Long-Range Wi-Fi Adapter

alfa ac1200

Alfa USB Wifi adapter is one of the best long-range dongle in the market and supports the latest 802.11ac protocol. The adapter is backward compatible and works on older wireless protocols such as 802.11n/g/b/a.

It is not a small device but has excellent range. There are two 5dBi removable antennas for distance and has the data transfer speed of up to 867 Mbps on 5GHz frequency.

The adapter is dual-band and works on both 2.4GHz and 5GHz band. It supports all Operating systems such as Windows (10/8/7/Vista/XP), Mac & Linux.

If you need a high-speed wifi adapter that works from distance for online gaming then Alfa AC1200 is your best choice.

  • Dual-Band 2.4GHz/5GHz USB Wireless Adapter
  • Delivers speed up to 300Mbps on Wireless-N & 867 Mbps on Wireless-AC
  • Supports Wi-Fi Standards 802.11ac, 802.11n, 802.11a, 802.11b
  • Two 5 dBi removable antennas for good distance
  • Compatible with Windows XP, Vista, 7, 8, 8.1, Mac & Linux

Check Price on Amazon


3. Linksys WUSB6300 AC1200 Wireless Adapter

linksys wusb6300

The Linksys WUSB6300 USB wireless adapter works on dual band and supports the latest standard Wireless AC. It is ideal for connecting PC or laptop to high-speed 802.11ac networks.

It is a Wireless-AC dongle but also backward compatible with the Wireless-N standard. It works on USB 3.0 for fast performance and offers 867 Mbps speed in 5GHz band and a speed of 300 Mbps in 2.4GHz band combining a total theoretical speed of 1200 Mbps. You can enjoy lag-free online gaming via 5GHz network.

For secured wifi it supports 128 bit WEP, WPA and WPA2 encryption. The adapter is compatible with Windows 10 OS and earlier versions like 8.1, 8, 7, Vista and XP.

  • Dual band 802.11ac Wireless AC adapter
  • Speed up to 867Mbps on Wireless-AC & 300 Mbps on Wireless-N
  • 128-bit encryption support (WEP, WPA and WPA2)
  • Compatible with all 802.11ac devices
  • Supports MS Windows 10, 8.1, 8, 7, Vista SP1/SP2 and XP SP3
  • USB 3.0 support

Check Price on Amazon


How to Choose the Best Wireless Network Adapter - Buying Guide

Tech savvy or not, knowing few things about Wi-fi and Adapters will help you choose the right adapter that works best in your network system. So let's see some of the important features you must consider before buying a USB Wireless Adapter.

1. What are Wireless Protocols?

802.11 is the number representing the Wireless protocols. It is the universal standard set for wireless products so that they can communicate with each other without trouble.

The current Wi-Fi standard is 802.11ac and introduced in 2013. It works only on 5 GHZ band but can transfer data much faster than wireless N.

But most devices in today's market use the previous 802.11n (or) Wireless-N protocol. This is the widely used wifi standard and works on both 2.4 GHz and 5 GHz band.

Dual Band: Adapters that works on both 2.4GHz and 5GHz frequency ranges are known as dual-band wireless adapters.

To simply put the newer 802.11ac wireless adapters have better speed over Wireless N device. So can you buy the 802.11ac dongle?

Well! It depends.

The fact is 802.11ac is fast but has less coverage. Remember it only works on 5 GHz range? The higher frequency does not travel as far as the lower 2.4 GHz frequency.

So if there is not much distance between adapter and router then the best option would be an 802.11ac dongle. Else go for the dual band Wireless-N dongle which is good for long distance range.

2. Wireless Frequencies

There is two type of frequencies used for wireless transmission. One is 2.4 GHz and the other one is 5 GHz range. Up until 2013, only 2.4 GHz band was used. But later due to overcrowding of wireless networks they have introduced the higher 5 GHz band.

The higher the frequency the less the signal can travel through barriers. So a 2.4GHz dongle will transmit data farther than the new 5GHz dongles.

Numerous networks still use 2.4GHz band and collide with other wireless devices fighting to get a signal through. And the fact that it travels a greater distance and penetrates through walls makes the situation even worse.

Hence the introduction of the 5GHz band. It travels less distance and has mighty speed. The network is also less crowded so there is a little chance for the collision with other N/w s.

3. Distance

Antennas play a larger role when it comes to distance. Some USB wireless adapters come with the built-in antenna which is good for staying low profile. But these internal antennas will not transmit signal as far as large external antennas.

On the other hand adapters with external antennas cover long distance well and carry wireless signal better than the built-in one. They come with a screw-in antenna which can be easily replaced with large dBi antenna as per distance requirement.

Generally, antenna size is measured in dBi. As a general rule of thumb, the larger the dBi the higher the coverage. But keep in mind having an adapter with large dBi antenna will not guarantee better signal at long distance - as external factors like barriers, adapter wattage will affect the signal quality.

4. Speed

Speed matters in a wireless connection... A LOT!

Till date, the Wireless-AC adapters (802.11ac) have the fastest data transfer speed of up to 1.3Gbps. The second best is the Wireless-N adapters (802.11n) with a speed of up to 300 Mbps which indeed is not at all slow for personal use.

But 802.11ac will only work in 5GHz range so if you prefer distance over speed then stick to the old 802.11n which works on 2.4GHz band.

Just keep in mind.

2.4 GHz band travel far but has less speed (relative).

5 GHz band travel less but with greater speed.

Certain dual band adapters are capable of using both 2.4GHz and 5GHz bands for maximum speed and said to have 1200Mbps transfer rate. Note that it's just a theoretical estimation and hard to be achieved in real-life. Wireless speed is always relative to the environment you live in.

5. Easy to Use

Wireless adapters are easy to setup and use it. With PCI adapters you have to go through installation process via setup CD and all. But that's not the case with USB Wifi adapters. Most of the USB Adapters are the plug-and-play type. All you have to do is to connect them to a free USB Port of your computer and the system will automatically detect the device and run set up for the first time. Once the driver is installed you are good to go from there.

6. Compatibility

The wireless adapter must be compatible with the router to send and receive data. Dual band routers will work with any adapter. But an old router will only work on 2.4 GHz range. So make sure the adapter also works in the similar range.

In case you are not sure about the router being used, just get a Dual Band Wireless N adapter. It will work with any router.

Besides your Desktop/Laptop Operating system is also important. A Wi-Fi adapter must be compatible with the computer OS in order to work. So make sure your adapter works on a particular OS and also have updated drivers required for it.

So if you buy a wireless adapter to work on Windows 10 machine, it must be compliant with Windows 10 OS. The fact it works on Windows 7 or 8 doesn't mean it will also work on Win 10 version.

7. USB 2.0 Vs USB 3.0

USB 3.0 is mandatory for 802.11ac adapters. This is because their peak data rate exceeds the USB 2.0 speed on 2.4GHz band.

USB 2.0 can transfer data at 480Mbps, the new USB 3.0 at 5Gbps speed. This is only theoretical, but real world's performance is always lower than this.


PCI Based or USB Wi-Fi Adapter? Which One to Choose?

Before starting your hunt for wireless adapters, you must first know that there are two types of wireless adapters commonly used these days. Let's see what they are.

USB Wireless Adapter

The first type of wireless adapter is USB based. USB Wifi adapters are the simplest to install and use among the two types. It's because of their plug and play nature. They work like a flash drive in this context.

You have to simply plug it into a USB Port, and then the computer will automatically detect, run setup and install the necessary drivers. After that, you can connect it to any available Wi-Fi network and you are good to go from there. The installation process takes place only for the first time you use it on a PC or Laptop.

Well! The wifi adapter is external and requires one free USB Port. In some cases, the devices are bigger and might as well block nearby ports. Plus you may need it to be out of the way of other computer cables.

In fact, it's good to use an USB extension cable to connect USB Wireless adapters. They will be out of your way and can be kept farther from PC to pick up wifi signals better.

PCI Based Wireless Adapter

PCI stands for Peripheral Component Interconnect and wireless adapters of these types should be plugged into the PCI slot of the computer's motherboard. These devices are bigger than the USB network adapters and come with powerful antennas sticking out at the back of the adapters.

PCI wifi adapters generally crowd over the area they are attached to. Plus somewhat harder to setup and use for an average user. Nonetheless, they are excellent in terms of wireless transmission and long distance coverage.

But overall I would happily choose anytime a USB wireless adapter over PCI ones just because of their simplicity and ease of use.


Advantages of Using USB Wireless Adapters

A USB wireless adapter is the easiest solution to put a device online. It's cheap, effective and has several advantages over using wired connection.

  • Free of Cords - The first and foremost benefit of using the wireless adapter is it eliminates the necessity of computer cables. Your computer desk will no more be a clutter of cords. You get to have true mobility if you work with laptop or tablet. When you have wifi, you don't have sit at your work table. You are free to take your work to couch or bed. Plus USB wireless adapters stay low profile and most of them look no bigger than a flash drive.
  • No Hardware Installation - There are several ways to set up wifi on your computer. Of all the choices USB wireless adapters is the popular choice for most users. It's because they are simple external devices. You have to simply plug them into a USB port, install drivers and connect to wifi network. That's all to the total set up. And the plug-and-play feature is even better.
  • But PCI based adapters have complicated setup. In some cases, you have to open up the computer or laptop case and fix wifi card to motherboard slot. Not a favorable choice at all.
  • Easy Replacement - Does your desktop doesn't have a built-in wifi card? Or you laptop wifi is broken? Then don't worry. You don't have to upgrade your entire computer which is quite costly. Get a USB wireless adapter compatible with your system OS. That'll do. It is the simplest solution to enable wifi on a computer. USB wifi adapters are very cheap and you can replace it at any time if the need arises.
  • Multi-Device Support - One of the key benefit of usb wireless adapter is it can be shared among multiple devices. Since it's an external device mounting and un-mounting is quite easy. So you can use the very same usb adapter on your laptop, desktop, tablet etc. The device is small so you can carry it anywhere you go and use it at your convenience.

FAQ on USB Wireless Adapters

I'm not sure about the Network used? Which Wi-Fi Adapter is right for me?

It's easier to get confused with all those wireless protocol numbers, operational frequency etc. If your network operates on 2.4GHz frequency then there's no point in buying a wireless adapter that only works on 5GHz band.

So in case you are not sure about the wireless network being used, then get a dual-band usb wifi dongle. They will work on most of the networks since they operate on both 2.4GHz and 5GHz band.

How can I know if an USB Wireless Adapter works on my Computer?

A wireless adapter needs to have driver software for the Operating system being used. So if you have Windows 10 PC, the wireless adapter you get to work with the machine must be Windows 10 compliant.

I live in City? Which Adapter should I buy?

802.11ac protocol only works in the new 5GHz band and doesn't travel far. So the network will be confined to a small area.

On the other hand, the older Wireless N works on 2.4GHz band and is widely used by many and travel far than 5GHz range. So there is a greater possibility for network collision in a crowded city which pulls down the wifi speed.

If you live in a city with crowded neighborhood your best choice would be a 5GHz Wifi adapter. If you live outside of the city limit with few neighbors then go for 2.4 GHz adapter which gives you greater coverage.

Can I use USB Wireless Adapter as Wi-Fi Hotspot?

Using USB wireless adapters as Wi-Fi Hotspot let you share the PC's internet connection with multiple devices like smartphone, tablet etc.

If your computer runs Windows 10 here's a way to do it.

Open Windows Settings > Network & Internet and choose 'Mobile HotSpot' and complete the setup wizard. You might as well need to tweak security settings to grant permission for this.


Over to You

USB Wireless Adapters are inexpensive and convenient solution to connect desktop computers to wifi networks. But then the market is crowded with so many brands claiming their adapters are the best among all. And it's also a tough task to narrow down to an adapter that works best for your desktop pc. Just remember, the Wi-Fi USB adapter must be compatible with your network and has drivers for the OS you use. The new 5GHz adapter will have high-speed but has short range. If you are not sure about the network and all, get a dual-band adapter. It will work with any network old or new.

Recommended Read For You: Best Kali Linux Wi-Fi Adapters

PHP CodeIgniter Pagination with Twitter Bootstrap Styles - Example

On 1/20/2018 24 Comments so far

PHP Codeigniter framework provides a good number of libraries required for building a website with codeigniter and pagination library is one among them. For those who are not familiar with the term pagination, this refers to the set of numbered links that allows you to navigate from page to page to view a large set of data. For example let's say you want to fetch and display some data from database and it contains several hundreds of records. In that case pagination will be very useful to display the database resultset in chunks and let the user to skim through several page links (similar to google search results).

However the pagination links in codeigniter are plain looking in nature and a little customization to codeigniter pagination doesn't hurt. Here we'll see in this tutorial, how to style codeigniter pagination links with twitter bootstrap styles.

Implement Twitter Bootstrap Styles in CodeIgniter Pagination

We'll see an example below to fetch and display the list of department names and their department head in a neat table view along with pagination links at the bottom.

MySQL Database Example

As an example I'll use this below 'employee' database for this tutorial.

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `employee`
--
CREATE TABLE IF NOT EXISTS `tbl_dept` (
  `int_id` int(4) NOT NULL AUTO_INCREMENT,
  `var_dept_name` varchar(50) NOT NULL,
  `int_hod` int(5) NOT NULL,
  KEY `int_id` (`int_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `tbl_emp` (
  `int_id` int(5) NOT NULL AUTO_INCREMENT,
  `var_emp_name` varchar(50) NOT NULL,
  `int_dept_id` int(4) NOT NULL,
  PRIMARY KEY (`int_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

The Model ('models/department_model.php')

First we create a model file with a method to fetch and return the entire department details along with the head of the department employee name.

<?php
class department_model extends CI_Model{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    //fetch department details from database
    function get_department_list($limit, $start)
    {
        $sql = 'select var_dept_name, var_emp_name from tbl_dept, tbl_emp where tbl_dept.int_hod = tbl_emp.int_id order by var_dept_name limit ' . $start . ', ' . $limit;
        $query = $this->db->query($sql);
        return $query->result();
    }
}
?>

The Controller ('controllers/department.php')

Next create the controller file and load the codeigniter pagination library and the department model file which we created earlier in the constructor method. Then create the index() function where we configure the behavior of the pagination library with the $config[] array and create the pagination links to be displayed at the bottom of the department table in the view file.

<?php
class department extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->database();
        $this->load->library('pagination');

        //load the department_model
        $this->load->model('department_model');
    }

    public function index()
    {
        //pagination settings
        $config['base_url'] = site_url('department/index');
        $config['total_rows'] = $this->db->count_all('tbl_dept');
        $config['per_page'] = "5";
        $config["uri_segment"] = 3;
        $choice = $config["total_rows"] / $config["per_page"];
        $config["num_links"] = floor($choice);

        //config for bootstrap pagination class integration
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['first_link'] = false;
        $config['last_link'] = false;
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['prev_link'] = '&laquo';
        $config['prev_tag_open'] = '<li class="prev">';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $this->pagination->initialize($config);
        $data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

        //call the model function to get the department data
        $data['deptlist'] = $this->department_model->get_department_list($config["per_page"], $data['page']);           

        $data['pagination'] = $this->pagination->create_links();

        //load the department_view
        $this->load->view('department_view',$data);
    }
}
?>

As you can see in the above code, we have integrated bootstrap's '.pagination' class to codeigniter pagination links. Using the '.active' css class will highlight the active page in the links.

The View ('views/department_view.php')

Finally create view file to display the department list in a neat striped table with bootstrap pagination links at the bottom.

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PHP CodeIgniter Pagination with Bootstrap Styles | Example</title>
    <!--link the bootstrap css file-->
    <link rel="stylesheet" href="<?php echo base_url("bootstrap/css/bootstrap.css"); ?>">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Department Name</th>
                        <th>Head of Department</th>
                    </tr>
                </thead>
                <tbody>
                    <?php for ($i = 0; $i < count($deptlist); ++$i) { ?>
                    <tr>
                        <td><?php echo ($page+$i+1); ?></td>
                        <td><?php echo $deptlist[$i]->var_dept_name; ?></td>
                        <td><?php echo $deptlist[$i]->var_emp_name; ?></td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 text-center">
            <?php echo $pagination; ?>
        </div>
    </div>
</div>
</body>
</html>

We have used bootstrap table styles such as '.table', '.table-striped', '.table-hover' to display the department list in a neat format and at the bottom with pagination links.

Open the controller in the browser and you get the department details displayed like this.

codeigniter-bootstrap-pagination-example
Read:

I hope now you get a better understanding of integrating twitter bootstrap styles with codeigniter pagination links.

Related Read: CodeIgniter-Bootstrap Pagination with Search Query Filter

Last Modified: Nov-10-2017

How to Merge Two JSON Strings into One with PHP

On 1/19/2018 Be the first to comment!

Hi! In this tutorial we will see how to merge two json strings into one in php. People often mistakes JSON for object or array but it's the string representation of a JavaScript object. In a recent project, I wanted to combine two jsons. That is, I have to make two API calls and combine their results into one. It is a rest api and returns the response as json. The task is simpler than I thought. It employs a similar technique I used here earlier when dealing with json. Let me show you how to do it.

php merge two json strings

PHP - Merging Two JSON into One:

If you are new to working with JSON, don't worry. PHP offers native functions to handle it easily. The idea is to decode the json data, write it to an array and encode it back to json.

Below are the steps involved in the process.

STEP-1) Let's take two different jsons containing couple of employee details.

<?php
$json1 = '{"id": "GD01", "name": "Garrett Davidson", "position": "System Administrator", "location": "New York"}';
$json2 = '{"id": "DW02", "name": "Donna Winters", "position": "Senior Programmer", "location": "Seattle"}';
?>

STEP-2) Next we should convert the json strings into an array and join them into a single array.

<?php
$array[] = json_decode($json1, true);
$array[] = json_decode($json2, true);
?>

Keep in mind the function json_decode() will return stdObject by default. To make it return associative array, we have to set the second parameter as 'true'.

STEP-3) Then convert the merged array to json. For this we have to use the function json_encode(). While encoding, I have included the token 'JSON_PRETTY_PRINT' to add proper indentation so that it's easy on the eyes.

<?php
$result = json_encode($array, JSON_PRETTY_PRINT);
?>

STEP-4) Finally print the merged json. You can simply echo it, but the output will look messy and difficult to read. So be sure to set the headers with right content type to display indents and blank spaces between the texts.

<?php
header('Content-type: text/javascript');
echo $result;
?>

This will produce the below output,

// output
[
    {
        "id": "GD01",
        "name": "Garrett Davidson",
        "position": "System Administrator",
        "location": "New York"
    },
    {
        "id": "DW02",
        "name": "Donna Winters",
        "position": "Senior Programmer",
        "location": "Seattle"
    }
]

As you can see, the output consists of a nested json combining the data from $json1 and $json2.

Here is the complete php script for json merging process.

index.php

<?php
$json1 = '{"id": "GD01", "name": "Garrett Davidson", "position": "System Administrator", "location": "New York"}';
$json2 = '{"id": "DW02", "name": "Donna Winters", "position": "Senior Programmer", "location": "Seattle"}';

// decode json to array
$array[] = json_decode($json1, true);
$array[] = json_decode($json2, true);

// encode array to json
$result = json_encode($array, JSON_PRETTY_PRINT);

// print merged json
header('Content-type: text/javascript');
echo $result;
?>

You can also store the json output in a file instead of displaying it in the browser window.

Read Also:

That explains about combining two or more json strings in php. The process can be easily done with core php alone and doesn't require any external tool. I hope you like this tutorial. Please share it on social media if you find it useful.

Contact Form

Name

Email *

Message *