Pages

Monday 15 July 2013

PNR Status by Web Scripting Method using c#.net

Introduction:

 Here I will explain how to check PNR Status through programmatically using c#.net

 PNR STATUS


                     Indian railway is one of the largest railway network and employer in the world, most of the people visit indian railway website to check their PNR status of the ticket,Today we will create a widgit,Ths widgit provide you a easy and clean interface to check your Passenger Name Record ( PNR ) status of your IRCTC reservation . To check your PNR status simply copy this code and paste your visual studio enter your 10 digit PNR number and hit the Get PNR Status button.

First, we need to design the page like below.
after that write the c# method for request/response pnr status.

public string GetPNRStatus(string sPNR)
{
//indianrail url
string URI = http://www.indianrail.gov.in/cgi_bin/inet_pnrstat_cgi.cgi;
//passing the pnr status to indian rail with help of querystring
string Parameters = Uri.EscapeUriString("lccp_pnrno1=" + sPNR + "&submitpnr=Get Status");
//creating the http request with help of httpwebrequest
System.Net.
HttpWebRequest req = (HttpWebRequest)System.Net.WebRequest.Create(URI);
//HTTP POST Headers
req.ContentType = "application/x-www-form-urlencoded";
//HTTP Host Name
req.Host = "www.indianrail.gov.in";
/You can use your own user-agent.
req.UserAgent =
"Mozilla/5.0 (compatible; MSIE 7.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0) DELL;Venue Pro";

req.Headers.Add(
HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");

req.Headers.Add(
HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");

req.KeepAlive =
true;
req.Referer =
"http://www.indianrail.gov.in/pnr_stat.html";
req.Accept =
"text/plain";
req.Method=
"POST";
//Byte size calculation before sending request.
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
//Requesting the pnr status from indianrail.gov.in
System.IO.
Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();

//get response from indianrail.gov.in
System.Net.
WebResponse resp = req.GetResponse();
if (resp == null) return null;
System.IO.
StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd();
}
after writing this method we can call button click event like below.
protected void BtnPNRStatus_Click(object sender, EventArgs e)
{
try
{
Response.Write(GetPNRStatus(txtPNRNumber.Text));
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

Finally we got result, see the results below.



 Note: This method involves scraping the Indian Railways website, as they do not have an API in place yet. This is purely for educative purposes, and is most likely illegal to implement in a full-feature application.


 

Wednesday 10 July 2013

Difference between heredoc and nowdoc

Introduction

In this article I will explain the difference between Heredoc and Nowdoc in PHP. Heredoc and Nowdoc are two methods for defining a string. A third and fourth way to delimit strings are the Heredoc and Nowdoc; Heredoc processes $variable and special character but Nowdoc does not processes a variable and special characters. First of all I will discuss Heredoc.

Heredoc allows a multi-line string to be easily assigned to variables or echoed. Heredoc text behaves just like a string without the double quotes.

Example

The following is a simple example of Heredoc:

<?php
class ABC
{
    public $ABC;
    public $bar;
    function ABC()
    {
        $this->ABC = 'ABC';
        $this->bar = array('Bar1', 'Bar2', 'Bar3');
    }
}
$ABC = new ABC();
$name = 'Tom';
echo <<<EOT
My name is "$name". I am printing some $ABC->ABC.
Now, I am printing some {$ABC->bar[1]}.
This should not print a capital 'A': \x41
EOT;
?>

OutPut:


Next, I will discuss Nowdoc. Nowdoc is an identifier with a single quote string and Nowdoc is specified similarly to a Heredoc but no parsing is done inside a Nowdoc. A Nowdoc is identified with the same "<<<" sequence used for heredoc. When you use Nowdoc then you cannot pass the space character.

Note Nowdoc is supported only PHP 5.3

Example
<?php
class ABC
{
    public $ABC;
    public $bar;
    function ABC()
    {
        $this->ABC = 'ABC';
        $this->bar = array('Bar1', 'Bar2', 'Bar3');
    }
}
$ABC = new ABC();
$name = 'Tom';
echo <<<'EOT'
My name is "$name". I am printing some $ABC->ABC.
Now, I am printing some {$ABC->bar[1]}.
This should not print a capital 'A': \x41
EOT;
?>
OutPut:




 

Tuesday 9 July 2013

Access/Invoking Asp.Net WebService from Php Client


Creating and consuming webservices in asp.net is an easy task with the help of Visual Studio. Although most of the scenarios I worked with were always with asp.net applications consuming asp.net web services, which makes things even easier. This week however I learned something new when I had to invoke a PHP client application to connect to my asp.net webservices.

Asp.Net Web Service

/// <summary>
/// Summary description for WebService1/// </summary>[WebService(Namespace = "http://tempuri.org/")][
WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.
ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService]public class WebService1 : System.Web.Services.WebService{
[
WebMethod]
public string HelloWorld(string StrValue){

return StrValue;}
}

And I host this web service in my localhost using IIS, and when I ping this url in explorer I have wsdl like this.

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
      <s:element name="HelloWorld">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="StrValue" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="HelloWorldResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="HelloWorldSoapIn">
    <wsdl:part name="parameters" element="tns:HelloWorld" />
  </wsdl:message>
  <wsdl:message name="HelloWorldSoapOut">
    <wsdl:part name="parameters" element="tns:HelloWorldResponse" />
  </wsdl:message>
 
  <wsdl:portType name="WebService1Soap">
    <wsdl:operation name="HelloWorld">
      <wsdl:input message="tns:HelloWorldSoapIn" />
      <wsdl:output message="tns:HelloWorldSoapOut" />
    </wsdl:operation>
  
  </wsdl:portType>
  <wsdl:binding name="WebService1Soap" type="tns:WebService1Soap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="HelloWorld">
      <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
   
  </wsdl:binding>
  <wsdl:binding name="WebService1Soap12" type="tns:WebService1Soap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="HelloWorld">
      <soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>   
  </wsdl:binding>
  <wsdl:service name="WebService1">
    <wsdl:port name="WebService1Soap" binding="tns:WebService1Soap">
      <soap:address location="http://localhost:7777/WebService1.asmx" />
    </wsdl:port>
    <wsdl:port name="WebService1Soap12" binding="tns:WebService1Soap12">
      <soap12:address location="http://localhost:7777/WebService1.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

As you can see there’s nothing to it.

The PHP code is not much harder once you know, First you have to have test the requested url is working or not which has the webservices infrastructure for PHP. Then you code a simple client to access our service.

<?php
$client = new SoapClient("http://localhost:7777/WebService1.asmx?wsdl");
$strRestult = $client->HelloWorld(array('StrValue' => 'ICS'))->HelloWorldResult;
echo "Welcome to " . $strRestult;

?>

Then run this have get a result from .Net WebService.





Friday 5 July 2013

Php Installation

Necessary Setup:


           To begin working with PHP you must first have access to either of the following:

  • A web hosting account that supports the use of PHP web pages and grants you access to MySQL databases. If you do not have a host, but are interested in signing up for one, we recommend that you first read our Web Host Guide to educate yourself about web hosting and avoid getting ripped off.
  • Have PHP and MySQL installed on your own computer. Read this lesson thorougly for more information on installing PHP.
Although MySQL is not absolutely necessary to use PHP, MySQL and PHP are wonderful complements to one another and some topics covered in this tutorial will require that you have MySQL access.

Installing Php:

For those who are experienced enough to do this yourself, simply head over to PHP.net - Downloads and download the most recent version of PHP.
However, if you are like most of us, you will most likely want to follow a guide to installing PHP onto your computer. These guides are kindly provided by PHP.net based on the operating system that you are using.
Installing MySQL:

As we mentioned before, MySQL is not a requirement to use PHP, however they often go hand in hand.
Visit MySQL's MySQL Installation Guide for help on installing MySQL.

Installation troubles:

If you have any installation troubles feel free to ask.

Content Management System

What is CMS?

        CMS  means Content Management System . CMS  is easily  to  use  and maintains and powerful features set allows you to quickly and easily create and manage an entire website.CMS is a web application you run on your web server to help facilitate creating a website.


           CMS Made Simple is an open source ( GPL) package.PHP Content Management System is  allows creation, editing, publishing, organizing and managing of content of a website.For a small website, adding and deleting a page manually is simple.CMS is easy way the process of adding and modifying new content to a webpage.

           PHP content management system which allows publishing and editing and deleting  content as well as site management from an easy-to-use administration page.In PHP CMS is a SEO optimized, professional grade content management system .

Examples of MOST USED CMS IN PHP

1)Wordpress:

          WordPress is a free and open source blogging tool and a content management system (CMS) based on PHP and MySQL. It has many features including a plug-in architecture and a template system

FOUNDER: Matthew Charles Mullenweg

2)Drupal:

            Drupal is a free software package that allows you to easily organize, manage and publish your content, with an endless variety of customization.

FOUNDER: Dries Buytaert   

3)Joomla:
               
           Joomla is an award-winning content management system (CMS), which enables you to build Web sites and powerful online applications.

