Tuesday 17 March 2015

How to PING API Web Server To Check Its Working Or Not

How to PING API Web Server To Check Its Working Or Not

Introduction
In this article we will create a small utility using C# that tells us whether our API server is up or down.
Purpose Our purpose is to check the API server so, we can make a request for our resources. It is recommended that before making any request to the server (API server in our case), we should ensure that our server is ready and up to handle our requests.
Throughout this article we will create a tiny utility to satisfy that purpose.
Requirements So, what do we require? We just want to know the status of our Web API server.
Creation of Utility Let's create a simple console app that tells us the status of our API server:
Open Visual Studio

Create a C# console application, name it "knowserverstatus" .
How To Perform API integration

Add the following method:
public static void ServerStatusBy(string url)    
public static void ServerStatusBy(string url)    

{    
   Ping pingSender = new Ping();    
   PingReply reply = pingSender.Send(url);    
   Console.WriteLine("Status of Host: {0}", url);    
   if (reply.Status == IPStatus.Success)    
   {    
      Console.WriteLine("IP Address: {0}", reply.Address.ToString());    
      Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);    
      Console.WriteLine("Time to live: {0}", reply.Options.Ttl);    
      Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);    
      Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);    
   }    
   else    
   Console.WriteLine(reply.Status);    
}  

Recommended Articles:

  1. How To Make Mail in SQL Server Database 

  2. How to Create Widget using Wordpress  

Do not forget to add following namespace:

using System.Net.NetworkInformation; 
Call this method from main: 
 
Console.Write("Enter server url:");    
var url = Console.ReadLine();    
Console.Clear();    
ServerStatusBy(url);    
Console.ReadLine(); 
Run it and we will get the following output
How to ping web servers using C# How to integrate API in C# List of API Web service Tools
How to ping web servers using C# How to integrate API in C# List of API Web service Tools

Elaboration of code

Let's elaborate on the preceding code. Here PING sends an Internet Control Message Protocol (ICMP) request to the requested server host/URL and waits to receive the response back. If the value of Status is success then that means our server is up and running.
Here PingReply returns all properties, described as:
Property Description
Address Gets the address of Host
Buffer Gets the buffer of data received, its an array of bytes
PingOption It handles how data transmitted
RoundTrip Gets the number of milliseconds to send ICMP echo request
Status Gets the status of request. If not Success , in other words Host is not up

Conclusion
In this article we discussed all about the PingReply class and using this class, we created a utility to know the status of our server.
Posted on 07:59 / 0 comments / Read More

Thursday 12 February 2015

CRUD Operations in CakePHP

CRUD Operations in CakePHP

CakePHP is an open source PHP framework built around Model-View-Controller (MVC). We will begin to create a small application that will do some basic Create, Read, Update, Delete (CRUD) operations on our database.
  • Model: It manages the data. It stores into and retrieves from the database.

  • View: It is for the presentation and is responsible for displaying the data provided by the model in a specific format.

  • Controller: Handles the model and view layers to work together. 
View, add, edit and delete functionality. You can download the full tutorial here.
 
 

Step1: The Database Structure

