Wednesday, May 9, 2018

Json Content Importer Short Code for Vcommission

If you are building your coupon website using wordpress, and want to automatically display the coupons list from website vcomission, then you can use jsoncontentimporter plugin.
First download and install jsoncontentimporter plugin and install and activate it.
Then use following short code in the page - post where you want to display vcommission coupons list:
[jsoncontentimporter url=https://tools.vcommission.com/api/coupons.php?apikey=xyz]
<img src = "{store_image}">
<a href="{link}" target="_blank" rel="noopener">{coupon_title}</a>
{coupon_code}
[/jsoncontentimporter]


This is the simple example, you can show more fields using {field name}

Friday, March 16, 2018

Make website live with godaddy

To make website live with godaddy, first register or sign in to godaddy. Registration is free.
Now search for some unique domain name for your website, and select the available domain name for your website. There are many offers to purchase domain names. Now after having your domain name, go to website builder to design a beautiful website. Godaddy provides simple drag and drop tools to design your website without having technical knowledge.
To build your website, click on website then click website builder. Godaddy is providing one month free trail to build and test your website. After free trial is over you have to renew it to continue with your website else you may cancel it at any time.

Tuesday, July 19, 2016

Design a Website for login & registration system using PHP and MySQL.

If anyone plans to design a website for his institute or organisation, then first he would like to design a page for user login and registration system. Everyone wants that only registered users may access features of the website. So I am going to design a very simple login and registration form using PHP & MySQL.
So to start designing login & registration form for users first create a database for users.
First run the XAMPP server, and then start Apache and MySQL services from the XAMPP Control Panel.
Now go to your favorite browser and type: http://localhost/phpmyadmin/
A page will open like this:


Now click on new to create a new database, under the caption Create Database, give the name of your database, for example dbtest and select Collation accordingly. Now click on create to create a new database. After creating database, create a table for the database. Let the table name be users and required number of columns be 4.  Now give the name to columns created in the table as id, name, email, and password. Select the type and give length for each columns name. After giving name to each column and filling other fields click on save.
 
When you click on save new database is created for users.  

 

Now close the browser.
Now after creating database, it’s time to create index, signup, login and logout pages. We also need a dbconnect file to connect to our database whenever needed.

Code for dbconnect.php is:
<?php
//connect to mysql database
$con = mysqli_connect("localhost", "root", "", "dbtest") or die("Error " . mysqli_error($con));
?>
_____________________________________________________________________________________

The code for index.php file is:                                                                         
<?php
session_start();
include_once 'dbconnect.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Login & Registration form</title>
</head>
<body>
<center><?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 } ?></center>                                     
</body>
</html>

_____________________________________________________________________________________
Code for register.php:
<?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>

<body>
                                <!-- menu items -->       

<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>
</body>
</html>


_____________________________________________________________________________________


Code for login.php:
<?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>

<body>
<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">           
<center>New User? <a href="register.php">Sign Up Here</a></center>
</div>
</div>
</div>


</body>
</html>

_____________________________________________________________________________________

Code for logout.php:
<?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");
}
?>

_____________________________________________________________________________________


Put all the above files in the htdocs folder. After that open your favorite browser and type 127.0.0.1, your login & registration website will open. You can test your website on your local computer before making it live.

Tuesday, July 12, 2016

Portable Server

We can install XAMPP on flash drive or pen drive and can use it as a portable server. We can use it on the go server at our laptop or any other computer at office or home. So there is no need to stick with one computer to use server for the development of your website.

To install XAMPP server on your flash drive, just download the .exe file from URL: https://www.apachefriends.org/index.html. Now connect the pen drive to your computer and click on the XAMPP installer file.




Click on next to continue installation.
Select all the components you want to install on your system.

 

Now create a new folder in you pen drive and give it any name, for example Myserver. Now select the path to install the server files.

 

Click on next.

 
Click on next to continue the installation.

 

After finishing the installation, it will ask to start the XAMPP control Panel. Select the option and click on finish to complete the installation.

The XAMPP control panel looks like:



Start Apache and other components as per your need.
Type http://localhost or 127.0.0.1 in your browser. You will see the default page like:

 


