Tuesday, 15 February 2011

PHP

<html>
<body>

<?php
echo "Hi there!";
$txt="Hi there!"; //a variable containing a string
echo $txt

$txt1="Hi!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2; //the concatenation operator

$var_name = value;
$d=date("D");
if ($d=="Fri") echo "Have a nice weekend!"; //if statement

$d=date("D");
if ($d=="Fri")
  echo "Have a nice weekend!";
else
  echo "Have a nice day!"; // if..else statement

$d=date("D");
if ($d=="Fri")
  echo "Have a nice weekend!";
elseif ($d=="Sun")
  echo "Have a nice lazy Sunday!";
else
  echo "Have a good day!"; // if...elseif....else Statement

$cars[0]="Mini Cooper";
$cars[1]="Rover";
$cars[2]="BMW";
$cars[3]="Toyota";
echo $cars[0] . " and " . $cars[1] . " are BRITISH cars."; // Numeric array: Mini Cooper and Rover are BRITISH cars.

$ages['James'] = "37";
$ages['John'] = "44";
$ages['Anthony'] = "43";

echo "James is " . $ages['JAMES'] . " years old."; // JAMES is 37 years old.
$x=array("ding","dang","dong");
foreach ($x as $value)
  {
  echo $value . "<br />";
  } // ding
       dang
       dong

function writeName()
{
echo "Michael James Snyder";
}

echo "My name is ";
writeName();
?> // PHP Function: My name is Michael James Snyder

function writeName($fname)
{
echo $fname . " Snyder.<br />";
}

echo "My name is ";
writeName("Michael James");
echo "My sister's name is ";
writeName("Wendy");
echo "My brother's name is ";
writeName("John");
?> // My name is Michael James Snyder.
      My sister's name is Wendy.
      My brother's name is John Snyder.

Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old. // Form:
// Welcome John!
// You are 44 years old.

$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow); // Tomorrow is 2011/02/16

?>



<html>

/* HTML creates user interfaces, but to create dynamic websites, or to transfer data from a Web page to another database program, use PHP Hypertext Processor (www.php.net). Dynamic web pages need to respond to the user, and need to retrieve information off a Web page and store it in a database, such as when you type your credit card number to buy something off a Web site. PHP is a popular programming language for running programs on Web servers (those computers responsible for displaying and retrieving information from Web pages, such as shopping data. PHP programs can run only on Web pages under many different operating systems. PHP mimics the syntax from C and Perl. */
<body>
/* If a comment extends over multiple lines,
It’s easier to use these types of comment
symbols instead. */
<?php // single line comment: The <?php and ?> tags define the beginning and ending of a PHP program.
echo “<h1>Greetings from PHP.</h1>”;
</body>
?>
# This is the end of the PHP program
</html>
// PHP program scripts are stored in a file that ends with the .php file extension.

$VariableName = value; // Declare any type of data; a variable holds a string or a number
VariableName
$MyAge // variable 1 is case sensitive
$myage // variable 2 is case sensitive

$myage = 38; //$myage variable is initially set to 38
$yourage = $myage; // the $myage variable also contains the value of 38
$myage = 103; // this line now stores the value 103 into the

$myage = 38;
$yourage = &$myage;
//Reference a variable with the ampersand symbol (&)
// allow a variable to contain identical data without specifically assigning those values.
// The $yourage variable references the $myage variable
// whatever value the $myage variable contains from now on will automatically get stored in the $yourage variable.
$myage = 103; //the $myage variable now contains the value of 103, so the $yourage variable contains 103 too.

if (condition) {
Command;
}

if (condition) {
Command;
}
else {
Command;
}


if (condition1) {
Command;
}
elseif (condition2) {
Command;
}
elseif (condition3) {
Command;
}


switch (expression) {
// use regular expressions that are built-into PHP to implement a finite automaton search algorithm
case value1:
Command;
break;
case value2:
Command;
break; // include the break command to tell the computer when to exit out of the SWITCH statement.
default:
Command;
}