To create a database and table:
  1. CREATE TABLE IF NOT EXISTS `demomovies` (    
  2.     
  3.    `id` char(36) NOT NULL,    
  4.     
  5.    `title` varchar(255) DEFAULT NULL,    
  6.     
  7.    `genre` varchar(45) DEFAULT NULL,    
  8.       
  9.    `rating` varchar(45) DEFAULT NULL,    
  10.     
  11.    `format` varchar(45) DEFAULT NULL,    
  12.     
  13.    `length` varchar(45) DEFAULT NULL,    
  14.     
  15.    `created` datetime DEFAULT NULL,    
  16.     
  17.    `modified` datetime DEFAULT NULL,    
  18.     
  19.    PRIMARY KEY (`id`)    
  20.     
  21. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;  
  1. INSERT INTO `demomovies` (`id`, `title`, `genre`, `rating`, `format`, `length`, `created`, `modified`) VALUES    
  2.     
  3. ('54d9874c-ae74-4451-b54a-14f01bafaffa''secondfirst''sdfsd''4.5''sdf''sdf''2015-02-10 05:21:32''2015-02-10 05:34:01'),    
  4.     
  5. ('54d98aa7-d65c-40cd-8b7f-14f01bafaffa''second''firest''5.4''dsf''sadf''2015-02-10 05:35:51''2015-02-10 05:35:51');    
Step 2: Create Model, Controller and View
Create a demomovie.php file and save it in the following path.
C:\xampp\htdocs\cakephp_example\app\Model
Open the demomovie.php file.

 
  1. <?php  
  2. class Demomovie extends AppModel {  
  3.   
  4.    var $name = 'demomovie';  
  5.   
  6.    var $validate =array(  
  7.     
  8.       'title' =>array(  
  9.   
  10.          'alphaNumeric' =>array(  
  11.   
  12.             'rule' => array('minLength',2),  
  13.   
  14.             'required' => true,  
  15.   
  16.             'message' => 'Enter should be minimum 2 only')  
  17.   
  18.          ),  
  19.   
  20.          'genre' =>array(  
  21.   
  22.             'alphaNumeric' =>array(  
  23.   
  24.                'rule' => array('minLength',4),  
  25.   
  26.                'required' => true,  
  27.   
  28.                'message' => 'Enter should be minimum 4 only')  
  29.   
  30.          ),  
  31.   
  32.          'rating' =>array(  
  33.   
  34.             'alphaNumeric' =>array(  
  35.   
  36.             'rule' => array('minLength',2),  
  37.   
  38.             'required' => true,  
  39.   
  40.             'message' => 'Enter should be minimum 4 only')  
  41.   
  42.          )  
  43.   
  44.       );  
  45.   
  46.    }  
  47.   
  48. ?>    
  49.    
Save it.
Controller
Create DemomoviesController.php and save it in the following path.
C:\xampp\htdocs\cakephp_example\app\Controller

Open DemomoviesController.php files and paste in the following code.
  1. <?php  
  2. class DemomoviesController extends AppController {  
  3.   
  4.    public $components = array('Session');  
  5.   
  6.    public function index()  
  7.   
  8.    {  
  9.   
  10.       $movies = $this->Demomovie->find('all');  
  11.   
  12.       $this->set('demomovies'$movies);  
  13.   
  14.    }  
  15.   
  16.    public function add()  
  17.   
  18.    {  
  19.   
  20.       if (!emptyempty($this->data)) {  
  21.   
  22.          $this->Demomovie->create($this->data);  
  23.   
  24.          if ($this->Demomovie->save()) {  
  25.   
  26.             $this->Session->setFlash('The movie has been saved');  
  27.   
  28.             $this->redirect(array('action' => 'add'));  
  29.   
  30.          } else {  
  31.   
  32.             $this->Session->setFlash  
  33.   
  34.             ('The movie could not be saved. Please, try again.');  
  35.   
  36.          }  
  37.   
  38.       }  
  39.   
  40.    }  
  41.   
  42.    public function delete($id = null)  
  43.   
  44.    {  
  45.   
  46.       if (!$id) {  
  47.   
  48.          $this->Session->setFlash('Invalid id for movie');  
  49.   
  50.          $this->redirect(array('action' => 'index'));  
  51.   
  52.       }  
  53.   
  54.       if ($this->Demomovie->delete($id)) {  
  55.   
  56.       $this->Session->setFlash('Movie deleted');  
  57.   
  58.       } else {  
  59.   
  60.          $this->Session->setFlash(__('Movie was not deleted',  
  61.   
  62.          true));  
  63.   
  64.       }  
  65.   
  66.       $this->redirect(array('action' => 'index'));  
  67.   
  68.    }  
  69.   
  70.    function edit($id = null) {  
  71.   
  72.       if (!$id && emptyempty($this->data)) {  
  73.   
  74.          $this->Session->setFlash('Invalid movie');  
  75.   
  76.          $this->redirect(array('action' => 'index'));  
  77.   
  78.       }  
  79.   
  80.       if (!emptyempty($this->data)) {  
  81.   
  82.          if ($this->Demomovie->save($this->data)) {  
  83.   
  84.             $this->Session->setFlash('The movie has been saved');  
  85.   
  86.             $this->redirect(array('action' => 'index'));  
  87.   
  88.          } else {  
  89.   
  90.          $this->Session->setFlash('The movie could not be saved. Please, try again.');  
  91.   
  92.       }  
  93.   
  94.    }  
  95.   
  96.    if (emptyempty($this->data)) {  
  97.   
  98.       $this->data = $this->Demomovie->read(null, $id);  
  99.   
  100.    }  
  101.   
  102. }  
  103.   
  104. function view($id = null) {  
  105.   
  106.    if (!$id) {  
  107.   
  108.       $this->Session->setFlash('Invalid movie');  
  109.   
  110.       $this->redirect(array('action' => 'index'));  
  111.   
  112.    }  
  113.   
  114.    $this->set('movie'$this->Demomovie->findById($id));  
  115.   
  116.    }  
  117.   
  118. }  
  119.   
  120. ?>  
 View
Create a Demomovies folder.
 
C:\xampp\htdocs\cakephp_example\app\View
Create add.ctp , edit.ctp , index.ctp , view.ctp files
C:\xampp\htdocs\cakephp_example\app\View\Demomovies

Set route
Open routes.php with the following pat.
  1. Router::connect('/'array('controller' => 'demomovies''action' => 'index''home'));  
Save it.
The following are screen shots of view, add, edit, and delete.
View

Add


Edit

After edit form:

Posted on 19:58 / 0 comments / Read More

Tuesday 10 February 2015

Multiple Joins in Codeigniter in PHP

Multiple Joins in Codeigniter in PHP

This code show Multiple Joins in Codeigniter.You can use this code in your projects to ease your work.

Earn Degree,PhD in counseling education


  1. $this->db->select('*');  
  2. $this->db->from('TableA AS A');// I use aliasing make joins easier  
  3. $this->db->join('TableC AS C''A.ID = C.TableAId''INNER');  
  4. $this->db->join('TableB AS B''B.ID = C.TableBId''INNER');  
  5. $result = $this->db->get();  
The join function works like this:

  1. join('TableName''ON condition''Type of join');
The equivalent SQL:

  1. $this->db->select('*');  
  2. $this->db->from('TableA AS A');// I use aliasing make joins easier  
  3. $this->db->join('TableC AS C''A.ID = C.TableAId''INNER');  
  4. $this->db->join('TableB AS B''B.ID = C.TableBId''INNER');  
  5. $result = $this->db->get();  
 
Posted on 20:35 / 0 comments / Read More

Thursday 5 February 2015

How to insert multiple excel sheet data using PHP and MySQL

How to insert multiple excel sheet data using PHP and MySQL

Earn Degree

How to insert multiple excel sheet data using PHP and MySQL

Code Here:

  1. <?php  
  2.    define ("DB_HOST""localhost"); // set database host  
  3.    define ("DB_USER""root"); // set database user  
  4.    define ("DB_PASS",""); // set database password  
  5.    define ("DB_NAME","api_db"); // set database name  
  6.    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");  
  7.    $db = mysql_select_db(DB_NAME, $linkor die("Couldn't select database");  
  8.    set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');  
  9.    include 'PHPExcel/IOFactory.php';  
  10.    $uploadedStatus = 0;  
  11.    if ( isset($_POST["submit"]) ) {  
  12.       if ( isset($_FILES["file"])) {  
  13.          //if there was an error uploading the file  
  14.          if ($_FILES["file"]["error"] > 0) {  
  15.             echo "Return Code: " . $_FILES["file"]["error"] . "<br />";  
  16.          }  
  17.          else {  
  18.             $imagename = $_FILES["file"]["name"] ;  
  19.             move_uploaded_file($_FILES["file"]["tmp_name"], $imagename);  
  20.             try {  
  21.                $objPHPExcel = PHPExcel_IOFactory::load($imagename);  
  22.             } catch(Exception $e) {  
  23.             
  24.               die('Error loading file "'.pathinfo($imagename,PATHINFO_BASENAME).'": '.$e->getMessage());  
  25.             }  
  26.             $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);  
  27.             $arrayCount = count($allDataInSheet); // Here get total count of row in that Excel sheet  
  28.             for($i=2;$i<=$arrayCount;$i++){  
  29.                $userName = trim($allDataInSheet[$i]["A"]);  
  30.                $userMobile = trim($allDataInSheet[$i]["B"]);  
  31.                insertTable= mysql_query("insert into tbl_users (usr_name, usr_email) values('".$userName."', '".$userMobile."');");  
  32.             }  
  33.             echo "Please check your database ";  
  34.          }  
  35.       } else {  
  36.             echo "No file selected <br />";  
  37.          }  
  38.       }  
  39. ?>  
  40. <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">           <table width="600" style="margin:115px auto; background:#f8f8f8; border:1px solid #eee; padding:10px;">  
  41.       <tr><td colspan="2" style="font:bold 21px arial; text-align:center; border-bottom:1px solid #eee; padding:5px 0 10px 0;">Demo for multiple data store using execel sheet</t  
  42.          <tr><td colspan="2" style="font:bold 15px arial; text-align:center; padding:0 0 5px 0;">Data Uploading System</td></tr>  
  43.             <tr>  
  44.                <td width="50%" style="font:bold 12px tahoma, arial, sans-serif; text-align:right; border-bottom:1px solid #eee; padding:5px 10px 5px 0px; border-right:1px solid #eee;">Select file</td>  
  45.                <td width="50%" style="border-bottom:1px solid #eee; padding:5px;">            
  46.                <input type="file" name="file" id="file" /></td>  
  47.             </tr>  
  48.          </tr>  
  49.          <td style="font:bold 12px tahoma, arial, sans-serif; text-align:right; padding:5px 10px 5px 0px; border-right:1px solid #eee;">Submit</td>  
  50.          <td width="50%" style=" padding:5px;"><input type="submit" name="submit" /></td>  
  51.       </tr>  
  52.    </table>  
  53. </form> 
Posted on 01:11 / 1 comments / Read More

Monday 2 February 2015

How to Create Widget using Wordpress


Introduction
Widget is a small block that performs a specific function. You can add widgets in sidebars also known as widget areas on your web page. Widgets is easy to install and the list of widget available widgets and widget areas by going to the Appearance » Widgets 
Earn Degree
Default widgets including categories, tag cloud, navigation menu, calendar, search, recent posts etc. If you drag the recent posts widget in a widget area, then it will contain a list of recent posts in Wordpress.
How to create widget
Step 1: To open function.php file and paste below code.

  1. // Creating the widget  
  2.   
  3. class wpb_widget extends WP_Widget {  
  4.   
  5.    function __construct() {  
  6.   
  7.       parent::__construct(  
  8.   
  9.       // Base ID of your widget  
  10.   
  11.       'wpb_widget',  
  12.   
  13.       // Widget name will appear in UI  
  14.   
  15.       __('WPBeginner Widget''wpb_widget_domain'),  
  16.   
  17.       // Widget description  
  18.   
  19.       array'description' => __( 'Sample widget based on WPBeginner Tutorial''wpb_widget_domain' ), )  
  20.   
  21.       );  
  22.   
  23.    }  
  24.   
  25.    // Creating widget front-end  
  26.   
  27.    // This is where the action happens  
  28.   
  29.    public function widget( $args$instance ) {  
  30.   
  31.       $title = apply_filters( 'widget_title'$instance['title'] );  
  32.   
  33.       // before and after widget arguments are defined by themes  
  34.   
  35.       echo $args['before_widget'];  
  36.   
  37.       if ( ! emptyempty$title ) )  
  38.   
  39.       echo $args['before_title'] . $title . $args['after_title'];  
  40.   
  41.       // This is where you run the code and display the output  
  42.   
  43.       echo __( 'Hello, World!''wpb_widget_domain' );  
  44.   
  45.       echo $args['after_widget'];  
  46.   
  47.    }  
  48.   
  49.    // Widget Backend  
  50.   
  51.    public function form( $instance ) {  
  52.   
  53.       if ( isset( $instance'title' ] ) ) {  
  54.   
  55.          $title = $instance'title' ];  
  56.   
  57.          }else {  
  58.   
  59.             $title = __( 'New title''wpb_widget_domain' );  
  60.   
  61.          }  
  62.   
  63.          // Widget admin form  
  64.   
  65.       ?>  
  66.   
  67.       <p>  
  68.   
  69.       <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>  
  70.   
  71.       <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />  
  72.   
  73.       </p>  
  74.   
  75.    <?php  
  76.   
  77. }  
  78.   
  79. // Updating widget replacing old instances with new  
  80.   
  81. public function update( $new_instance$old_instance ) {  
  82.   
  83.       $instance = array();  
  84.   
  85.       $instance['title'] = ( ! emptyempty$new_instance['title'] ) ) ? strip_tags$new_instance['title'] ) : '';  
  86.   
  87.       return $instance;  
  88.   
  89.    }  
  90.   
  91. // Class wpb_widget ends here  
  92.   
  93. // Register and load the widget  
  94.   
  95. function wpb_load_widget() {  
  96.   
  97.    register_widget( 'wpb_widget' );  
  98.   
  99.    }  
  100.   
  101. add_action( 'widgets_init''wpb_load_widget' );  
  102.  
  103.  


  104. Step 2: Check widget in  widgets area.

