Month: February 2018

How to check port is open and not open using PHP?

Sometime this is need to know that some port is active or not cause a port is used to recognize a specific service which is being executed in a computer. To recognize a port and to send packets, 16 bit numbers known as port numbers are used. A port number along with IP address serves as a destination for packets to be sent.

Suppose domain name so get this ip address so ip is There are many website to know ip. Then check port that open or not.

$host_connection = ''; // techparkbd
$ports_number = array(21, 25, 80, 81, 110,143, 443, 3306); //checking port number

foreach ($ports_number as $port)
    $connection_check = @fsockopen($host_connection, $port);

    if (is_resource($connection_check))
        echo '<h5>' . $host_connection . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open now.</h5>' . "\n";


        echo '<h5 style="color: red">' . $host_connection . ':' . $port . ' is not open now.</h5>' . "\n";


when you run this code it will show result like this (ftp) is open now. (smtp) is open now. (http) is open now. is not open now. (pop3) is open now. (imap) is open now. (https) is open now. () is open now.

This is very simple way to know port open or not. If you face any problem then please inform me.


json_encode not working uft8 content , solve by use extra parameter in json_encode

Sometime json_encode not working in uft8 content so this is very common problem , In this article it will solve this problem. This is simple code which help you.

$data = [
    'গুগলের ‘স্টাইল আইডিয়াস’',
    'ফেসবুকের নয়া উদ্যোগে'
echo "<pre>";
echo "<br>";
echo json_encode($data); // normal json_encode
echo "<br>";
echo json_encode($data, JSON_UNESCAPED_UNICODE); // json_encode with extra parameter which Encode multibyte Unicode characters literally

Then output is :

This is array data:

    [0] => গুগলের ‘স্টাইল আইডিয়াস’
    [1] => ফেসবুকের নয়া উদ্যোগে

This is normal json_encode

echo json_encode($data);
output will be is:

["\u0997\u09c1\u0997\u09b2\u09c7\u09b0 \u2018\u09b8\u09cd\u099f\u09be\u0987\u09b2 \u0986\u0987\u09a1\u09bf\u09df\u09be\u09b8\u2019","\u09ab\u09c7\u09b8\u09ac\u09c1\u0995\u09c7\u09b0 \u09a8\u09df\u09be \u0989\u09a6\u09cd\u09af\u09cb\u0997\u09c7"]


echo json_encode($data, JSON_UNESCAPED_UNICODE);
output will be: 

["গুগলের ‘স্টাইল আইডিয়াস’","ফেসবুকের নয়া উদ্যোগে"]

If you face this problem then use this code which help you, if you face any problem then please inform me. I will try to help you.


Dynamic Drag and Drop using PHP & mysql and jQuery

This is very common feature that items list need to drag and drop and save it. Drag’n drop generally looks hard-to-apply but it is definitely not by using JavaScript frameworks. In this article i will show how the drag’n drop & saving the new positions to the database Will be working”. This is very simple process you can apply it. This is simple code which you can check

First create a simple database Suppose “drag” . Here is the code for create a table then run this code in mysql

CREATE TABLE `records` (
 `recordID` int(11) NOT NULL auto_increment,
 `recordText` varchar(255) default NULL,
 `recordListingID` int(11) default NULL,
 PRIMARY KEY (`recordID`)
INSERT INTO `records` VALUES ('1', 'Once dropped, an Ajax query is activated', '3');
 INSERT INTO `records` VALUES ('2', 'Dragging changes the opacity of the item', '2');
 INSERT INTO `records` VALUES ('3', 'Returned array can be found at the right', '1');
 INSERT INTO `records` VALUES ('4', 'It is very very easy', '4');

The most important column in the database is recordListingID which shows us the order of the records.

Then create a php page which ready mysql connect .

* Author : Ali Aboussebaba
* Email :
* Website :
* Subject : Dynamic Drag and Drop with jQuery and PHP

// PDO connect *********
function connect() {
	$host = 'localhost';
	$db_name = 'drag';
	$db_user = 'root';
	$db_password = '';
    return new PDO('mysql:host='.$host.';dbname='.$db_name, $db_user, $db_password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

Then create index.php which is the main page to view list

$pdo = connect();
$sql = 'SELECT * FROM records ORDER BY recordListingID ASC';
$query = $pdo->prepare($sql);
$list = $query->fetchAll();


    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jQuery Dynamic Drag'n Drop</title>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>

        body {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 16px;
            margin-top: 10px;

        ul {
            margin: 0;

        #contentWrap {
            width: 700px;
            margin: 0 auto;
            height: auto;
            overflow: hidden;

        #contentTop {
            width: 600px;
            padding: 10px;
            margin-left: 30px;

        #contentLeft {
            float: left;
            width: 400px;

        #contentLeft li {
            list-style: none;
            margin: 0 0 4px 0;
            padding: 10px;
            border: #CCCCCC solid 1px;

        #contentRight {
            float: right;
            width: 260px;

    <script type="text/javascript">

            $(function() {
                $("#contentLeft ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
                    var order = $(this).sortable("serialize");
                        url: 'http://localhost/updatelist.php?action=updateRecordsListings',
                        type: 'POST',
                        data: order,
                        success: function (result) {



<div id="contentWrap">
    <div id="contentLeft">
            foreach ($list as $rs) {
                <li id="recordsArray_<?=$rs['recordID']?>"><?=$rs['recordText']?></li>

    <div id="contentRight">
        <p>New List will be displayed here.</p>
        <p>&nbsp; </p>



After posting the array of “new order of the items” to updatelist.php, we must run a query to update our database that will reflect the last positions of every item:

$pdo = connect();

$action = $_GET['action'];
$updateRecordsArray = $_POST['recordsArray'];

if ($action == "updateRecordsListings"){

    $listingCounter = 1;
    foreach ($updateRecordsArray as $recordIDValue) {

        $query = "UPDATE records SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
        $query = $pdo->prepare($query);
        $listingCounter = $listingCounter + 1;

    echo '<pre>';
    echo '</pre>';
    echo 'If you refresh the page, you will see that records will stay just as you modified.';

all done so run index.php and drag list , it will automatically save drag list and after refresh it will show new list

This is example output

this is output