Best Kali Linux Compatible Wireless Adapters/Dongles 2017

On 10/23/2017 Be the first to comment!

Here are the best kali linux compatible wireless adapters and usb dongles for 2017. 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

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

best wifi card for kali linux

Another great USB 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

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

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

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

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:

Best Mechanical Keyboards for Programming in 2017 - Reviews & Buying Guide

On 10/19/2017 Be the first to comment!

As a coder you should never compromise on the quality of your tools and keyboard is one such important programming tool. Being a programmer you spend most of the time typing on the keyboard. Therefore, it only makes sense that you invest in the best mechanical keyboard for programming in 2017.

A reliable high quality mechanical keyboard will provide you with comfortable typing experience and enhance your productivity. These mechanical keyboards use mechanical switches to give tactile feedback and help you type faster and efficiently than the standard keyboards. It is not an easy job to find the perfect keyboard to suit your need, so we put together the ultimate guide to help you in choosing the best coding keyboard.

Best 6 Mechanical Keyboards for Programming - Recommendations & Reviews

1. Filco Ninja Majestouch 2 - Best Programming Keyboard

filco majestouch 2 ninja review

Filco Ninja Majestouch-2 is the best mechanical keyboard for programmers on the market right now. It is one of the modern keyboards that support Full USB N-Key Rollover, meaning there is no limit to how many keys you press at once, all keystrokes will be accurately registered. This feature is very useful not only for gamers, but also for programmers, as they often use extensive combinations of shortcuts while coding.

Filco Ninja Majestouch 2 features front printing key caps that looks almost blank and good. This avoids the problem of fading labels. Although coders are precision typists, having faded label on keyboard do not look good.

The sturdy chassis and smooth key caps call for excellent build quality. The keyboard is available with Cherry MX Brown and Blue switches and Full size or Tenkeyless option. I like the full-size but if you want to bring it on your trip then TKN is a good choice. It just weighs only 2.2 pounds and requires little space.

The mechanical keyboard comes with 1.5 m cord to power up. Not all keys are backlit, but only the Caps, Num and Scroll Lock keys. See, it's not like you need an illuminated keyboard for programming work. In short Filco Ninja Majestouch 2 is the best professional keyboard that a programmer can ask for.

Full Size - Check Price on Amazon

Tenkeyless - Check Price on Amazon


2. WASD Code 87 - Best Keyboard for Programming MAC and PC

best keyboard for programming mac

CODE comes with a clean design with no logo on front. It's not just another programming keyboard, but the finest any professionals can get. At first glance, the keyboard may seem simple but, it balances greatly with its performance. Everything about this speaks of quality right from the build to the tactile performance.

Illuminated keyboards are a great help when you are accustomed to working at late night. And CODE comes with LED back lighting with 7 levels of adjustment. It uses Cherry MX switches. The key caps have high quality labels and feel smooth at your fingertips.

WASD CODE comes in several options, Tenkey-less / Full Size, Cherry MX Blue / Brown switches. The keyboard supports excellent cable routing. It has a 1.8m micro-USB cable with a cable tie, which allows you to route the cable in different ways.

It is compatible with PC and Mac and offers hardware-level control. With the help of DIP switch you can turn ON/OFF the operating system keys and switch over the keyboard function from QWERTY to MAC mode.

The CODE Keyboard offers great feel and supports alternate layouts - a great choice for programmers.

Cherry MX Brown - Check Price on Amazon

Cherry MX Blue - Check Price on Amazon


3. CM Storm QuickFire Rapid - Best Cheap Mechanical Keyboard

cm storm quickfire rapid review

CM Storm QuickFire Rapid is the best budget mechanical keyboard featuring Cherry MX switches and solid build. Coming from a well-known manufacturer of keyboards, QuickFire Rapid is one of the most popular products in its class. It is available both as TKL and Full Size version and completely customizable to your liking.

The design is simple and clean with excellent performance. It offers several options for switches such as Cherry MX Brown / Blue / Green / Red. Cherry MX keys provide solid feedback and suitable for programmers who prefer precision and comfort.

CM Storm QuickFire Rapid supports NKRO with PS/2 and 6 KRO via USB. In addition, the laser marked key caps are very durable and can be changed if desired. You also get some additional key caps and a key cap puller as well with the device.

It has multimedia controls and features a detachable braided USB cord with cable routing. So you can route the cable left, right or back according to your choice. Programmers who also like to play game get a nice option with this - which is to disable Windows keys with a dedicated switch.