if (expression == value1) {
// use regular expressions that are built-into PHP to implement a finite automaton search algorithm
Command;
}
elseif (expression == value2) {
Command;
}
else {
Command;
}
switch (expression) {
// use regular expressions that are built-into PHP to implement a finite automaton search algorithm
case value1: // check if a variable matches multiple values
case value2: // stack multiple case statements
Command;
break;
case value3:
case value4;
Command;
break;
default:
Command;
}
if (expression == value1) || (expression == value2) {
Command;
}
else if (expression == value3) || (expression == value4) {
Command;
}
else {
Command;
}

for (startvalue; endvalue; increment) { // a loop that repeats for a fixed number of times
Command; // loop until a certain Boolean condition becomes True
}

for ($i = 1; $i <= 4; $i++) { // The FOR loop runs four times, set the Start value to 1 and the End value to 4
Command;
}
while (condition) { // I don’t know how many times I need to repeat commands here
Command; // If the condition is True, the loop runs at least once. If this condition is False, the loop doesn’t run.
}

function functionname (Parameter list)
// this is a subprogram that solves a specific task
// The Parameter list defines any data that the function needs to work.
// If the function doesn’t need to accept any values, the parameter list can be empty.
{
Commands;
return $value; // Defines a value to return.
}

function myfunction () // This function doesn’t return a value or accept any parameters

{
Command;
}
$arrayname[index] = data;
/*Arrays can hold any type of data and grow as large as I need them without having to define a size ahead of time.
To create an array, I define an array name, the data I want to store, and the index number where I want to store that item in the array*/

$myarray[0] = “Hello”; // I want to store the string “Hiya”
$myarray[1] = 3.57; // I want to store the number 3.57 in the first and second elements of an array

$arrayname[“key”] = data; // I create associative arrays to  identify data by a unique string key not an index number

$myarray[“pi”] = 3.14; // I assign the number 3.14 to the “pi” key

$variable = $arrayname[“key”]; I use the key value to retrieve data from an associative array

$myarray[“pi”] = 3.14;
// I want to retrieve data stored under the key “pi
// This first line stores the value 3.14 into the array and assigns it to the key “pi”.
$number2use = $myarray[“pi”];
// This second line pulls out the data, associated with the key “pi”
// This stores that data into the $number2use variable.
// “array_pop” is a built-in array functions for manipulating arrays
// “array_pop” removes the last element from an array
// “array_push” adds an element to the end of an array
// “sort” sorts arrays in ascending order

class classname {  // define a class
public $propertyname; // specify the property to create an object
public function methodname() { // specify the methods to create an object
commands;
}
}

$objectname = new classname; // I use this Syntax to create an object

$objectname->propertyname = value;
// I specify the object name and the property you want to use to assign a value to an object’s property
// the dollar symbol is not used when assigning a value to an object’s property
// ($) isn’t used to designate the property name.

$objectname->methodname();
// specify the object name followed by the method name to tell an object to run a method

class classname1 {
public $propertyname;
public function methodname() {
commands;
}
}
class classname2 extends classname1 {
// use the extends keyword followed by the class name you want to inherit from to inherit from a class
// an object can inherit from one class
// This is “single inheritance” in Object Oriented Programming
public $propertyname;
public function methodname() {
commands;
}
}

include_once "a.php"; // this will include a.php
/*include is a directive or statement that causes another PHP file to be included and evaluated*/

Saturday, 12 February 2011

Simple Object Access Protocol - SOAP

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">


<soap:Header>
...
</soap:Header>


<soap:Body>
...
  <soap:Fault>
  ...
  </soap:Fault>
</soap:Body>


</soap:Envelope>




<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  ...
  Message information goes here
  ...
</soap:Envelope>


soap:encodingStyle="URI" 
[This encodingStyle attribute is used to define the data types used in the document]


soap:mustUnderstand="0|1"
[This SOAP mustUnderstand attribute can be used to indicate whether a header entry is mandatory or optional 
for the recipient to process.
If we add mustUnderstand="1" to a child element of the Header element 
it indicates that the receiver processing the Header must recognize the element.]