The default index file in the folder D:\xampp\htdocs\ will open. You can keep it or delete/replace it with your own file. Now your portable server is ready to use on any computer. Just plugin your pen drive on which xampp is installed to any computer or laptop and start Apache and other components as per your need. To open XAMPP control panel open the folder Myserver and click on the file xampp-control.

Wednesday, June 8, 2016

Creating new website and handling its database on your local system.



In my last two posts :Install XAMPP server, test and run a website on your own local system and Host more than one website  from your own local system., I told you about installing a server on your system and testing a simple website on your own local computer. Now in this post we will learn about creating a website for users and handling its database from your system.
To begin with first we create database for our website. We are creating a website for users to enter username, email id and contact number. Let the name of database be userd, and table name is users. First go to your web browser and type the following: http://localhost/phpmyadmin/



New web page will open: to create database, click on new ,

Enter the name of database as userd, and select collation as utf8mb4_unicode_ci and click on create.
Now after creating database, it will ask for table name, number of fields in table. Under create table enter name of table as users and Number of columns as 3. Click on go.



Now enter the name of columns: username, e_id, contact.



Click on save. Now our database has been created.
To create a website named www.mytestweb.com, first create a new folder named mytestweb in hdocs folder at C:\XAMPP\htdocs.
Now open the file httpd-vhosts file with note pad or other editor which is lying in the folder:
C:\XAMPP\apache\conf\extra
Add the following lines at the end of file:

<VirtualHost *:80>  
DocumentRoot "C:\XAMPP\htdocs\mytestweb"
ServerName www.mytestweb.com
</VirtualHost>

Save the file and close it.
To local host the website we have to add www.mytestweb.com to hosts file in the folder:
C:\Windows\System32\Drivers\etc
Open the hosts file with note pad or any other editor and add the following lines at the end of the file:
127.0.0.1 www.mytestweb.com
Save the file and close it.
Now add the following php files to the mytestweb folder which is lying in C:\XAMPP\htdocs.
Let us start with creating a registration page in php. In this registration page we will accept some data like username, email_id, contact_no from user and store it in our data base. Following is the php code for registration page:

<html>
<body>
<h1>Welcome To mytestweb.com</h1>
<br>
<h2>Please Register Your Self at our wesite for free</h2>
<br>Please Enter Your Details:
<form action="insert.php" method="post">
User Name: <input type="text" name="username" /><br><br>
Email ID : <input type="text" name="e_id" /><br><br>
Contact Number: <input type="int" name="contact" /><br><br>
<input type="submit" />
</form>
</body>
</html>

Copy the above code and paste in new text document file and save it as register.php.
In the above code, insert.php file is used to insert the data into our database.



Code for insert.php:

<html>
<body>
<?php
 // Create connection