In general it is a very good mechanical keyboard for beginners. If you are new to mechanical keyboards and want to try your hands on it, I would recommend QuickFire Rapid rather than going for expensive ones.

Cherry MX Brown - Check Price on Amazon

Cherry MX Blue - Check Price on Amazon


4. Corsair K95 - Best Value for Money

best value for money mechanical keyboard

The flagship Corsair k95 is one of the best value for money mechanical keyboard for programming. It got loads of customizing options and features Cherry MX Red and Brown switches with smooth actuation and flawless accuracy. Built with aircraft-grade aluminium, quality and durability is not something you have to worry about.

Corsair k95 is the full-size keyboard that includes number pad with 18 additional programmable G-Keys. The programmable keys support 3 different profiles offering totally 54 programmable keys. This much level of customization makes it the best keyboard for programmers.

It offers many high-end features, such as Key-by-Key backlight, media control, 100% anti-ghosting and an astonishing 122-key rollover. This practically means that you can sleep over the keyboard and it would still register each keystroke separately.

The fact that it requires two USB ports to power on and the lack of USB hub are the downside of this awesome keyboard. But overall the positive aspects of Corsair K95 outweigh the small negatives and it is a great professional mechanical keyboard.

Check Price on Amazon


5. Corsair Vengeance K65 - Tenkeyless Coding Keyboard

corsair vengeance k65 review

If you are looking for a best tenkeyless mechanical keyboard then Corsair Vengeance K65 should be your top choice. The keyboard is quite affordable and comes with rugged, anodized aluminum solid chassis. Being 10-key less keyboard, it is small and portable and can be carried with you on travel.

People with large hands may find typing on tenkeyless keyboard inconvenient as the keys will be little confined. But that is not the case with Corsair Vengeance K65. Despite being compact, it has standard size keys, making typing very comfortable.

It uses linear MX Red switches with acute precision and features Full Key Roll over and Anti-Ghosting. It also offers detachable USB with cable routing which is very convenient if you move around a lot.

A small drawback of Vengeance K65 is the lack of programmable keys, but it is understandable because of the smaller size of the device. Apart from that, it is a great tenkeyless keyboard to program that offers comfort, accuracy and portability.

Check Price on Amazon


6. Ducky Shine 5 RGB - LED Backlit Mechanical Keyboard

best backlit mechanical keyboard 2017

As it name suggests Ducky Shine 5 RGB is a full-size backlit RGB illuminated mechanical keyboard. The keyboard is all shiny with impressive design. It has a solid, if slightly rough chassis with individual LED backlit keys and smooth key caps. The key caps are made of double shot ABS, which is thicker and more durable than normal ABS.

Generally, illuminated keyboards use special software to change colors and lighting effects. But not Ducky Shine 5. It uses key combinations to change lighting profiles, such as Breathing, Reactive, Aurora, Wave and Ripple mode. There is also the option to change the lighting level for the Red, Green and Blue colors individually.

The keyboard features Cherry MX Brown / Blue switches and uses the ARM M3 MCU, to provide the fastest key response possible. It has 24 media keys, but they are disabled by default. You have to follow the instructions provided in the manual to enable them.

Ducky Shine 5 comes with removable 5-foot long mini-USB cable to power on. And the good thing is it is compatible with Mac as well. You have to use the DPI switches to make it work with Mac OS.

Cherry MX Blue - Check Price on Amazon

Cherry MX Brown - Check Price on Amazon


How to Choose the Best Keyboard for Programming?

The keyboard is the most important gear of a programmer so it only makes sense to get a well designed quality keyboard that will last for years to come. Undoubtedly, a good keyboard will provide the best experience for a programmer and increase performance. But a poor design keyboard will make things hard and frustrating for a coder and will reduce their quality of performance.

Most programmers, including myself prefer that their keyboard is as simple as possible following the standard layout and excellent response on key press. But not all programmers' needs are the same. It may vary according to their nature of work and personal preferences. Even before purchasing a new keyboard, make a list of all the features you want the most and make that priority.

Keyboard Size

When it comes to keyboard its size matters. The size of the keyboard depends on the number of keys it contains. There are three common keyboard sizes available on the market and they are Full size, Tenkeyless (TKL) and Compact.

A full sized keyboard follows a standard design with 104 keys, including the number pad and all. This is the size of the keyboard widely used, but they are not light and take up more desk space. Also, your hands must travel a long distance to reach the mouse.

