How To Create A Simple REST API in PHP? Step By Step Guide!

How To Create A Simple REST API in PHP? Step By Step Guide!

Previously, we learned how to create, read, update and delete database records (CRUD operations) with our PHP, MySQL & OOP CRUD Tutorial.

Today, before we go to JavaScript programming, we will learn how to create a simple REST API in PHP. Enjoy our step-by-step tutorial below!

This post covers the following topics:

1.0 Project Overview
1.1 What is REST API?
1.2 Why do we need REST API?
1.3 Where REST API is used?
1.4 REST API in our tutorials

2.0 File Structure

3.0 Setup the Database
3.1 Create Categories Table
3.2 Dump Data For Categories Table
3.3 Products Table
3.4 Dump Data For Products Table
3.5 Connect to database

4.0 Read Products
4.1 Product Object
4.2 Create “read.php” file
4.3 Add Product “read()” method
4.4 Output

5.0 Create Product
5.1 Create create.php file
5.2 Product create() method

6.0 Read One Product
6.1 Create read_one.php file
6.2 Product readOne() method
6.3 Output

7.0 Update product
7.1 Create “update.php” file
7.2 Product update() method

8.0 Delete Product
8.1 Create “delete.php” file
8.2 Product delete() method

9.0 Search Products
9.1 Create “search.php” file
9.2 Create “search()” method
9.3 Output

10.0 Paginate Products
10.1 Create “read_paging.php” file
10.2 Create “core.php” file
10.3 Create “readPaging()” method
10.4 Create “count()” method
10.5 Get “paging” array
10.6 Output

11.0 Read Categories
11.1 Category object
11.2 Create “read.php” file
11.3 Category “read()” method
11.4 Output

12.0 Download Source Codes
13.0 What’s Next?
14.0 Related Tutorials
15.0 Notes

1.0 PROJECT OVERVIEW

1.1 What is REST API?

To define “REST API”, we have to know what is “REST” and what is “API” first. I’ll do my best to explain it in simple terms because REST has a lot of concepts inside of it that could mean a lot of things.

REST stands for “REpresentational State Transfer”. It is a concept or architecture for managing information over the internet. REST concepts are referred to as resources. A representation of a resource must be stateless. It is usually represented by JSON. This post is worth reading: How I Explained REST to My Wife?

API stands for “Application Programming Interface”. It is a set of rules that allows one piece of software application to talk to another. Those “rules” can include create, read, update and delete operations. If you want to learn more, watch the video below and read the musiccritic’s YouTube camera review if you interested on making some videos.

REST API enable your application to cooperate with one or several different applications using REST concepts. If you want to learn more, watch the video below.

1.2 Why do we need REST API?

In many applications, REST API is a need because this is the lightest way to create, read, update or delete information between different applications over the internet or HTTP protocol. This information is presented to the user in an instant especially if you use JavaScript to render the data on a webpage.

1.3 Where REST API is used?

REST API can be used by any application that can connect to the internet. If data from an application can be created, read, updated or deleted using another application, it usually means a REST API is used.

1.4 REST API in our tutorials

A REST API is needed for our JavaScript programming tutorials. This post will help you a lot with that need. Our JavaScript programming tutorials includes the following topics:

But don’t mind those topics for now. We will do it one step at a time. You don’t need to learn all of it as well. Just choose what you need to learn.

Also, please note that this PHP REST API is not yet in its final form. We still have some work to do with .htaccess for better URLs and more.

But one thing is for sure, this source codes is good enough and works for our JavaScript tutorials.

2.0 FILE STRUCTURE

At the end of this tutorial, we will have the following folders and files.
├─ api/
├─── config/
├────── core.php – file used for core configuration
├────── database.php – file used for connecting to the database.
├─── objects/
├────── product.php – contains properties and methods for “product” database queries.
├────── category.php – contains properties and methods for “category” database queries.
├─── product/
├────── create.php – file that will accept posted product data to be saved to database.
├────── delete.php – file that will accept a product ID to delete a database record.
├────── read.php – file that will output JSON data based from “products” database records.
├────── read_paging.php – file that will output “products” JSON data with pagination.
├────── read_one.php – file that will accept product ID to read a record from the database.
├────── update.php – file that will accept a product ID to update a database record.
├────── search.php – file that will accept keywords parameter to search “products” database.
├─── category/
├────── read.php – file that will output JSON data based from “categories” database records.
├─── shared/
├────── utilities.php – file that will return pagination array.

3.0 SETUP THE DATABASE

Using PhpMyAdmin, create a new “api_db” database. Yes, “api_db” is the database name. After that, run the following SQL queries to create new tables with sample data.

3.1 Create Categories Table


CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(256) NOT NULL,
  `description` text NOT NULL,
  `created` datetime NOT NULL,
  `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;

3.2 Dump Data For Categories Table

INSERT INTO `categories` (`id`, `name`, `description`, `created`, `modified`) VALUES
(1, 'Fashion', 'Category for anything related to fashion.', '2014-06-01 00:35:07', '2014-05-30 17:34:33'),
(2, 'Electronics', 'Gadgets, drones and more.', '2014-06-01 00:35:07', '2014-05-30 17:34:33'),
(3, 'Motors', 'Motor sports and more', '2014-06-01 00:35:07', '2014-05-30 17:34:54'),
(5, 'Movies', 'Movie products.', '0000-00-00 00:00:00', '2016-01-08 13:27:26'),
(6, 'Books', 'Kindle books, audio books and more.', '0000-00-00 00:00:00', '2016-01-08 13:27:47'),
(13, 'Sports', 'Drop into new winter gear.', '2016-01-09 02:24:24', '2016-01-09 01:24:24');

3.3 Products Table


CREATE TABLE IF NOT EXISTS `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) NOT NULL,
  `description` text NOT NULL,
  `price` decimal(10,0) NOT NULL,
  `category_id` int(11) NOT NULL,
  `created` datetime NOT NULL,
  `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=65 ;

3.4 Dump Data For Products Table


INSERT INTO `products` (`id`, `name`, `description`, `price`, `category_id`, `created`, `modified`) VALUES
(1, 'LG P880 4X HD', 'My first awesome phone!', '336', 3, '2014-06-01 01:12:26', '2014-05-31 17:12:26'),
(2, 'Google Nexus 4', 'The most awesome phone of 2013!', '299', 2, '2014-06-01 01:12:26', '2014-05-31 17:12:26'),
(3, 'Samsung Galaxy S4', 'How about no?', '600', 3, '2014-06-01 01:12:26', '2014-05-31 17:12:26'),
(6, 'Bench Shirt', 'The best shirt!', '29', 1, '2014-06-01 01:12:26', '2014-05-31 02:12:21'),
(7, 'Lenovo Laptop', 'My business partner.', '399', 2, '2014-06-01 01:13:45', '2014-05-31 02:13:39'),
(8, 'Samsung Galaxy Tab 10.1', 'Good tablet.', '259', 2, '2014-06-01 01:14:13', '2014-05-31 02:14:08'),
(9, 'Spalding Watch', 'My sports watch.', '199', 1, '2014-06-01 01:18:36', '2014-05-31 02:18:31'),
(10, 'Sony Smart Watch', 'The coolest smart watch!', '300', 2, '2014-06-06 17:10:01', '2014-06-05 18:09:51'),
(11, 'Huawei Y300', 'For testing purposes.', '100', 2, '2014-06-06 17:11:04', '2014-06-05 18:10:54'),
(12, 'Abercrombie Lake Arnold Shirt', 'Perfect as gift!', '60', 1, '2014-06-06 17:12:21', '2014-06-05 18:12:11'),
(13, 'Abercrombie Allen Brook Shirt', 'Cool red shirt!', '70', 1, '2014-06-06 17:12:59', '2014-06-05 18:12:49'),
(26, 'Another product', 'Awesome product!', '555', 2, '2014-11-22 19:07:34', '2014-11-21 20:07:34'),
(28, 'Wallet', 'You can absolutely use this one!', '799', 6, '2014-12-04 21:12:03', '2014-12-03 22:12:03'),
(31, 'Amanda Waller Shirt', 'New awesome shirt!', '333', 1, '2014-12-13 00:52:54', '2014-12-12 01:52:54'),
(42, 'Nike Shoes for Men', 'Nike Shoes', '12999', 3, '2015-12-12 06:47:08', '2015-12-12 05:47:08'),
(48, 'Bristol Shoes', 'Awesome shoes.', '999', 5, '2016-01-08 06:36:37', '2016-01-08 05:36:37'),
(60, 'Rolex Watch', 'Luxury watch.', '25000', 1, '2016-01-11 15:46:02', '2016-01-11 14:46:02');

3.5 Connect to database

Create “config” folder. Open that folder and create “database.php” file. Put the following code inside it.

<?php
class Database{
 
    // specify your own database credentials
    private $host = "localhost";
    private $db_name = "api_db";
    private $username = "root";
    private $password = "";
    public $conn;
 
    // get the database connection
    public function getConnection(){
 
        $this->conn = null;
 
        try{
            $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
            $this->conn->exec("set names utf8");
        }catch(PDOException $exception){
            echo "Connection error: " . $exception->getMessage();
        }
 
        return $this->conn;
    }
}
?>

4.0 READ PRODUCTS

4.1 Product Object

Create “objects” folder. Open that folder and create “product.php” file. Put the following code inside it.

<?php
class Product{
 
    // database connection and table name
    private $conn;
    private $table_name = "products";
 
    // object properties
    public $id;
    public $name;
    public $description;
    public $price;
    public $category_id;
    public $category_name;
    public $created;
 
    // constructor with $db as database connection
    public function __construct($db){
        $this->conn = $db;
    }
}

4.2 Create “read.php” file

Create “product” folder. Open that folder and create “read.php” file. Put the following code inside it.

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
 
// include database and object files
include_once '../config/database.php';
include_once '../objects/product.php';
 
// instantiate database and product object
$database = new Database();
$db = $database->getConnection();
 
// initialize object
$product = new Product($db);
 
// query products
$stmt = $product->read();
$num = $stmt->rowCount();
 
// check if more than 0 record found
if($num>0){
 
    // products array
    $products_arr=array();
    $products_arr["records"]=array();
 
    // retrieve our table contents
    // fetch() is faster than fetchAll()
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        // extract row
        // this will make $row['name'] to
        // just $name only
        extract($row);
 
        $product_item=array(
            "id" => $id,
            "name" => $name,
            "description" => html_entity_decode($description),
            "price" => $price,
            "category_id" => $category_id,
            "category_name" => $category_name
        );
 
        array_push($products_arr["records"], $product_item);
    }
 
    echo json_encode($products_arr);
}
 
else{
    echo json_encode(
        array("message" => "No products found.")
    );
}
?>

4.3 Add Product “read()” method

Open “objects” folder. Open “product.php” file. The code on the previous section will not work without the following code in “product.php” file.

Add the following method inside the “Product” class. To make sure you added it correctly, put the code before the last closing curly brace.

// read products
function read(){
 
    // select all query
    $query = "SELECT
                c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
            FROM
                " . $this->table_name . " p
                LEFT JOIN
                    categories c
                        ON p.category_id = c.id
            ORDER BY
                p.created DESC";
 
    // prepare query statement
    $stmt = $this->conn->prepare($query);
 
    // execute query
    $stmt->execute();
 
    return $stmt;
}

4.4 Output

If you develop on localhost and will run the read.php file using this URL: http://localhost/api/product/read.php

You will see an output like this:

By the way, I’m using a Chrome extension called JSONView to make the JSON data readable in the browser.

5.0 CREATE PRODUCT

5.1 Create create.php file

Open “product” folder. Create a new “create.php” file. Open that file and put the following code inside it.

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
 
// get database connection
include_once '../config/database.php';
 
// instantiate product object
include_once '../objects/product.php';
 
$database = new Database();
$db = $database->getConnection();
 
$product = new Product($db);
 
// get posted data
$data = json_decode(file_get_contents("php://input"));
 
// set product property values
$product->name = $data->name;
$product->price = $data->price;
$product->description = $data->description;
$product->category_id = $data->category_id;
$product->created = date('Y-m-d H:i:s');
 
// create the product
if($product->create()){
    echo '{';
        echo '"message": "Product was created."';
    echo '}';
}
 
// if unable to create the product, tell the user
else{
    echo '{';
        echo '"message": "Unable to create product."';
    echo '}';
}
?>

5.2 Product create() method

Open “objects” folder. Open “product.php” file. The previous section will not work without the following code inside the Product (objects/product.php) class.

// create product
function create(){
 
    // query to insert record
    $query = "INSERT INTO
                " . $this->table_name . "
            SET
                name=:name, price=:price, description=:description, category_id=:category_id, created=:created";
 
    // prepare query
    $stmt = $this->conn->prepare($query);
 
    // sanitize
    $this->name=htmlspecialchars(strip_tags($this->name));
    $this->price=htmlspecialchars(strip_tags($this->price));
    $this->description=htmlspecialchars(strip_tags($this->description));
    $this->category_id=htmlspecialchars(strip_tags($this->category_id));
    $this->created=htmlspecialchars(strip_tags($this->created));
 
    // bind values
    $stmt->bindParam(":name", $this->name);
    $stmt->bindParam(":price", $this->price);
    $stmt->bindParam(":description", $this->description);
    $stmt->bindParam(":category_id", $this->category_id);
    $stmt->bindParam(":created", $this->created);
 
    // execute query
    if($stmt->execute()){
        return true;
    }
 
    return false;
    
}

I highly recommend completing this whole tutorial first. But if you want to test the code above, you have to use our JavaScript code. The reason is our JavaScript code is designed to work with this REST API.

Please complete one of our JavaScript programming tutorials. This same concept applies to our “update” and “delete” code.

6.0 READ ONE PRODUCT

6.1 Create read_one.php file

Open “product” folder. Create new “read_one.php” file. Open that file and put the following code.

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Credentials: true");
header('Content-Type: application/json');
 
// include database and object files
include_once '../config/database.php';
include_once '../objects/product.php';
 
// get database connection
$database = new Database();
$db = $database->getConnection();
 
// prepare product object
$product = new Product($db);
 
// set ID property of product to be edited
$product->id = isset($_GET['id']) ? $_GET['id'] : die();
 
// read the details of product to be edited
$product->readOne();
 
// create array
$product_arr = array(
    "id" =>  $product->id,
    "name" => $product->name,
    "description" => $product->description,
    "price" => $product->price,
    "category_id" => $product->category_id,
    "category_name" => $product->category_name
 
);
 
// make it json format
print_r(json_encode($product_arr));
?>

6.2 Product readOne() method

Open “objects” folder. Open “product.php” file. The previous section will not work without the following code inside the Product class.

// used when filling up the update product form
function readOne(){
 
    // query to read single record
    $query = "SELECT
                c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
            FROM
                " . $this->table_name . " p
                LEFT JOIN
                    categories c
                        ON p.category_id = c.id
            WHERE
                p.id = ?
            LIMIT
                0,1";
 
    // prepare query statement
    $stmt = $this->conn->prepare( $query );
 
    // bind id of product to be updated
    $stmt->bindParam(1, $this->id);
 
    // execute query
    $stmt->execute();
 
    // get retrieved row
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
 
    // set values to object properties
    $this->name = $row['name'];
    $this->price = $row['price'];
    $this->description = $row['description'];
    $this->category_id = $row['category_id'];
    $this->category_name = $row['category_name'];
}

6.3 Output

If you develop on localhost and will run the read_one.php file using this URL: http://localhost/api/product/read_one.php?id=60

As you can see in the URL above, an ID parameter value (id=60) has to be passed.

You will see an output like this:

7.0 UPDATE PRODUCT

7.1 Create “update.php” file

Open “product” folder. Create new “update.php” file. Open that file and put the following code inside it.

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
 
// include database and object files
include_once '../config/database.php';
include_once '../objects/product.php';
 
// get database connection
$database = new Database();
$db = $database->getConnection();
 
// prepare product object
$product = new Product($db);
 
// get id of product to be edited
$data = json_decode(file_get_contents("php://input"));
 
// set ID property of product to be edited
$product->id = $data->id;
 
// set product property values
$product->name = $data->name;
$product->price = $data->price;
$product->description = $data->description;
$product->category_id = $data->category_id;
 
// update the product
if($product->update()){
    echo '{';
        echo '"message": "Product was updated."';
    echo '}';
}
 
// if unable to update the product, tell the user
else{
    echo '{';
        echo '"message": "Unable to update product."';
    echo '}';
}
?>

7.2 Product update() method

Open “objects” folder. Open “product.php” file. The previous section will not work without the following code inside the Product class.

// update the product
function update(){
 
    // update query
    $query = "UPDATE
                " . $this->table_name . "
            SET
                name = :name,
                price = :price,
                description = :description,
                category_id = :category_id
            WHERE
                id = :id";
 
    // prepare query statement
    $stmt = $this->conn->prepare($query);
 
    // sanitize
    $this->name=htmlspecialchars(strip_tags($this->name));
    $this->price=htmlspecialchars(strip_tags($this->price));
    $this->description=htmlspecialchars(strip_tags($this->description));
    $this->category_id=htmlspecialchars(strip_tags($this->category_id));
    $this->id=htmlspecialchars(strip_tags($this->id));
 
    // bind new values
    $stmt->bindParam(':name', $this->name);
    $stmt->bindParam(':price', $this->price);
    $stmt->bindParam(':description', $this->description);
    $stmt->bindParam(':category_id', $this->category_id);
    $stmt->bindParam(':id', $this->id);
 
    // execute the query
    if($stmt->execute()){
        return true;
    }
 
    return false;
}

8.0 DELETE PRODUCT

8.1 Create “delete.php” file

Open “product” folder. Create new “delete.php” file. Open that file and put the following code inside it.

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
 
 
// include database and object file
include_once '../config/database.php';
include_once '../objects/product.php';
 
// get database connection
$database = new Database();
$db = $database->getConnection();
 
// prepare product object
$product = new Product($db);
 
// get product id
$data = json_decode(file_get_contents("php://input"));
 
// set product id to be deleted
$product->id = $data->id;
 
// delete the product
if($product->delete()){
    echo '{';
        echo '"message": "Product was deleted."';
    echo '}';
}
 
// if unable to delete the product
else{
    echo '{';
        echo '"message": "Unable to delete object."';
    echo '}';
}
?>

8.2 Product delete() method

Open “objects” folder. Open “product.php” file. The previous section will not work without the following code inside the Product class.

// delete the product
function delete(){
 
    // delete query
    $query = "DELETE FROM " . $this->table_name . " WHERE id = ?";
 
    // prepare query
    $stmt = $this->conn->prepare($query);
 
    // sanitize
    $this->id=htmlspecialchars(strip_tags($this->id));
 
    // bind id of record to delete
    $stmt->bindParam(1, $this->id);
 
    // execute query
    if($stmt->execute()){
        return true;
    }
 
    return false;
    
}

9.0 SEARCH PRODUCTS

9.1 Create “search.php” file

Open “product” folder. Create “search.php” file. Open that file and put the following code.

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
 
// include database and object files
include_once '../config/database.php';
include_once '../objects/product.php';
 
// instantiate database and product object
$database = new Database();
$db = $database->getConnection();
 
// initialize object
$product = new Product($db);
 
// get keywords
$keywords=isset($_GET["s"]) ? $_GET["s"] : "";
 
// query products
$stmt = $product->search($keywords);
$num = $stmt->rowCount();
 
// check if more than 0 record found
if($num>0){
 
    // products array
    $products_arr=array();
    $products_arr["records"]=array();
 
    // retrieve our table contents
    // fetch() is faster than fetchAll()
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        // extract row
        // this will make $row['name'] to
        // just $name only
        extract($row);
 
        $product_item=array(
            "id" => $id,
            "name" => $name,
            "description" => html_entity_decode($description),
            "price" => $price,
            "category_id" => $category_id,
            "category_name" => $category_name
        );
 
        array_push($products_arr["records"], $product_item);
    }
 
    echo json_encode($products_arr);
}
 
else{
    echo json_encode(
        array("message" => "No products found.")
    );
}
?>

9.2 Create search() method

Open “objects” folder. Open “product.php” file. Add the following search() method.

// search products
function search($keywords){
 
    // select all query
    $query = "SELECT
                c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
            FROM
                " . $this->table_name . " p
                LEFT JOIN
                    categories c
                        ON p.category_id = c.id
            WHERE
                p.name LIKE ? OR p.description LIKE ? OR c.name LIKE ?
            ORDER BY
                p.created DESC";
 
    // prepare query statement
    $stmt = $this->conn->prepare($query);
 
    // sanitize
    $keywords=htmlspecialchars(strip_tags($keywords));
    $keywords = "%{$keywords}%";
 
    // bind
    $stmt->bindParam(1, $keywords);
    $stmt->bindParam(2, $keywords);
    $stmt->bindParam(3, $keywords);
 
    // execute query
    $stmt->execute();
 
    return $stmt;
}

9.3 Output

Output should look like the following. Notice the sample search keyword on the URL.

Try this link: http://localhost/api/product/search.php?s=shirt

10.0 PAGINATE PRODUCTS

10.1 Create “read_paging.php” file

On the /api/product/ folder, create “read_paging.php” file.

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
 
// include database and object files
include_once '../config/core.php';
include_once '../shared/utilities.php';
include_once '../config/database.php';
include_once '../objects/product.php';
 
// utilities
$utilities = new Utilities();
 
// instantiate database and product object
$database = new Database();
$db = $database->getConnection();
 
// initialize object
$product = new Product($db);
 
// query products
$stmt = $product->readPaging($from_record_num, $records_per_page);
$num = $stmt->rowCount();
 
// check if more than 0 record found
if($num>0){
 
    // products array
    $products_arr=array();
    $products_arr["records"]=array();
    $products_arr["paging"]=array();
 
    // retrieve our table contents
    // fetch() is faster than fetchAll()
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        // extract row
        // this will make $row['name'] to
        // just $name only
        extract($row);
 
        $product_item=array(
            "id" => $id,
            "name" => $name,
            "description" => html_entity_decode($description),
            "price" => $price,
            "category_id" => $category_id,
            "category_name" => $category_name
        );
 
        array_push($products_arr["records"], $product_item);
    }
 
 
    // include paging
    $total_rows=$product->count();
    $page_url="{$home_url}product/read_paging.php?";
    $paging=$utilities->getPaging($page, $total_rows, $records_per_page, $page_url);
    $products_arr["paging"]=$paging;
 
    echo json_encode($products_arr);
}
 
else{
    echo json_encode(
        array("message" => "No products found.")
    );
}
?>

10.2 Create “core.php” file

This file holds our core configuration like the home URL and pagination variables.

Open the “config” folder and create “core.php” file. Open “core.php” file and place the following code.

<?php
// show error reporting
ini_set('display_errors', 1);
error_reporting(E_ALL);
 
// home page url
 
// page given in URL parameter, default page is one
$page = isset($_GET['page']) ? $_GET['page'] : 1;
 
// set number of records per page
$records_per_page = 5;
 
// calculate for the query LIMIT clause
$from_record_num = ($records_per_page * $page) - $records_per_page;
?>

10.3 Create “readPaging()” method

Open product.php file in /api/objects/ folder. Add the following method inside product class. This method will return a list of records limited to what we set in “$records_per_page” of the previous section.

// read products with pagination
public function readPaging($from_record_num, $records_per_page){
 
    // select query
    $query = "SELECT
                c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
            FROM
                " . $this->table_name . " p
                LEFT JOIN
                    categories c
                        ON p.category_id = c.id
            ORDER BY p.created DESC
            LIMIT ?, ?";
 
    // prepare query statement
    $stmt = $this->conn->prepare( $query );
 
    // bind variable values
    $stmt->bindParam(1, $from_record_num, PDO::PARAM_INT);
    $stmt->bindParam(2, $records_per_page, PDO::PARAM_INT);
 
    // execute query
    $stmt->execute();
 
    // return values from database
    return $stmt;
}

10.4 Create “count()” method

Still in the product class (product.php file), add the following method. The total rows are needed to build the pagination array. It is included in the ‘paging’ computation.

// used for paging products
public function count(){
    $query = "SELECT COUNT(*) as total_rows FROM " . $this->table_name . "";
 
    $stmt = $this->conn->prepare( $query );
    $stmt->execute();
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
 
    return $row['total_rows'];
}

10.5 Get “paging” array

Create “shared” folder.
Open “shared” folder and create “utilities.php” file.
Open “utilities.php” file and put the following code.

<?php
class Utilities{
 
    public function getPaging($page, $total_rows, $records_per_page, $page_url){
 
        // paging array
        $paging_arr=array();
 
        // button for first page
        $paging_arr["first"] = $page>1 ? "{$page_url}page=1" : "";
 
        // count all products in the database to calculate total pages
        $total_pages = ceil($total_rows / $records_per_page);
 
        // range of links to show
        $range = 2;
 
        // display links to 'range of pages' around 'current page'
        $initial_num = $page - $range;
        $condition_limit_num = ($page + $range)  + 1;
 
        $paging_arr['pages']=array();
        $page_count=0;
        
        for($x=$initial_num; $x<$condition_limit_num; $x++){
            // be sure '$x is greater than 0' AND 'less than or equal to the $total_pages'
            if(($x > 0) && ($x <= $total_pages)){
                $paging_arr['pages'][$page_count]["page"]=$x;
                $paging_arr['pages'][$page_count]["url"]="{$page_url}page={$x}";
                $paging_arr['pages'][$page_count]["current_page"] = $x==$page ? "yes" : "no";
 
                $page_count++;
            }
        }
 
        // button for last page
        $paging_arr["last"] = $page<$total_pages ? "{$page_url}page={$total_pages}" : "";
 
        // json format
        return $paging_arr;
    }
 
}
?>

10.6 Output

You should see “paging” in the JSON output.

11.0 READ CATEGORIES

11.1 Create “category.php” file

Open “objects” folder. Create new “category.php” file. Put the following code inside the “category.php” file.

<?php
class Category{
 
    // database connection and table name
    private $conn;
    private $table_name = "categories";
 
    // object properties
    public $id;
    public $name;
    public $description;
    public $created;
 
    public function __construct($db){
        $this->conn = $db;
    }
 
    // used by select drop-down list
    public function readAll(){
        //select all data
        $query = "SELECT
                    id, name, description
                FROM
                    " . $this->table_name . "
                ORDER BY
                    name";
 
        $stmt = $this->conn->prepare( $query );
        $stmt->execute();
 
        return $stmt;
    }
}
?>

11.2 Create “read.php” file

Create new “category” folder. Open that folder and create new “read.php” file inside it. Open “read.php” file and put the following code.

<?php
// required header
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
 
// include database and object files
include_once '../config/database.php';
include_once '../objects/category.php';
 
// instantiate database and category object
$database = new Database();
$db = $database->getConnection();
 
// initialize object
$category = new Category($db);
 
// query categorys
$stmt = $category->read();
$num = $stmt->rowCount();
 
// check if more than 0 record found
if($num>0){
 
    // products array
    $categories_arr=array();
    $categories_arr["records"]=array();
 
    // retrieve our table contents
    // fetch() is faster than fetchAll()
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        // extract row
        // this will make $row['name'] to
        // just $name only
        extract($row);
 
        $category_item=array(
            "id" => $id,
            "name" => $name,
            "description" => html_entity_decode($description)
        );
 
        array_push($categories_arr["records"], $category_item);
    }
 
    echo json_encode($categories_arr);
}
 
else{
    echo json_encode(
        array("message" => "No products found.")
    );
}
?>

11.3 Add Category “read()” method

Open “objects” folder. Open “category.php” file. The previous section’s code will not work without the following code inside the “category.php” file. Add the following method inside the “Category” class.

// used by select drop-down list
public function read(){
 
    //select all data
    $query = "SELECT
                id, name, description
            FROM
                " . $this->table_name . "
            ORDER BY
                name";
 
    $stmt = $this->conn->prepare( $query );
    $stmt->execute();
 
    return $stmt;
}

11.4 Output

If you develop on localhost and will run the read.php file using this URL: http://localhost/api/category/read.php

You will see an output like this:

12.0 DOWNLOAD SOURCE CODES

IF you download any source codes from our AJAX TutorialReact TutorialAngularJS Tutorial or Angular 2 Tutorial , this PHP REST API source code is free and included in their respective packages.

BUT if you need to download this PHP REST API source code only, you can do it using the green download button below.

FEATURES PHP REST API
Create product YES
Read products YES
Read one product YES
Update product YES
Delete product YES
Search products YES
Read & search products with pagination YES
Create category YES
Read categories YES
Read one category YES
Update category YES
Delete category YES
Search categories YES
Read and search categories with pagination YES
FREE email support for 3 months YES
Source code updates via email YES

Email : adityaypi@yahoo.com, Mobile : +91-9555699081

Alternatives to Standard Arduino IDE: Which One To Choose?

Alternatives to Standard Arduino IDE: Which One To Choose?

The Arduino IDE is absolute genius and it’s the perfect tool for a beginner. But, what happens if you want more, if you want an alternative to this, a powerful development tool able to bring you advanced features in code efficiency and speed of development.

With the classical Arduino IDE an expert who wants to specialize in embedded software development can have a dead line in developing and debugging a project.

Another problem that can be solved with an advanced IDE is by writing code in other languages that the standard Arduino programming language. In theory, it’s not possible to write sketches in other language than the C like Arduino code, but if you write a compiler for the chip and define a series of built-in functions, you can transmit the compiled code via the serial port to the Arduino microcontroller. In this case, you can write your code in Python and uploaded it to the Arduino board, which is a good case for a developer with a lot of experience in a particular programming language.

Some of the tools explored in this article are just a front-end putting in the front of avr-gcc and avrdude, while other software are really peace of art with advanced features and a wide range of features.

An alternative to the classical Arduino IDE should have a great collection of libraries, it should able to serial communicate with the bootloader, multiple serial monitors, intellisense, provide multi-tab project where can be written libraries as one single project, and many other options for both novice and advanced users.

Electron

Electron GUI

The Electron IDE is an HTML tool written in NodeJS and HTML and designed to run as an application on your computer. The IDE tools were designed in mind with the idea of mobility. Electron can be accessed from anywhere and is available with all the library attached to the tool.

Codebender

Codebender

Like any good IDE, the Codebender provide you built-in libraries, comprehensive documentation and the freedom to monitor the serial port and upload your sketch to Arduino directly from a browser. The tool uses the clang compiler able to provide very good descriptive warnings when you have done something wrong.

Stino

Stino IDE

Stino is not a complete IDE, it’s just a plugin written for Sublime Text. But even it’s a simple plugin, it can offer a sophisticated text editor code, it can compile the code and upload the sketches in Arduino microcontroller. It is a plugin written in Python and can be run on several operating systems including Windows, Mac OS X, and Linux.

Eclipse

Eclipse

Probably Eclipse is one of the most popular IDE in the world, and most probably, it would offer the most complete features to develop libraries and complex sketches for Arduino boards. The Eclipse can provide a set of features that are not available in all IDE’s such as multi-tab project where can be written libraries at the same time and as one single project. Beside a greater flexibility in coding, the Eclipse is fast, offer great shortcuts, and is clean.

Visual Studio

Visual Studio

Compatible with all versions of the Arduino, the Visual Studio could become your favorite IDE after installation of the Visual Micro plugin designed to support all the features of the Arduino including compiler errors, upload, board selection, or multiple pde/ino files.

Gedit

Gedit [image source]

Fully compatible with Linux OS, the Gedit IDE is a highly customizable Arduino IDE that can make coding fast and fun.

Komodo Edit

Komodo Edit [image source]

With support for a wide variety of programming languages including Python, PHP, Perl, Ruby, Tcl, Javascript, …, the Komodo is a versatile editor that integrates visual debugging, unit testing tool, version control integration, and several other features that let you develop code for Arduino microcontroller.

MariaMole

MariaMole [image source]

With a lot of features such as a workspace enable to work in the same time with multiple projects and a built process configurable, the MariaMole is one of the best open-source IDE designed for professional Arduino developers. The software can be installed only on Windows OS.

Zeus

Zeus

With friendly configure options, the Zeus is a programmers editor with support for a wide range of programming languages and a set of features that can help you develop sketches for Arduino boards.

Atmel Studio

Atmel Studio

The Atmel Studio is already at the six versions and it’s a complete software development environment for Arduino able to provide a simulator, programmer, debugger, and also an editor.

AVR-GCC

AVR-GCC [image source]

AVR-GCC is a free software engineered to provide a series of libraries for use with GCC on Atmel AVR microcontrollers.

CodeBlocks

CodeBlocks

CodeBlocks is a fully compatible IDE for Arduino boards, with a set of features including Arduino core files and libraries, a compiler core files caches to speed up the compiling action, pre-configured AVR compiler toolchain, dedicated project wizard for Arduino development, it’s able to upload HEX to Arduino boards, and it can be integrated with Arduino API-level simulator.

ROBOTC for Arduino

ROBOTC for Arduino [image source]

With support for multiple other robot platforms such as LEGO and VEX robotics, the ROBOTC for Arduino is a complex IDE that support multitasking and has a built-in debugging window to access pin information and more.

Xcode

Xcode

Xcode is built for Mac OS X and is able to provide a lot of features that let you develop sketches for Arduino boards including debugging, git repository management, code snippets, self documentation, and many more features. The software is free.

ArduinoDroid – Arduino IDE

ArduinoDroid – Arduino IDE

Now you can develop Arduino sketches using an Arduino device. This Android application is a complete IDE application that lets you develop, compile and upload your code to the Arduino board.

Notepad ++
Yes, you can use the Notepad++ to develop sketches for Arduino. It cannot be used as a proper IDE with GUI and several other features, it can be used only to edit the .ino file after that you have to use the NPPexec script to run the Arduino IDE and load the sketch.

Install Vqmod in OpenCart manually (2.5+)

Install Vqmod in OpenCart manually (2.5+)

1. Backup or make a duplicate of your existing installed OpenCart files and folders in safe place.

2.Download the latest version Vqmod for Opencart  from:

https://github.com/vqmod/vqmod/releases

3. Using FTP, upload the “vqmod” folder from the zip to the root of your opencart store.Be sure the vqmod folder and the vqmod/vqcache folders are writable (either 755 or 777).

* Also be sure index.php and admin/index.php are writable.

 + If not sure which you need, first try 755.

 + If you get errors about permissions, then try 777.

4. Now, we need to modify two files. One is /index.php and another one is /admin/index.php file.

  Edit your  index.php

  FIND

// Startup

require_once(DIR_SYSTEM . ‘startup.php’);

// Application Classes

require_once(DIR_SYSTEM . ‘library/customer.php’);

require_once(DIR_SYSTEM . ‘library/currency.php’);

require_once(DIR_SYSTEM . ‘library/tax.php’);

require_once(DIR_SYSTEM . ‘library/weight.php’);

require_once(DIR_SYSTEM . ‘library/length.php’);

require_once(DIR_SYSTEM . ‘library/cart.php’);

require_once(DIR_SYSTEM . ‘library/affiliate.php’);

 REPLACE WITH

// vQmod

require_once(‘./vqmod/vqmod.php’);

VQMod::bootup();

// VQMODDED Startup

require_once(VQMod::modCheck(DIR_SYSTEM . ‘startup.php’));

// Application Classes

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/customer.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/currency.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/tax.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/weight.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/length.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/cart.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/affiliate.php’));

 Edit your admin/index.php file

FIND

// Startup

require_once(DIR_SYSTEM . ‘startup.php’);

// Application Classes

require_once(DIR_SYSTEM . ‘library/currency.php’);

require_once(DIR_SYSTEM . ‘library/user.php’));

require_once(DIR_SYSTEM . ‘library/weight.php’);

require_once(DIR_SYSTEM . ‘library/length.php’);

 REPLACE WITH

// vQmod

require_once(‘../vqmod/vqmod.php’);

VQMod::bootup();

// VQMODDED Startup

require_once(VQMod::modCheck(DIR_SYSTEM . ‘startup.php’));

// Application Classes

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/currency.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/user.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/weight.php’));

require_once(VQMod::modCheck(DIR_SYSTEM . ‘library/length.php’));

5. vQmod is now ready to use. Upload desired xml script to ‘vqmod/xml’ folder

6. Load your store homepage and verify it works.

Install Vqmod in Opencart autoinstaller.

Install Vqmod in Opencart  autoinstaller.

1. Backup or make a duplicate of your existing installed OpenCart files and folders in safe place.

2. Download the latest version of Vqmod from:

https://github.com/vqmod/vqmod/releases

look at vqmod for opencart and download latest version.

3. Using FTP, upload the “vqmod” folder from the zip to the root of your opencart store.Make sure vqmod/vqcache folders are writable (either 755 or 777).

* Also be sure index.php and admin/index.php are writable.

 + If not sure which you need, first try 755.

 + If you get errors about permissions, then try 777.

4. Goto http://www.yoursite.com/vqmod/install

5. You should get a success message.( If not, check permissions above and try again.)

6. vQmod is now ready to use. Upload desired xml script to ‘vqmod/xml’ folder

7. Load your store homepage and verify it works.

*DO NOT DELETE THE INSTALL FOLDER!

*YOU MUST RUN THE INSTALLER EVERY TIME YOU UPGRADE OPENCART!!

*THERE IS NO DANGER OF RE-RUNNING THE INSTALLER!

20 Most Demanded & Hot Selling Products in India Online

20 Most Demanded & Hot Selling Products in India Online

Online shopping is a growing trend in India and the numbers of both sellers and buyers are increasing daily by whopping percentages. According to a reliable source, India’s total online sales figure is estimated to reach the US $100 billion by 2020, and apparels would be the largest segment. Clothing even now is a major product of online sales. Other items that are in high demand of online buyers are mobile phones, consumer electronics, footwear, food and health supplements, beauty products, kitchen and home furnishings, fashion accessories, jewellery, books, toys and video games, handmade goods, and online subscriptions.

Products that are most in demand and selling online in India are:

Apparels – Dresses constitute the largest segment of all products sold online in India. Close to 35% of entire revenue generated from online sales comes from apparels and dress materials. Apparels include ladies clothes, men’s clothing, and children’s dresses.

Mobile Phones – Mobile phones are very popular items for sale on eCommerce sites. All brands and models available in the open market are also sold through online sites. For buyers, it is easy to compare among models online before buying a handset of choice.

Books – Buying a book could be really time-consuming if bought from the open market. It is easy for a buyer to locate a seller of their selected titles across eCommerce sites. Educational, fictional, and reference books from Indian as well as overseas publishers are available across eCommerce sites.

Consumer Electronics – eCommerce sites are excellent platforms for buying/selling consumer electronic goods like laptops, tablets, and digital cameras. By 2025 India is expected to become world’s 5th largest consumer durable market.

Footwear – Online is perhaps the best place to search for and buy footwear. The varieties are exhaustive and include shoes, slippers, sandals, and snickers for both ladies and gentlemen. People get to choose among leading brands from across the world.

Jewellery – Buying exclusive jewellery items is often a tough task when bought across counters. The entire process of selecting preferred items and buying from global leaders is done conveniently through eCommerce websites.

Fashion Accessories – It is obvious that after jewellery items, fashion accessories is a popular product category sold online. Belts, hand bags, purses, wallets, head bands, and watches are some of the items bought widely online by Indians.

Beauty Products – Skin care products like cream, lotion, face masks, moisturisers, and perfumes are demanded items that are sold online. Hair care products like gel, cream, colour, shampoo, dryers etc. are widely hot selling products through eCommerce sites.

Computer Hardware, Software, and Accessories – Desktops, disk drives, storage devices, printers, scanners, mouse, and switches are some of the computing devices and accessories that people buy online in India. Market’s leading brands are available to customers at hugely discounted prices.

Video Games – eCommerce sites in India are used to buy video games especially as gifts to children. Games ranging from FIFA World Cup, Grand Theft Auto, Call of Duty, and so on are all available on online sites.

Toys and Games – Online sites are a paradise for kids’ toys. Be it traditional games like snakes-n-ladders, scrabble or current generation remotely operated cars and helicopters, eStores offer every toy of your choice.

Home Decor Items – Drapes, cushion covers, furnishings, flower vases, table mats, tea coasters, rugs, carpets, wall-hangings and so on are available in online stores.

Kitchenware – Online marketplaces are widely used for buying kitchenware like utensils, crockery, cutlery, storage jars, and so on.

Household Appliances – This category of goods including burners, microwave ovens, pressure cookers, washing machines, electric irons, electric kettle, rice cookers, induction plates, etc are popularly sold online.

Sports Goods and Fitness Equipment – Recently these commodities have a lot of online buyers. Cricket bats, tennis and badminton rackets, football and basketballs, carom boards, football boots, cricket gear, hockey sticks, and so on are readily available online.

Baby Care Products – Baby care items is a huge revenue generator when it comes to online sales. Products like soap, powder, cream, oil, linen and diapers are sold extensively on online retail sites. Items like feeding bottles, teether, soothers, and pacifiers are also widely sold.

Food and Health Supplements – A recent addition to online supplies are food and health supplements. Changing life pattern has prompted many Indians to opt for food and health supplements triggering an increased demand for such items. eCommerce sites are the best option for buying such products.

Provisions – Items of daily use like rice, pulses, salt, sugar, cooking oil, spices, and toiletries are now sold online at a lesser price compared to market rates. For people with little time for visiting market regularly, such an online option is splendid.

Handmade Items – Handcrafted items such as costume jewellery, artefacts, scarves, footwear, table mats, purses etc. are gradually gaining popularity as items for online sale in India.

Subscriptions – Subscriptions to digital media like music channels, sports channels, films, and entertainment channels is a new kind of online service being offered to buyers.

eCommerce business in India is thriving and newer items are getting added to the list of commodities every day.

Seven Awesome New Features In Visual Studio 2017

Seven Awesome New Features In Visual Studio 2017

Microsoft developers have been using Visual Studio for their IDE since before .NET was even a thing. Visual Studio is twenty years old this year, and on March 7th, 2017 Microsoft released the latest version of it’s flagship developer product, Visual Studio. With this release are a bunch of new features, improvements, and exciting changes for the beloved Microsoft developer environment. Here are seven features in the new IDE that will excite developers using the development environment.

1. EditorConfig Built In

The EditorConfig project has been available for Visual Studio 2015, but it required you to install a plugin to take advantage of the code-style configuration tool. With the release of 2017, EditorConfig is now built into the IDE. This means you can simply create an .editorconfig file in the root of your solution and check it into your source control. This will get your whole team using the same code format rules (once you can all agree on what they should be).

2. New Visual Studio Installer

Visual Studio 2017 also comes with a new installer. The new installer lets you put together an install of Visual Studio customized to the type of development you’re doing. You can install only the features you will need every day and leave out things that you might never need. This is a great way to keep the IDE small and snappy.

3. Manage Visual Studio Performance

The Manage Visual Studio Performance (under the Help menu) allows you to view the performance of your Visual Studio IDE and can even give you suggestions about extensions that might be impacting the performance of your environment! This includes turning on Lightweight Solution Load, which doesn’t load all the projects in a solution when you open the solution, only when you begin to work in that project. You can still navigate through the code, but the project won’t be loaded until you actually start to work with that project. Awesome!

4. Mobile Development

With Microsoft’s acquisition of Xamarin a few years ago, .NET developers have been enjoying the Xamarin for free as a plugin to Visual Studio 2015. In Visual Studio 2017, it’s now one of the install options when installing Visual Studio! This is a signal that cross-platform, mobile development is now a first-class citizen in your Microsoft development toolbelt!

5. Live Unit Testing

Unit testing has been permeating every development stack over the last decade and Microsoft has followed the trend by making Live Unit Testing available. This means as you change your code, Visual Studio will let you know if your changes will break unit tests, or if they will not be covered by unit tests; in real time.

Running unit tests has almost always been an extra step of your development workflow, but with the Live Unit Testing indicators in your editor popping up as you edit code, it just happens. You can also click on an indicator in the editor and it will show you which tests are exercising that line of code. Unit testing for the win, anyone?

6. Better Javascript Support

With the proliferation of Javascript and Javascript frameworks like Angular, React, Ember, and Vue, it’s no surprise that VSCode has really gleaned a lot of support from the developer community. VSCode has excellent support for Javascript (ES5 and ES6) as well as framework support for Angular and React, including JSX.

Building on that win, Microsoft used the Javascript engine built into VSCode in Visual Studio 2017. This means that all the great support in VSCode is now available without switching out of your Visual Studio editor!

7. Docker Support Built-In

With the adoption of containerization, microservices, and Microsoft’s own work with Docker to help support Windows Containers, it’s no surprise that developers are looking for tighter integration with Docker for their development environments. In Visual Studio 2015 (Update 3), you could install the Visual Studio Tools For Docker and get integrated support for Docker containers. Visual Studio 2017, builds this feature in and when choosing the application template from the File -> New menu, you can choose to turn on Docker support, giving you all the goodness of the plug-in, built in to Visual Studio!

Visual Studio has always been the editor of choice for those writing .NET applications and tapping into the Microsoft ecosystem. It has always had all the tools developers need to be their best, most productive selves. Now Microsoft has done some outstanding work to include and integrate with non-Microsoft tools that developers love to use, as well as help developers discover problems in their code, and improve the performance of their IDE. With the new additions and improvements in Visual Studio 2017, developers should love it even more!

What is an Ecommerce Privacy Policy?

What is an Ecommerce Privacy Policy?

What is an Ecommerce Privacy Policy?

A privacy policy is a statement that explains how a company collects, handles, stores, shares and protects customer’s personal and often sensitive information gathered through their interactions with a website. For an ecommerce store, this is crucial as it not only seen as a sign of credibility and trust, but also ensures that website owners are protected, along with their customers, whilst also adhering to their legal obligations. In the United States, Canada, the United Kingdom, Australia, and New Zealand, a privacy policy on any website that collect data from it’s users is required by law.

Why do you need an Ecommerce Privacy Policy?

Ecommerce store owners need to both limit their risk as well as manage the expectations of their customers to avoid any misunderstandings.

As an ecommerce store, you will undoubtedly be collecting personal information from customers and visitors to your site such as name, age, address, email and credit card details. For obvious reasons, many will want to know that this information is in safe hands so an accessible privacy policy on the website will demonstrate your commitment to security whilst helping to build confidence in your website and business.

A privacy policy also serves as protection from potential lawsuits from customers as well as other businesses. If your ecommerce site is sued, you can show that you have in place a publicly stated privacy policy that clearly declares what you do with the sensitive information collected.

Also, If your store has a payment gateway, they will likely require that you to have a privacy policy before approval is granted.

What should an Ecommerce Privacy Policy include?

A privacy policy should be written in a straightforward language so that it is easy to understand and helps to instill a sense of trust. A policy that is complex and full of technical jargon may scare off visitors to your site. Making your statement easy to read helps build trust. Ensuring that your policy addresses any questions a consumer may have about doing business with you and also addresses any issues that could potentially be of a concern.

A typical privacy policy on an ecommerce site might include:

  • What kind of information is collected from the visitor/customer and why it is required e.g. an email address is required for communication.
  • How the visitor’s/customer’s information is collected and securely stored.
  • Explain if data may be left on a user’s computer, such as cookies (which is often used to track the viewing habits of visitors, make it easier for returning customers to log in and remembers what products were added to the shopping cart. If you offer the option of avoiding cookies, inform them of the website features that will not be available to them as a result.
  • What you will do with the information collected and in what circumstances will it be released.
  • How, if any, of the collected information, is shared or even sold. If shared, it should include an opt-out option for those customers who don’t want their information disclosed to third parties.
  • How customers can review the information a website has collected from them and how they are able to change or delete that information
  • For what period of time is the information held for and who has access to the collected data.
  • The policy’s effective date and a description of any changes since then

How to Generate an Ecommerce Privacy Policy?

If you have the funds, you can hire an expert or a lawyer to help you draft your privacy policy. Many will often look around at competitor sites and tweak the policy to suit their own business. For those that barely have the time on their hands let alone the finances, there are many sites out there that provide privacy policy templates which helps businesses owners to generate one rather quickly and pain-free.

An  eCommerce Privacy Policy should be accurate, clear, concise and easy to find on a website.  Not only does it serve as a means of protection to the your online business in terms of addressing misunderstandings and potential lawsuits, it acts as an effective means of being transparent and credible, keeping you accountable for the sensitive data you collect, and building trust with your customers and visitors to your site.

Soa Technology

How to install missing woocommerce pages

How to install missing woocommerce pages

First Method

This can be done by:

  1. Go to the “System Status” tab on Woocommerce
  2. Click on the “Tools” tab at the top of the page
  3. On that page, the sixth option down is called “Install pages”.
  4. Clicking that will “install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.”


Second Method

WooCommerce > 2.1.x Shortcodes:

[woocommerce_cart] – shows the cart page
[woocommerce_checkout] – shows the checkout page
[woocommerce_order_tracking] – shows the order tracking form
[woocommerce_my_account] – shows the user account page

WooCommerce < 2.1.x Shortcodes:

[woocommerce_edit_account] – Edit account pages
[woocommerce_change_password] – shows the change password page
[woocommerce_view_order] – shows the user account view order page
[woocommerce_logout] – shows the logout page
[woocommerce_pay] – shows the checkout pay page
[woocommerce_thankyou] – shows the order received page
[woocommerce_lost_password] – shows the lost password page
[woocommerce_edit_address] – shows the user account edit address page

Step 1.

Create new page and call it Cart. If cart page already exist WP will automatically call it cart-2 or whatever.

Step 2 Add [woocommerce_cart] shortcode on the page.

Step 3. Publish this page.

Step 4. Now go to woocommerce–>settings—>checkout—> look for check out pages—>under cart looku for cart page . Now save changes.

Zipping and Unzipping Files in UNIX

Zipping and Unzipping Files in UNIX

There are several methods of archiving files and retrieving archives. I recommend using the “zip” function to compress your files for its ease of use and portability. (Files zipped in Unix can be extracted using various tools on various platforms including Windows).

Below I have provided various “unzip” methods. The “right” unzip method depends upon the method used to zip the file. You can tell the zip method by the file extension (e.g., .zip, .tar, .gz, etc.)

Zipping Files Using ZIP

This Unix program is compatible with the zip program for Windows and most other operating systems. To zip files, first have the files uploaded to your server, then log into your account with SSH. Navigate to the directory where the files are that you want to zip (for instance by typing cd www then cd sounds to move to your/www/sounds directory). Then type:

zip myzip file1 file2 file3

This puts the files named file1, file2, and file3 into a new zip archive called myzip.zip.

Unzipping Files

Please note that the unzip method you use is defined by the filename you are trying to unzip. For example, if you are trying to unzip a file called file.tar – you would use the method described in “tar“. Files ending in .gzip or .gz need to be extracted with the method described in “gunzip“.

Zip

If you have an archive named myzip.zip and want to get back the files, you would type:

unzip myzip.zip

Typing zip or unzip by itself will give you a usage summary, showing nearly all the options available.

Tar

To extract a file compressed with tar (e.g., filename.tar), type the following command from your SSH prompt:

tar xvf filename.tar

Basically, this command means that you will see the file “explode”, so don’t worry when you see your screen scrolling wildly. It also means that you will see any errors in the archive.

Gunzip

To extract a file compressed with gunzip, type the following:

gunzip filename_tar.gz

then if you receive no errors, type:

tar xvf filename_tar

Example :
$ zip -r backupimg.zip profileimage (Make zip of profileimage folder and subfolder)
$ zip -r backupimg.zip . (Make zip of current folder and subfolder)

Install Latest Git on Centos

Install Latest Git on Centos

  1. Download with yum.yum install git
  2. If you need the latest, try to remove git first.yum remove git
  3. Change directory to tmp.cd /tmp
  4. Download the latest git https://github.com/git/git/releases. Example we use 2.16.curl -O -L https://github.com/git/git/archive/v2.16.0-rc2.tar.gz
  5. Extract tar.tar -zxvf v2.16.0-rc2.tar.gz
  6. Execute as root.
    cd git-v2.16.0
    make clean
    make configure
    sudo make install
  7. Check git version.git --version