$conn = new mysqli('localhost','root','');
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// this will select the Database userd
mysqli_select_db($conn,"userd");
// create INSERT query
$sql="INSERT INTO users (username, e_id, contact) VALUES ('$_POST[username]','$_POST[e_id]','$_POST[contact]')";
if ($conn->query($sql) === TRUE) {
    echo "Thanks for Entering Your Details";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
mysqli_close($conn);
?>
<br><a href = 'index.php'>Click Here For Home Page</a>
</body>
</html>

Every website have an index.php or home.php file. So indext.php file in our case is:

<html>
<body>
<body style="background-color:orange">
<h1>Welcome to Mytestwebsite</h1>
<br>
<a href="register.php"> Register yourself here: </a><br>
<br>
OR
<br>
<br>
<a href="details.php"> Click here to see the list of registered user details</a>

</body>
</html>

Now show the details entered by users:
Code for details.php file is as follows:

<html>
<body>
<?php

// Create connection
$conn = new mysqli('localhost','root','');

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

mysqli_select_db($conn,"userd");

$sql = "SELECT * FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
echo"<table border = '1'>
<tr>
<th>User Name:</th>
<th>Email ID: </th>
<th>Contact Number</th>
</tr>";
echo "<tr>";
echo "<td>" . $row["username"]."</td>";
echo"<td>"  . $row["e_id"]."</td>";
echo"<td>" . $row["contact"]."</td>";
echo"</tr>";
echo"</table>";
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>
<br>

</body>
</html>

Go to your favorite browser and enter the website address : http://www.mytestweb.com/
Following screen will open:


First enter some data by clicking on the link: Register yourself here: 



Enter your details and click on submit.

You will see a thanks message like:


To go on home page click on the link Click Here For Home Page

On the home screen click on the link Click here to see the list of registered user details to see the list of users registered.

Host more than one website from your own local system.



In my last post: Install XAMPP server, test and run a website on your own local system. I told you about installing a server on your system and creating and testing a simple website from your own system. That was to host a single website from one system, now we learn about hosting multiple websites from one system. This can be done by Virtual Host. Virtual Host means to host more than one website on single machine.  To host multiple websites, you have to create separate folders for each website in the htdocs folder.  Like if you want to websites mysite1, mysite2…….., create folders like
C:\XAMPP\htdocs\mysite1, C:\XAMPP\htdocs\mysite2 …………
Now create individual index.php files for mysite1, mysite2…….
Next tell apache to host multiple websites, for this we have to configure httpd-vhosts file in apache which is in the folder C:\XAMPP\apache\conf\extra. Open the file with note pad or other editor. This file will look like :



Now add the following lines in the last of file without deleting anything from the file:

<VirtualHost *:80>  
DocumentRoot "C:\XAMPP\htdocs\mysite1"
ServerName www.mysite1.com
</VirtualHost>

<VirtualHost *:80>  
DocumentRoot "C:\XAMPP\htdocs\mysite2"
ServerName www.mysite2.com
</VirtualHost>

Now the httpd-vhosts file looks like:


After having done editing with apache, we have to modify host file in the directory C:\Windows\System32\Drivers\etc\hosts
Add the following lines in the last of file:
127.0.0.1 www.mysite1.com
127.0.0.1 www.mysite2.com


After updating the hosts file and httpd-vhost file, restart all the services of XAMPP. And now you have different websites hosted from your own computer with your own server. 

Install XAMPP server, test and run a website on your own local system.


First of all to create and host a website from your own local computer you need a server installed on your system. XAMPP is a light weight server which can be easily downloaded and installed on your system in few minutes. There are different versions of XAMPP server and are compatible with different versions of windows, one should download accordingly.  To download XAMPP server open the URL: https://www.apachefriends.org/index.htmlXAMPP stands for Cross-Platform (X), Apache (A), MariaDB (M), PHP (P) and Perl (P). XAMPP is an open source package, means anyone can download and use it on his system for free.



Click on XAMPP for windows to download the XAMPP version for windows. Download the exe file and double click on it to install.



Click on next to continue installation.
Select all the components you want to install on your system.



Click on next.

  
Select the folder in which you want to install the server.



Click on next.



Click on next to continue the installation.


After finishing the installation, it will ask to start the XAMPP control Panel.

The XAMPP control panel looks like:


Start Apache and other components as per your need.
Type http://localhost or 127.0.0.1 in your browser. You will see the default page like:



The default index file in the folder c:\xampp\htdocs\  will open. You can keep it or delete/replace it with your own file. The files in htdocs folder are default and only for learning purpose. You may delete these files.

Now open a new notepad file and type the following:
<?php
   echo ‘Welcome to Mysite’;
?>
And save the file as index.php and save it in the folder:
 c:\xampp\htdocs\ (or whichever directory you installed XAMPP in).
Again type localhost in your browser and you will see the message “Welcome to Mysite.”
Now to use your custom name instead of localhost you have to do some changes in the hosts file residing in the folder:
C:\Windows\System32\Drivers\etc
Copy the hosts file to the desktop or other directory and open it with notepad or other editor.
It will look like:



After the last line: 127.0.0.1 localhost,
add this new line :127.0.0.1 www.mysite.com.


Now replace the file in folder C:\Windows\System32\Drivers\etc\hosts with the hosts file saved on Desktop.
Important Note: Don’t ever try 127.0.0.1 www.google.com or other real website name in this hosts file as this is to map IP address to a website on your computer. So whenever you try this using website name like google and try to open google in your browser, the webpage saved in  folder  c:\xampp\htdocs\ will open and not the real website of google.



Now type www.mysite.com in your browser and see the magic. Whatever changes you make in the file c:\xampp\htdocs\index.php it will reflect in your local website www.mysite.com.
This way you can test your  HTML or PHP files and can see how your website looks.

Now to see your website from other device or computer connected in your local network, just type your IP address in the browser of that system.