FOUNDER:   Joomla Leadership Team 

E-Commerce Best CMS

1)Magento:

            
            Magento is a feature-rich eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store.

FOUNDER:IT was launched on March 31, 2008. It was developed by Varien (now Magento Inc).


Feel free to ask if you have any suggessions or questions?
 


Php Tutorial

Php Tutorial

            PHP is the widely-used  Server side Scripting Language and it is free Software to download and use. PHP is perfectly suited for Web development and can be embedded directly into the HTML code.you have to learn php in this php tutorial small php example and small php programming  code is  available.
Start learning PHP now!



What is Php?

              Taken directly from PHP's home, PHP.net, "PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly."

              This is generally a good definition of PHP. However, it does contain a lot of terms you may not be used to. Another way to think of PHP is a powerful, behind the scenes scripting language that your visitors won't see!When someone visits your PHP webpage, your web server processes the PHP code. It then sees which parts it needs to show to visitors(content and pictures) and hides the other stuff(file operations, math calculations, etc.) then translates your PHP into HTML. After the translation into HTML, it sends the webpage to your visitor's web browser.

What's it do!

It is also helpful to think of PHP in terms of what it can do for you. PHP will allow you to:
  • Reduce the time to create large websites.
  • Create a customized user experience for visitors based on information that you have gathered from them.
  • Open up thousands of possibilities for online tools. Check out PHP - HotScripts for examples of the great things that are possible with PHP.
  • Allow creation of shopping carts for e-commerce websites.
What you should know?

Before starting this tutorial it is important that you have a basic understanding and experience in the following:
  • HTML - Know the syntax and especially HTML Forms.
  • Basic programming knowledge - This isn't required, but if you have any traditional programming experience it will make learning PHP a great deal easier
Tutorial Overview

              This tutorial is aimed at the PHP novice and will teach you PHP from the ground up. If you want a drive-through PHP tutorial this probably is not the right tutorial for you.

              Remember, you should not try to plow through this tutorial in one sitting. Read a couple lessons, take a break, then do some more after the information has had some time to sink in.