Posted on 19:04 / 0 comments / Read More

Tuesday 23 December 2014

How To Hash Password Using PHP

We will learn what is the significance of a hash for a secure password in PHP. Password hashing is one of the most basic security issues while developing an application or website, we usually accept some value from the user as in a password, without hashing we store it in the Applications database, the question arises in the scenario of someone stealing the application database then perhaps you lose that application connection to users and many other things.

Earn Degree
For such kinds of scenarios we use hashing, by applying a hashing algorithm to our password before storing it in the database, we ensure that attackers will not determine the original password, while still being able to compare the resulting hash to the original password in the future.   

Topics
  • About hash
  • About slat
  • Code
About HashingHashing is an algorithm. An algorithm for protecting our user inputted password from attackers. There are some algorithms available named MD5, SH1 and SHA256 that are very fast and efficient. With some modern techniques and computer equipment, it has become trivial for the In PHP to use "brute force" to get the stored (hashed) encrypted value. PHP 5.5 provides a native password hashing API that safely handles both hashing and the verifying of the password in a secure manner. For verifying the password we mostly use the crypt() function. We need to take care of preventing timing attacks by using a constant time-sharing comparison. Neither the "==" and  "===" operators nor strcmp(). A password_verify() is used to verify.

About SaltA cryptographic salt is data that is applied during the hashing process in order to eliminate the possibility of output being looked up in a list of per-calculated pairs of hashes and their input, this is known as a rainbow table.

