Showing posts with label webservice. Show all posts
Showing posts with label webservice. Show all posts

Wednesday, March 18, 2015

Breadcrumbs introduction and brief for SEO

The section inside the website or a web page that helps user to understand their exact location within the site are breadcrumbs, they appear close to the top of the page. Breadcrumbs are extremely helpful to users in large scale websites like eCommerce or articles achieve where they will refer to these breadcrumbs and assure they are at right place where they needed to be.



They are graphical control element used for navigation purpose in user interface; it allows user and visitors to track their state or location with current document or application. Below is a sample example about breadcrumb.

breadcrumb photo
Breadcrumb
Now if to talk about above picture, any of us can say the navigation way for the page that is shown in example. In it "Home" and "Actress"  are clickable links that a user can click on and get navigated to respective pages. Let us see a few more description in this topic, Here I have presented the graphical demonstration for easy understanding.
breadcrumb

Being very easily understandable and navigation able, breadcrumb are very vita while SEO. As SEO is done for making site user friendly and search engine friendly. 


Wednesday, December 24, 2014

Restful webservice Application in PHP

Firstly let me be clear about the environment and requirements for the project. The required materials for the project are:

  1. IDE fully supportive for PHP
  2. A local Web Server (WAMP,XAMPP etc.) as per your O/S and easiness. 
  3. Google Chrome web browser with an extinction Advance rest Client.
Now if we have all this things with us we are ready to start. The basic functioning that our "Restfull Web Service " will be registering a user, loging a user along with some other functionalities that shall be brodened later.



Now lets create a database as per our requirement . Create a database "rest". Inside SQL insert the below code :

USE rest;
CREATE TABLE rest (username varchar(15) , password varchar (15), email varchar (50), status varchar (80));


The first thing we need to do is; create a folder "rest"  inside your web server after that lets create a file"DB_Config" that will enable us to connect to our database.

(DB_Config.php)

 <?php  
 /**  
  * Created by PhpStorm.  
  * User: wao  
  * Date: 1/26/2015  
  * Time: 4:28 PM  
  */  
 $mysql_hostname = "localhost"; /* replace it with your host [In most case the host name is same "localhost"] */  
 $mysql_user = "root"; /*It is a default username in your MySQL if you have set manual users please replace "root"*/  
 $mysql_password = "";/*It is a default password in your MySQL if you have set manual password please replace ""*/  
 $mysql_database = "rest"; /* insert your database name here*/  
 $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)  
 or die("Opps some thing went wrong, couldnot connect to the database");  
 mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong, cannot select database");  
 ?> 


After we are done with DB_Config.php file we will now create a next file namely "signup.php" 


 <?php  
 // Include confi.php  
 include_once('DB_Config.php');  
 if($_SERVER['REQUEST_METHOD'] == "POST"){  
  // This code gets data  
  $username = isset($_POST['username']) ? mysql_real_escape_string($_POST['username']) : "";  
  $email = isset($_POST['email']) ? mysql_real_escape_string($_POST['email']) : "";  
  $password = isset($_POST['password']) ? mysql_real_escape_string($_POST['password']) : "";  
  $status = isset($_POST['status']) ? mysql_real_escape_string($_POST['status']) : "";  
  // Below script inserts data into data base  
  $sql = "INSERT INTO `rest`.`users` (`ID`, `username`, `email`, `password`, `status`) VALUES (NULL, '$username', '$email', '$password', '$status');";  
  $qur = mysql_query($sql);  
  if($qur){  
  $json = array("status" => 1, "msg" => "Done User created!");  
  }else{  
  $json = array("status" => 0, "msg" => "Error creating user!");  
  }  
 }else{  
  $json = array("status" => 0, "msg" => "Request method not accepted");  
 }  
 @mysql_close($conn);  
 /* Output header */  
  header('Content-type: application/json');  
  echo json_encode($json);  
  ?>  