A SOAP Request


POST /InStock HTTP/1.1
Host: www.opsecsecurity.com/stock
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn


<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">


<soap:Body xmlns:m="http://www.opsecsecurity.com/stock">
  <m:GetStockPrice>
    <m:StockName>Applied Holographics</m:StockName>
  </m:GetStockPrice>
</soap:Body>


</soap:Envelope>








A SOAP Response:


HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn


<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">


<soap:Body xmlns:m="http://www.opsecsecurity.com/stock">
  <m:GetStockPriceResponse>
    <m:Price>42</m:Price>
  </m:GetStockPriceResponse>
</soap:Body>


</soap:Envelope>






---






soap:actor="URI"
[This SOAP actor attribute is used to address the Header element to a specific endpoint.]
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">


[Question]
<soap:Body>
  <m:GetPrice xmlns:m="http://www.ba.com/prices">
    <m:Item>Dubai</m:Item>
  </m:GetPrice>
</soap:Body>


<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">


[Answer]
<soap:Body>
  <m:GetPriceResponse xmlns:m="http://www.ba.com/prices">
    <m:Price>1000.00</m:Price>
  </m:GetPriceResponse>
</soap:Body>


</soap:Envelope>


</soap:Envelope>


[HTTP Protocol Question]
POST /item HTTP/1.1
Host: 192.168.2.4
Content-Type: text/plain
Content-Length: 200


[HTTP Protocol Answer]
200 OK
Content-Type: text/plain
Content-Length: 200

XML



XML


<?xml version="1.0" encoding="ISO-8859-1"?>


<note>
<to>Marina</to>
<from>James</from>
<heading>Reminder</heading>
<body>Don't forget me!</body>
</note>


<note>
  <date>
    <day>28</day>
    <month>10</month>
    <year>2003</year>
  </date>
  <to>Marina</to>
  <from>James</from>
  <heading>Reminder</heading>
  <body>Don't forget to celebrate your birthday!</body>
</note>


<root>
  <child>
    <subchild>.....</subchild>
  </child>
</root>


<p>This is a paragraph in XML with a closing tag</p>
<p>This is another paragraph in XML with a closing tag</p>


<message>these opening and closing tags have been written with the same case</message>


<b><i>This text is bold and italic and these elements have been nested within each other</i></b>


<note date="11/02/2011">
  <to>Marina</to>
  <from>James</from>
</note>


<message>if salary &lt; 50000 then find a better paid job</message>


<person sex="female">
<person sex='female'>


<person>
  <sex>female</sex>
  <firstname>Marina</firstname>
  <lastname>Pluvinage Snyder</lastname>
</person>

CSS



<head>


<style type="text/css">


hr {color:yellow;}
p {margin-left:20px;}
body {background-image:url("pictures/profile10.gif");}
</style>