On the other hand, a Tenkeyless keyboard is lighter than the full-size keyboard and very portable. It has a standard key layout without the numeric keys, resulting in only 87 keys. This makes the keyboard smaller and also keeps the mouse closer together so you don't have to reach that far. Basically, number pad is of little use to programmers. Also, given the ergonomic factor, TKL design is probably the best keyboard for a programmer in my opinion.

The third, Compact size follows a 60% design and excludes numeric keys and function keys, such as F1 to F12, Home, Insert, Delete, Page Up and Down keys. There is no doubt that the compact keyboard is the lightest of all, but at the cost of so many functional keys, it probably is not the best choice for coding work.

Ergonomics

Ergonomic keyboards usually come with sculpted or split designs that are way different from what you are used to. It will take some time getting used to the new layout and everything. But once you start working on the ergonomic keyboard, it will be difficult to return to the normal keyboard.

Unless you suffer from wrist pain or injury, there's no need to buy ergonomic keyboard. For one thing, they aren't cheap and will not make you type faster. But mainly because they don't use mechanical switches in ergonomic keyboards, so feedback of keys are not that good.

May be this is my opinion, but I have tried different keyboards and nothing is satisfactory like working on a mechanical keyboard. As a programmer you'll need to type fast and want a satisfactory typing experience, which is why mechanical keyboards are the best in this context.

Improving Keyboard Ergonomics

Using the wrist rest is a simple solution to maintain the ergonomics of the keyboard. It'll keep your palms raised as you type to remove strain on your wrists. In this way you can improve ergonomics of your standard keyboard without switching over to an expensive ergonomic design.

The wrist rests made of rubber or finished wood are the best and come in different shapes and sizes. When buying wrist rests, make sure their height and length match your keyboard model and fit comfortably at the bottom of it.

Keyboard Switch Type

What makes a keyboard good or bad? It all starts with the type of switch they use. There are several switch technologies used in the manufacture of keyboard, such as membrane, mechanical, dome, scissor switch, etc. In these, membrane and mechanical switches are most commonly used on PC keyboards.

Generally, Membrane keyboards are cheap, but their key feedback is not so good. While mechanical keyboards are designed with a separate switch under each key and is composed of a base, a spring and a rod. Based on the shape of the spring and stem used, the switches are classified into several types. And each type also has different drive force, travel distance and sound. Cherry MX and Topre are popular types in mechanical switches.

Mechanical Switch Color

If you want the best keyboard for programming, all you need to do is choose a keyboard with Cherry MX switches. Cherry MX switches come in various colors named Cherry MX Red, Blue, Brown, Black and Clear. Black and Red ones are the most popular switches for gaming keyboards.

In my experience, the best mechanical switches for programming are the Cherry MX Brown, Blue and Clear switches. The tactile feedback offered by these switches gives you a great feel for every keystroke and let you into the flow of effortless coding.

Both the Brown and Clear switches are non-clicky, so they will not make noise while typing. Also the brown switches has 45g actuation force, which is much lower, so you won't feel soreness on your fingers even after typing for long hours. On the other hand, the blue switches have the actuation force of 50g and are clicky. Therefore, they will be suitable for individuals who like to hear audible audio feedback of key strokes and it gives a great feeling of satisfaction when typing.

Key Rollover & N-Key Rollover

The term Key Rollover or KRO refers to the ability to register multiple key presses at the same time on a keyboard. If a keyboard is labeled "6 Key Roll Over", it means that the keyboard can only register six keys at the same time. When labeled as "N-key rollover" there is no limitation on the number of keys you press at a time and all key presses will be recorded and carried out without fail.

This feature benefits mainly in games than in programming. But programmers also get some benefits because of the extensive shortcut key-combinations they often use.

The old PS/2 cable supports N-KRO by default, but the recent USB connection allows only 6 KRO. Nowadays, modern keyboards use two USB ports simultaneously and allow N-Key Rollover.

Over To You

Finding the best keyboard for programming can be daunting when you do not know what to look for on a keyboard. We hope this guide has shed some light on what to look for in a mechanical keyboard and given you some good recommendations in the market. Now is the time to make the choice that fits both your needs and your budget.

Also Read:

Take Webpage Screenshot using PHP and PageSpeed Insights API

On 10/09/2017 Be the first to comment!

Hi! Today I have come up with an interesting post which is about taking screenshot of webpage using PHP and Google PageSpeed Insights API. This handy feature will help you provide thumbnail preview of websites to improve user experience on your sites and applications. There are several third-party screen capture APIs and Plugins available in the market but here I'm going to show you a very simple solution. Yep that is to use Google PageSpeed Insights API to capture screen shot. And the fact that it doesn't requires registration or apikey is really good.