After finishing with "signup.php" we wil now create another file "login.php"


 <?PHP  
 include_once('DB_Config.php');  
 if($_SERVER['REQUEST_METHOD'] == "POST"){  
  // Get data  
  $username = isset($_POST['username']) ? mysql_real_escape_string($_POST['username']) : "";  
  $password = isset($_POST['password']) ? mysql_real_escape_string($_POST['password']) : "";  
  // Insert data into data base  
  $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";  
  $qur = mysql_query($sql);  
  $count=mysql_num_rows($qur);  
  if($count == 1)  
  {  
  $json=array("status"=>1, "msg"=>"user logged in");  
  }else{  
  $json=array("status"=>0, "msg"=>"user not loggedin!either password doesnot match or u have other error");  
  }  
 }else{  
  $json = array("status" => 0, "msg" => "Request method not accepted");  
  }  
 @mysql_close($conn);  
 /* Output header */  
  header('Content-type: application/json');  
  echo json_encode($json);  
  ?> 

     Open Google Chrome and run Advance Rest Client , and please refer to the snapshot for checking your webservice restfull application.


Download Source Code
    
restful web service php

Tuesday, December 23, 2014

PDO in PHP

PHP Data Object is what PDO stands for, PDO defines a lightweight, consistent interface that is used for accessing database in PHP. No data functions can be performed or brought in use only using PDO but a database specific PDO driver should be used instead to access a database server. PDO is latest and it is only available  after PHP 5.1 version. PDO makes it easier and convenient and provides a data-access abstraction layer this helps using multiple database  with same function query to fetch the data.

Databases supported by PDO :

Driver name
Supported databases
PDO_CUBRID
Cubrid
PDO_DBLIB
FreeTDS / Microsoft SQL Server / Sybase
PDO_FIREBIRD
Firebird
PDO_IBM
IBM DB2
PDO_INFORMIX
IBM Informix Dynamic Server
PDO_MYSQL
MySQL 3.x/4.x/5.x
PDO_OCI
Oracle Call Interface
PDO_ODBC
ODBC v3 (IBM DB2, unixODBC and win32 ODBC)
PDO_PGSQL
PostgreSQL
PDO_SQLITE
SQLite 3 and SQLite 2
PDO_SQLSRV
Microsoft SQL Server / SQL Azure
PDO_4D
4D


Below here is a simple example of PDO :

Example:

PHP Code(connection.php)

 <?php  
 $dsn = 'mysql:dbname=ft;host=localhost;port=3306';  
 $username = 'root';  
 $password = '';  
 try {  
   $db = new PDO($dsn, $username, $password);  
   if ($db) {  
     echo "Successfully connected to database.";  
   }  
 } catch (PDOException $e) {  
   echo "Could not connect with MySql:" . $e->getMessage();  
 }  
 ?>  
 PHP PDO Insert:  
 PHP Script (insert.php):  
 <?php  
 $dsn = 'mysql:dbname=try;host=localhost;port=3306';  
 $username = 'root';  
 $password = '';  
 try {  
   $db = new PDO($dsn, $username, $password);  
 } catch (PDOException $e) {  
   echo "Could not connect with MySql:" . $e->getMessage();  
 }  
 //PDO Class  
 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
 $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);  
 //PDO Statement Class  
 $sth = $db->prepare("INSERT INTO test(id, message) VALUES (:id, :mgs)");  
 $data = array(  
   ':id' => 'first',  
   ':msg' => 'this is first message'  
 );  
 echo $sth->execute($data);  
 ?> 
File to get or fetch records ( PHP PDO getting record):

PHP Script (records.php)
 <?php  
 $dsn = 'mysql:dbname=try;host=localhost;port=3306';  
 $username = 'root';  
 $password = '';  
 try {  
   $db = new PDO($dsn, $username, $password);  
 } catch (PDOException $e) {  
   echo "Could not connect with MySql:" . $e->getMessage();  
 }  
 //PDO Class  
 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
 $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);  
 //PDO Statement Class  
 $sth = $db->query("SELECT * FROM test");  
 print_r($sth->fetch());  
 ?> 

Monday, December 22, 2014

A brief History in PHP

Introduction on PHP
In this rapid world of Information and Technology PHP is one of the most used server-side scripting and programming language, almost 50% of web programmers uses PHP for their server side. This language is easy to learn and yet developed for purpose of web development. Though it also has some general usage. In the year 2013 PHP was found to be installed in more than 240 million websites which is more than 39 percent. Rasmus Lerdorf  Developed this dynamic language in 1994, its latest version was lately released in 18 December 2014 and it’s 5.6.4 version. PHP can be used along with HTML  for various operations in web applications that makes it robust  and popular. All codes coded in PHP are interpreted by PHP interpreter.