body
{
background-color:#d0e4fe;
}
h1
{
color:orange;


<link rel="stylesheet" type="text/css" href="Snyderstyle.css" />


#text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}


p {color:red;text-align:center;}
/*This is a comment, CSS declarations always ends with a semicolon, 
and declaration groups are surrounded by curly brackets*/


p
{
text-align:center;
/*This is another comment*/
color:black;
font-family:arial;
}


#para1
{
text-align:center;
color:red;
}
/*This is another comment, This style rule will be applied to the element with id="para1"*/


.center {text-align:center;}
/*This is another comment, all HTML elements with class="center" will be center-aligned*/


</head>




<style> /* I use the <style> and </style> tags and then define the type of text I want to format */
<!--
textstylename {
attribute: value;
}
-->
</style>

<html>
<head>
<title>This text appears in the title bar.</title>
</head>
<style>
<!--
h1 {
color : #FF0000; /*I want to display the colour red for all heading 1 text*/
}
-->
</style>
</head>
<body>
<h1>This heading is defined by the style.</h1>
</body>
</html>

<html>
<head> /* This stylesheet defines text in the <h1> heading */
<title>This text appears in the title bar.</title>
</head>
<style>
<!--
h1 {
}
p {
/* This stylesheet defines text in the <p> paragraph text */
color : #00FF00;
background-color: $FF0000;
text-align : center; /* Text-align attributes */
}
-->
</style>
</head>
<body>
<h1>This heading is defined by the style.</h1>
<p>This is text is modified by the paragraph style.</p>
</body>
</html>

<html>
<head>
<title>This text appears in the title bar.</title>
</head>
<style>
<!--
h1 {
color : #FF0000;
}
p {
color : #00FF00;
background-color: $FF0000;
text-align : center;
}
-->
</style> /* this style defines formatting for the <p> paragraph text */
</head>
<body>
<h1>This heading is defined by the style.</h1>
<p>This is paragraph text gets modified by the paragraph
style.</p> /* A single style formats text stored in both <p> tags*/
<p>This is paragraph text also gets modified.</p>
</body>
</html>

<style>
<!--
.classname {
/* I can define style classes if I want the flexibility to choose different styles to use for text stored within identical tags. A style class lets me define formatting and then I can apply this style class to any type of text stored within different types of tags.  I define a class name and its formatting attributes to create a style class.
*/
attribute: value;
}
-->
</style>

<tag class = “classname”>Text to be formatted</tag> /*Include the class name within a tag to use a style class*/

<html>
<head>
<title>This text appears in the title bar.</title>
</head>
<style> /*Style classes let me apply different styles to text stored within identical tags*/
<!--
.firstclass {
color : #FF0000;
}
.secondclass {
color : #00FF00;
text-align : center;
}
-->
</style>
</head>
<body>
<h1 class = “firstclass”>This heading is defined by the
firstclass style.</h1>
<p class = “firstclass”>This is paragraph text gets
modified by the firstclass style.</p>
<p class = “secondclass”>This is paragraph text gets
modified by the secondclass style.</p>
</body>
</html>
store stylesheets in separate files.

h1 {
color : #FF0000;
}
.myclass {
/*the stylesheet simply contains the tag or class names along with the attributes I want to modify, when the stylesheet is stored as a separate file.*/
color : #00FF00;
text-align : center;
}
/*I store one or more styles in a separate file saved with the .css file extension.*/

<link rel = “stylesheet” jref = “stylesheet.css” type = /* I include that stylesheet file in my HTML Web page by adding the <link> tag*/
“text/css” media = “screen”> /* The media portion of the <link> tag defines how the Web page will be viewed. i.e. braille, aural, handheld.*/

.firstclass {
color : #FF0000;
}
.secondclass {
color : #00FF00;
text-align : center;
} /* I store the styles in a styleme.css file*/

<html>
<link rel = “stylesheet” href = “./styleme.css” type =
“text/css” media = “screen”> /* I include this stylesheet in any HTML Web page by using the <link> tag*/
<head>
<title>This text appears in the title bar.</title>
</head>
<body>
<h1 class = “firstclass”>This heading is defined by the
firstclass style.</h1>
<p class = “firstclass”>This is paragraph text gets
modified by the firstclass style.</p>
<p class = “secondclass”>This is paragraph text gets
modified by the secondclass style.</p>
</body>
</html>

<html> /* Any styles stored in the HTML code of my Web page takes precedence over any styles stored in either the file2.css or file1.css external files. The text will be formatted according to the stylesheet closest to the text. Styles stored in an internal stylesheet take precedence over an external stylesheet.*/
<link rel = “stylesheet” href = “./file1.css” type =
“text/css” media = “screen”> /* I define the order to apply the external stylesheets by using multiple <link> tags if I have two external stylesheets that format the same text.*/
<link rel = “stylesheet” href = “./file2.css” type = /* the styles stored in the file2.css stylesheet take precedence over the styles stored in the file1.css. */
“text/css” media = “screen”>
<body>
</body>
</html>