In general, Google PageSpeed Insights API is used to measure site performance. But you can also use it to capture screenshot of the website / webpage from a url. Let's see how to get the website screen shot from url using PageSpeed Insights API in PHP.

take screenshot of webpage in php

Using Google's PageSpeed Insights API:

Using Google PageSpeed Insights API to grab the webpage screen shot is very easy. All you have to do is call the api with params like this,

https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$webpageURL&screenshot=true

where $webpageURL = url of the web page you need to take screenshot.

This api call will return the website screenshot for desktop view.

To take screenshot of mobile version use,

https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$webpageURL&screenshot=true&strategy=mobile

Take Website Screenshot from URL with PHP:

Following is a small php example to capture the screenshot of a webpage using PageSpeed Insights API. Here we have a simple form where the user has to enter the url for which they need image preview. Once they submit the form, the url is passed to the api, which returns the response containing screenshot data.

index.php

<?php
if (!empty($_POST['url'])) {
    // get webpage url
    $url = $_POST['url'];
    // check if it is a valid url
    if (filter_var($url, FILTER_VALIDATE_URL)) {
        // send request to api
        $data = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$url&screenshot=true");
        $data = json_decode($data, true);
        // get screenshot image
        $screenshot = $data['screenshot']['data'];
        $screenshot = str_replace(array('_','-'),array('/','+'),$screenshot);
    } else {
        $err = "Please enter a valid URL!";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Capture Website Screenshot in PHP - Demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" >
    <link href="css/bootstrap.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="container">
    <div class="col-xs-8 col-xs-offset-2 well" style="background: none;">
        <form action="index.php" method="post">
            <div class="form-group">
                <input type="text" name="url" placeholder="Enter Webpage URL" class="form-control" />
            </div>
            <div class="form-group">
                <input type="submit" name="submit" value="Take Screenshot" class="btn btn-danger"/>
            </div>
        </form>
    </div>
    <?php if(isset($screenshot)) { ?>
    <div class="col-xs-8 col-xs-offset-2 text-center well" style="background: none;">
        <h2>Website Screenshot</h2><br/>
        <img src="<?php echo 'data:image/jpeg;base64,' . $screenshot; ?>" />
    </div>
    <?php } else if(isset($err)) { ?>
    <div class="col-xs-8 col-xs-offset-2 text-center well" style="background: none;">
        <?php echo $err; ?>
    </div>
    <?php } ?>
</div>
</body>
</html>

The above markup produce a php form with a text box and a submit button. Enter the url on the provided box and hit 'Take Screenshot' button.

take website screenshot php google api

If the provided url is a valid one, upon api request the website screenshot image will be displayed just below the form like this,

capture webpage screenshot php

That's it! Likewise, you can easily capture the webpage screenshot with PHP and Google API. I hope you like this tutorial. If you find it useful, please do share it on social media.

Also Read:

URL Shortener Service using PHP and Google API

On 9/26/2017 Be the first to comment!

Hi! In today's post we will see about creating URL Shortener service using PHP and Google API. Google provides tons of APIs for users to easily complete several complicated tasks. And Google url shortener service (goo.gl) is one among them. In the past I have discussed about some other APIs like youtube api and google finance api. Now I'm going to show you about using google url shortener api service and generate shorten url using php.

php url shortener using google api

Google URL Shortener API:

The Google URL Shortener is a service that takes long URLs and makes them short with fewer characters to make the link easier to share on social networks or by email. With Google's URL Shortening API, you can create these short urls programmatically by sending the long url through the http request. Please note that the API has a daily limit of 1,000,000 requests for free - more than that goes to your billing.

In order to use google url shortener api, you must first get the api key and have to tag it with each of your REST calls.

  • To obtain the key, login to Google developer console
  • Create new or select an existing project
  • Click 'ENABLE API' and select APIs in the APIS & auth section
  • Choose 'URL Shortener API' and click 'ENABLE'
  • Under Credentials, generate a new key by selecting 'API key' option.

Creating URL Shortener Service with PHP and Google API:

The following PHP script quickly generates a short URL from a long URL by using the Google's URL Shortener API. So many examples around the Net uses only cURL method. So I have tried a different way in my tutorial. Here I use the file_get_contents() function to send the HTTP POST request to the api and retrieve the json response containing the short url.

<?php
$apikey = 'YOUR_API_KEY'; // change this to yours
$longurl = 'https://www.google.com/';
$data = array('longUrl' => $longurl);
$context = array(
    'http' => array(
        'method' => 'post',
        'header'=>'Content-Type:application/json',
        'content' => json_encode($data)
        )
    );
$context = stream_context_create($context);
$response = file_get_contents('https://www.googleapis.com/urlshortener/v1/url?key=' . $apikey, false, $context);
$json = json_decode($response, true);

echo 'The Long URL: ' . $json['longUrl'] . '<br/>';
echo 'The Shortened URL: ' . $json['id'];

// Output

// The Long URL: https://www.google.com/
// The Shortened URL: https://goo.gl/Njku
?>

In order to make http request via file_get_contents() function, we have to pass the headers and other options through a context. For that we have used the function stream_context_create() in the above code. It creates and returns a stream context that we need to make the http request to the web service. It takes up options as an associative array of associative arrays.

The API responds in json format containing shortened url stored in 'id'.

You can display the whole json response from the api in this way,

<?php
echo "<pre>";
print_r($response);

// Output

// {
//  "kind": "urlshortener#url",
//  "id": "https://goo.gl/Njku",
//  "longUrl": "https://www.google.com/"
// }
?>
Read:

This is how you can generate short urls with php and google api. Feel free to modify the code and add more features to the url service. Google really simplifies the task of shortening url and the good thing is that you don't have to maintain database on your own. I hope you like this tutorial. Please do not forget to share it in social networks.

10 Best Tips To Make Your Site Mobile Friendly - Infographics

On 9/19/2017 Be the first to comment!

Hi! Here we have the infographics that gives you the 10 best tips to make your site mobile friendly and improve the mobile user experience. Smartphones are not just used to make calls and send messages. Millions of mobile users use them to surf internet, search for news, information, and to shop and purchase.

The fact that your site can be viewed on a mobile device does not make it mobile-friendly. If you have not properly optimized your website / e-commerce site for mobile traffic you could loss leads and sales.

Studies shows that more than half of the internet traffic is through mobile devices and the rate increases day by day. Almost 60% of mobile users said to have trouble accessing websites and face navigation problems.

Even though your site looks perfect and beautiful from desktop, the mobile user experience could be totally different. So many websites have separate mobile sites and its fine if you have small static sites. But responsive websites are much more preferred these days and provide uniform user experience for both desktop pc and mobile users.

Leveraging responsive technology frameworks like Bootstrap will help you build responsive mobile friendly websites. They follow the mobile-first approach and create a similar experience for users regardless of whether they access the site from the desktop, tablet or smartphone.

In addition to the better user experience across devices, you also don't need to have separate mobile url and redirect to mobile site. This gives you SEO benefits and makes the site much easier to manage.

10 Best Tips To Make Your Site Mobile Friendly - Infographics

For your website to be friendly and optimized for mobile traffic, follow the 10 best suggestions that appear in the below infographic. It will help you build a positive experience for your mobile customers.

best tips to make your site mobile friendly

10 Best Tips To Make Your Site Mobile Friendly - An Infographic by kodingmadesimple.com

To embed this infographic on your site: Copy and Paste the Below Code


SMS Gateway API Integration in PHP - Sending Text Messages

On 9/11/2017 Be the first to comment!

Hi! In this tutorial, we'll look at how to integrate sms api in php and send bulk text messages using simple php script. These days, increasing number of web applications uses SMS feature for product promotions, user authentication or sales and event notifications directly through their mobile phones. To send sms via php, you need to integrate an appropriate SMS gateway provider in your application. There are a number of SMS Service providers in the market and they offer APIs in various programming languages.

Here I'm going to show you how to integrate Textlocal SMS gateway in PHP.

sms gateway integration in php

Read: How to Create AJAX Search Engine using PHP and MySQL

Textlocal SMS API:

Textlocal is a bulk sms gateway that offers an easy and powerful messaging platform. It helps you maintain massive contact lists, compose rich multi-media messages and send sms in bulk. It has flexible APIs supporting different programming platforms.

Register with SMS Gateway:

In order to use Textlocal sms gateway in your web app, you must first register with their service and get your hash code.

Visit this link and signup for the sms service. It is necessary to provide details such as email address, mobile number and password for registration. At the beginning you will get 10 free sms credits which you can use for testing.

Read: User Login and Registration System using PHP and MySQL

Once you finish signing up, login and go to the Dashboard.

From there, navigate to 'Help' > 'All Documentation' page and get your API hash code.

You also need to download the API library textlocal.class.php. For that go to http://api.textlocal.in/docs/phpclass and click on 'Download' link on the righ side of the page.

SMS API Integration in PHP:

Extract and move 'textlocal.class.php' to your root folder. You have to include this class in your php code and use the sendSms() function to send text messages. To test the service, you can send sms from localhost. Here's the php code to do it.

<?php
require('textlocal.class.php');

$username = 'myemail@example.com'; // change this to your email address
$hashcode = 'xxxxxxx'; // change this to yours

$textlocal = new Textlocal($username, $hashcode);
$numbers = array(919999999999); // separate multiple numbers by comma
$sender = 'TXTLCL';
$message = 'Hi! This is a test message!!!';

try {
    $result = $textlocal->sendSms($numbers, $message, $sender);
    $data = json_decode($result, true);
    if($data['status'] == 'success'){
        echo 'SMS sent successfully!';
    }
} catch(Exception $e) {
    die('Error: ' . $e->getMessage());
}
?>

To send sms in bulk, use comma-delimited array list of mobile numbers. Also make sure the numbers are in international format i.e. country code followed by 10-digit mobile no. A maximum of 10,000 numbers are allowed at a time.

Run the above code and if all goes well, you will see success message. I received the sms within couple of seconds. Remember that you will only get ten sms credits under free account. So use it wisely to test the code and not run it in a loop.

Read: How to Import JSON into MySQL using PHP

By default, the Textlocal API will send the response as JSON. This is the response I received from the API.

{
    "balance": 8,
    "batch_id": 302329336,
    "cost": 1,
    "num_messages": 1,
    "message": {
        "num_parts": 1,
        "sender": "TXTLCL",
        "content": "Hi! This is a test message!!!"
    },
    "receipt_url": "",
    "custom": "",
    "messages": [
        {
            "id": "1200053892",
            "recipient": 919999999999
        }
    ],
    "status": "success"
}

The API returns a status field containing the message 'Success' or 'Failure'. You can use it to check if sms is sent or not.

You can also display the entire api response this way,

<?php
$result = $textlocal->sendSms($numbers, $message, $sender);
print_r($result);
?>

Read: Store and Retrieve Image from MySQL Database using PHP

Likewise you can send bulk sms in php via the Textlocal sms gateway. The entire process is simple and with few lines of code you can send bulk messages from your website. You can also use the cURL method and send an HTTP request to the sms server. I hope you like this tutorial. Please don't forget to share it in social media.

PHP Login and Registration Script with MySQL Example

On 9/07/2017 58 Comments so far

PHP Login and Registration Script: User Login/registration system is one of the key components of any membership driven websites and the ability to build them is a must have skill for any web developer. In this post, let us see how to create a complete login and registration system using php and mysql database.

This tutorial is fairly simple and easy to understand, but it covers as much as required to build advanced login/registration system - right from data validation to maintaining php sessions for authenticated access.

MySQL Database for Login/Registration Module

Before entering into the coding part, first let us build the database required for this example.

Read Also:
CREATE DATABASE `testdb`;
USE `testdb`;

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) NOT NULL,
  `email` varchar(60) NOT NULL,
  `password` varchar(40) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Run this sql file in phpmyadmin interface and create the database and table.

PHP Script for Login and Registration System

To build the login/registration system we need to create the following files.

  • index.php - This is the home page of our application
  • register.php - It contains the user sign up form
  • login.php - It contains the login form
  • logout.php - This contains the user logout script
  • dbconnect.php - MySQL database connection script

System Flow for User Login Registration Module

These are the steps breakdown of the user registration/login module we are going to build.

  1. The Home page (index.php) contains links for login and sign up process in top navigation menu.
  2. For new users » click on sigup link » user redirected to registration form » fill up the form and submit » validate the form input » registration succeed » notify user and redirect to login page.
  3. For registered users » click on login link on index.php » user redirected to login page » user provide login credentials » authenticate user and redirect to index page.
  4. For signed in users » show user's name and logout link on navigation bar.
  5. User clicks on logout » delete user details from session variable and destroy session » redirect to Home page.

Note: This tutorial uses twitter bootstrap framework for css. I prefer to use this as it's readily available and you can easily integrate bootstrap with HTML. But if you prefer custom style sheet then you can simply attach one and replace all the class selectors used in the html tags with your own. However the program functionality remains the same and will not be disturbed.

Dbconnect.php

This is where we connect to the mysql database. Keeping database connectivity in a separate file is very handy. This way you can get access to database across multiple files by simply including the file once and access it anywhere.

<?php
//connect to mysql database
$con = mysqli_connect("localhost", "myusername", "mypassword", "testdb") or die("Error " . mysqli_error($con));
?>

Register.php

This php file contains the code for the user registration process. The access to this page will be restricted for signed in user. We do this by checking out the session variable.

<?php
session_start();

if(isset($_SESSION['usr_id'])) {
    header("Location: index.php");
}

include_once 'dbconnect.php';

//set validation error flag as false
$error = false;

//check if form is submitted
if (isset($_POST['signup'])) {
    $name = mysqli_real_escape_string($con, $_POST['name']);
    $email = mysqli_real_escape_string($con, $_POST['email']);
    $password = mysqli_real_escape_string($con, $_POST['password']);
    $cpassword = mysqli_real_escape_string($con, $_POST['cpassword']);
    
    //name can contain only alpha characters and space
    if (!preg_match("/^[a-zA-Z ]+$/",$name)) {
        $error = true;
        $name_error = "Name must contain only alphabets and space";
    }
    if(!filter_var($email,FILTER_VALIDATE_EMAIL)) {
        $error = true;
        $email_error = "Please Enter Valid Email ID";
    }
    if(strlen($password) < 6) {
        $error = true;
        $password_error = "Password must be minimum of 6 characters";
    }
    if($password != $cpassword) {
        $error = true;
        $cpassword_error = "Password and Confirm Password doesn't match";
    }
    if (!$error) {
        if(mysqli_query($con, "INSERT INTO users(name,email,password) VALUES('" . $name . "', '" . $email . "', '" . md5($password) . "')")) {
            $successmsg = "Successfully Registered! <a href='login.php'>Click here to Login</a>";
        } else {
            $errormsg = "Error in registering...Please try again later!";
        }
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>User Registration Script</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport" >
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
</head>
<body>

<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <!-- add header -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.php">Koding Made Simple</a>
        </div>
        <!-- menu items -->
        <div class="collapse navbar-collapse" id="navbar1">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="login.php">Login</a></li>
                <li class="active"><a href="register.php">Sign Up</a></li>
            </ul>
        </div>
    </div>
</nav>

<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4 well">
            <form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="signupform">
                <fieldset>
                    <legend>Sign Up</legend>

                    <div class="form-group">
                        <label for="name">Name</label>
                        <input type="text" name="name" placeholder="Enter Full Name" required value="<?php if($error) echo $name; ?>" class="form-control" />
                        <span class="text-danger"><?php if (isset($name_error)) echo $name_error; ?></span>
                    </div>
                    
                    <div class="form-group">
                        <label for="name">Email</label>
                        <input type="text" name="email" placeholder="Email" required value="<?php if($error) echo $email; ?>" class="form-control" />
                        <span class="text-danger"><?php if (isset($email_error)) echo $email_error; ?></span>
                    </div>

                    <div class="form-group">
                        <label for="name">Password</label>
                        <input type="password" name="password" placeholder="Password" required class="form-control" />
                        <span class="text-danger"><?php if (isset($password_error)) echo $password_error; ?></span>
                    </div>

                    <div class="form-group">
                        <label for="name">Confirm Password</label>
                        <input type="password" name="cpassword" placeholder="Confirm Password" required class="form-control" />
                        <span class="text-danger"><?php if (isset($cpassword_error)) echo $cpassword_error; ?></span>
                    </div>

                    <div class="form-group">
                        <input type="submit" name="signup" value="Sign Up" class="btn btn-primary" />
                    </div>
                </fieldset>
            </form>
            <span class="text-success"><?php if (isset($successmsg)) { echo $successmsg; } ?></span>
            <span class="text-danger"><?php if (isset($errormsg)) { echo $errormsg; } ?></span>
        </div>
    </div>
    <div class="row">
        <div class="col-md-4 col-md-offset-4 text-center">    
        Already Registered? <a href="login.php">Login Here</a>
        </div>
    </div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

Read: How to Use Google reCAPTCHA in PHP Form

This is how the registration form looks like.

php-sign-up-script

Registration form requires user to fill up name, email id and password and confirm password fields. All the fields are mandatory and user will be asked to provide the data if it is left blank like this.

php-registration-form-validation

Once the user fills out the details and submits the form for sign up, we sanitize the received data to avoid sql injection and validate the form input. If validation fails the user will be shown with the appropriate error message below each form input like this.

php-registration-form-validation-error
php-registration-password-validation

If the validation succeeds the data will be stored in the database and user will be shown with the login link.

Login.php

This file contains the php code for user login process. The access to login form will be restricted for signed in users by checking if the php session is set or not.

<?php
session_start();

if(isset($_SESSION['usr_id'])!="") {
    header("Location: index.php");
}

include_once 'dbconnect.php';

//check if form is submitted
if (isset($_POST['login'])) {

    $email = mysqli_real_escape_string($con, $_POST['email']);
    $password = mysqli_real_escape_string($con, $_POST['password']);
    $result = mysqli_query($con, "SELECT * FROM users WHERE email = '" . $email. "' and password = '" . md5($password) . "'");

    if ($row = mysqli_fetch_array($result)) {
        $_SESSION['usr_id'] = $row['id'];
        $_SESSION['usr_name'] = $row['name'];
        header("Location: index.php");
    } else {
        $errormsg = "Incorrect Email or Password!!!";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>PHP Login Script</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport" >
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
</head>
<body>

<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <!-- add header -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.php">Koding Made Simple</a>
        </div>
        <!-- menu items -->
        <div class="collapse navbar-collapse" id="navbar1">
            <ul class="nav navbar-nav navbar-right">
                <li class="active"><a href="login.php">Login</a></li>
                <li><a href="register.php">Sign Up</a></li>
            </ul>
        </div>
    </div>
</nav>

<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4 well">
            <form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform">
                <fieldset>
                    <legend>Login</legend>
                    
                    <div class="form-group">
                        <label for="name">Email</label>
                        <input type="text" name="email" placeholder="Your Email" required class="form-control" />
                    </div>

                    <div class="form-group">
                        <label for="name">Password</label>
                        <input type="password" name="password" placeholder="Your Password" required class="form-control" />
                    </div>

                    <div class="form-group">
                        <input type="submit" name="login" value="Login" class="btn btn-primary" />
                    </div>
                </fieldset>
            </form>
            <span class="text-danger"><?php if (isset($errormsg)) { echo $errormsg; } ?></span>
        </div>
    </div>
    <div class="row">
        <div class="col-md-4 col-md-offset-4 text-center">    
        New User? <a href="register.php">Sign Up Here</a>
        </div>
    </div>
</div>

<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

This file produces a login form similar to this.

php-login-system-script

Login form requires users to provide login credentials (email & password). Both the input fields are mandatory and notify user to fill out if left blank.

php-login-system-form-validation

Here too we sanitize the data and check for user authentication against database records. If it fails, we notify the user with error message like this,

php-login-system-form-validation-error

If the user credentials are legitimate then we create session and store user's id and name in the session variable and redirect to index.php.

Read: How to Upload & Watermark Images with PHP

Index.php

This is the home page of our application and shows login and sign up menu links for visitors and for signed in members will show their name and logout link respectively.

<?php
session_start();
include_once 'dbconnect.php';
?>
<!DOCTYPE html>
<html>
<head>
    <title>Home | Koding Made Simple</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport" >
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
</head>
<body>

<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.php">Koding Made Simple</a>
        </div>
        <div class="collapse navbar-collapse" id="navbar1">
            <ul class="nav navbar-nav navbar-right">
                <?php if (isset($_SESSION['usr_id'])) { ?>
                <li><p class="navbar-text">Signed in as <?php echo $_SESSION['usr_name']; ?></p></li>
                <li><a href="logout.php">Log Out</a></li>
                <?php } else { ?>
                <li><a href="login.php">Login</a></li>
                <li><a href="register.php">Sign Up</a></li>
                <?php } ?>
            </ul>
        </div>
    </div>
</nav>

<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

Logout.php

This file will be fired up when the user clicks on the logout link. The user logout process is fairly simple. It destroy session and unset the user data from the session.

<?php
session_start();

if(isset($_SESSION['usr_id'])) {
    session_destroy();
    unset($_SESSION['usr_id']);
    unset($_SESSION['usr_name']);
    header("Location: index.php");
} else {
    header("Location: index.php");
}
?>

Once you created all the above files, run the app and you will see the home page like this,

php-login-registration-system-home
index.php - Home Page

Now click on the sign up link and you will be redirected to the user registration form,

php-registration-form

Now enter the form details and submit the sign up button. If everything goes right then you will be registered and notified with a message like this,

php-registration-success

Now go to the login form through the login link.

Provide the login credentials and you will be signed in and redirected to the index page.

signed-in-user-home-page
index.php as signed-in user

Click on logout to sign out the session and you will be taken back to the index page again.

home page
After Log out

Download

That's it. You have successfully created user login and registration system in php and mysql.

Read Also:

I hope you find this php login/registration script useful. Meet you in another interesting tutorial!

Last Modified: 7-Sep-2017

Contact Form

Name

Email *

Message *