History of PHP
In the year 1994 PHP development was started by Rasmus Lerdorf, he started writing a series of CGI (Common Gateway Interface) binaries in the programming language called C. After working it for some time he added the ability to work with web forms feature and he also added the feature to communicate with databases. Several PHP versions have been released till now with different added features. In year 1995 on 8th of June PHP version 1.0 was released, this came out to be the popular version and on 1997 the second version was released and introduced to market , this version contained more features compared to version 1.0. Version 3.0 on 20th October 2000 was released after and so and so today we have version 5.6.4 of PHP. Version 4.1 in 2002 had a feature in it called SuperGlobals , and in the same year version 4.3 introduced command-line interface for the purpose of supplementing the CGI.

Features of PHP that make it so popular and robust language are listed below:

·        HTTP authentication with PHP: It is possible to use the header () function to send an Authentication required.
Cookies: PHP supports HTTP cookies; these are the mechanism for storing data in browser for tracking purpose.

Sessions: PHP supports session to preserve certain data who has frequent access; it enables more customized applications with best security.

Dealing with XForms:  XForms are used in wide variety of platform and browsers or even non-traditional media such as PDF documents, PHP deals with this variation of web forms.

Handling file uploads: PHP handles file uploads in wide range, single, multiple etc. mostly post and put methods are used in file handling.

Using remote files:  You can use HTTP and FTP URLs with most of the functions that tae a filename as a parameter as long as allow_url_fopen is enabled in php.ini.

Connection handling: In PHP always connection status is maintained, there are 4 possible states 0=Normal , 1=Aborted , 2=Timeout , 3= Aborted and Timeout.

Persistent Database Connections: These connections are those links which do not close when the execution of your scripts ends.

Safe Mode: PHP safe mode troubleshoots the shared-server security problem.

Command line uses:  The main focus of Command line uses is to enable developing shell application with PHP.

Garbage Collection: PHP keeps reference count for all variables and destroy them(in most cpnditions) as soon as this reference counts to zero.

DTrace Dynamic Tracing: DTrace can trace operating system behavior and user program execution.


Monday, October 20, 2014

Conflicts for which language to choose HTML to HTML5 as a starter !

As a starter, I in my personal view would refer to learn HTML. As After learning HTML you can easily update your studies to HTML5. Most of the things in HTML and HTML5 are in common but though many extra features have been added in HTML5 to HTML.
Before starting I would like to go a little back on history and let you get some historical information on HTML (Hyper Text Markup Language). HTML was introduced by a physicist Tim Berners-Lee in 1989, so HTML is not more older then 26years. It was a memo wrote by Tim burners-Lee proposing an internet based hypertext system that leaded later to development of HTML. HTML is the markup language that browsers use to compose and interpret texts, images, audio, video materials in web pages. The first introduced public description about the language was a document called ”HTML Tags”.
After a little history we will now leave the rest history to b history and further move on with the details about HTML. In HTML document all things are well formatted by tags. Tags are sort of building blocks in HTML documents. HTML tags has some major functions like:
1.       It specifies the document type to the browser.
2.       Tag is the container for all other elements in HTML.
Tags in HTML are included inside “<>” and is necessary to close the tag after its uses is over. Eg: <html> </html>, here <html> opens the tag whereas </html> closes the tag. Unless you include your tag inside <> the tag is not supposed to be tag. In HTML basically “four” tags are commonly used. These tags are the most necessary tags in HTML.
1.       <HTML>
2.       <HEAD>
3.       <TITLE>
4.       <BODY>
Note: case do not matters you can write your tags in either lower case i.e. <html> or in upper case <HTML> that makes no difference.
Now that we have known a little about HTML and its background I will be providing a simple example about how to write your first HTML document and run it in your computer. However there are various platforms like Adobe Dreamweaver, Google Web Designer etc. but in my view it would be great if you start learn with notepad or notepad++ and you need most is a browser you can use any of them.
Steps to your first HTML document :
   1. Create a folder named HTML in your desktop.
             2. Open a notepad and save the file inside your HTML folder in your desktop naming it my_first_page or anything you feel convenient of.
       3. After saving the file, open it again and start typing the code below.
<html>
<head>
<title>
my first page
</title>
<head>
<body>
My First Page !
</body>
<html>
      4. The file might have been saved with .txt extinction in it now rename the file in my_first_page.html or my_first_page.htm.
      5. Right click on the file and go to open with option and select your browser(as shown in picture).
     6. You just have created your first web page ”Congrats”.