Salt is a "bit" of additional data that makes our hashes safe and secure from attackers. The use of a salt makes it impossible to find the result. password_hash() That creates a random salt if one will not be provided and this is generally the easiest and most secure approach.

Code
  1.  <?php  
  2. echo password_hash("hello", PASSWORD_DEFAULT)."\n";  
  3. ?>  
  4.    
How To Hash Password Using PHP

When we use password_hash() or crypt(),  the return value includes the salt as part of the generated hash. This value will be stored in the database, since it includes information about the hash function that was used and can be given directly to password_verify() or crypt() when we verify the password.  
SummaryIn this article we learned how to be secure when we use passwords. Salt, Hashing and their work flow. Thanks for reading this article.
Posted on 19:51 / 1 comments / Read More

Thursday 18 December 2014

How To Make Mail in SQL Server Database

How To Make Mail in SQL Server Database

In this post, I am detailing how you can set up data source email within SQL machine.
Data source email is utilized to deliver the e-mail utilizing SQL Machine. it really is replacing SQL Mail associated with SQL Machine previously edition. Data source Email has its own improvement more than SQL Mail. Data source Email is founded on SMTP (Simple Email Move Protocol) as well as extremely fast as well as dependable where by SQL Mail is founded on MAPI (Messaging Software Development Interface). Data source email depends upon Support Agent which means this support should be allowed with regard to Data source Email. Data source Email could be protected for more protection.

Setup Database Mail

You can find the database mail in sql server under the management like this:
sqlServer1.png
Right click on database mail and select configure database mail.

sqlServer2.png
sqlServer3.png
sqlServer4.png
sqlServer5.png
sqlServer6.png
sqlServer7.png
sqlServer8.png
sqlServer9.png
sqlServer10.png
sqlServer11.png
sqlServer12.png

To Send a mail from Database Mail

sqlServer13.png
sqlServer14.png
If you want to send mail from the code:
use msdb
go
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'TestingDatabaseMail',
@recipients = 'praveshsinghfaq@gmail.com',
@subject = 'Test Mail',
@body = 'Testing E-Mail';
sqlServer15.png


Posted on 19:41 / 0 comments / Read More
 
Copyright © 2015. Free IT Codes | IT Projects . All Rights Reserved
Home | Company Info | Contact Us | Privacy policy | Term of use | Widget | Site map
Design by Herdiansyah . Published by Borneo Templates