Test

Powered by Blogger.

Monday, 23 April 2012

Scalable vector Graphics

SVG Shapes

SVG has some predefined shape elements that can be used by developers:

    Rectangle <rect>
    Circle <circle>
    Ellipse <ellipse>
    Line <line>
    Polyline <polyline>
    Polygon <polygon>
    Path <path>

The following chapters will explain each element, starting with the rect element.
SVG Rectangle - <rect>
Example 1

The <rect> element is used to create a rectangle and variations of a rectangle shape:

Here is the SVG code:
Example
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect width="300" height="100"
  style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"/>
</svg>




.

Code explanation:

    The width and height attributes of the rect element define the height and the width of the rectangle
    The style attribute is used to define CSS properties
    The CSS fill property defines the fill color of the rectangle
    The CSS stroke-width property defines the width of the border of the rectangle
    The CSS stroke property defines the color of the border of the rectangle

Example 2

Let's look at another example that contains some new attributes:

Here is the SVG code:
Example
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150"
  style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;
  stroke-opacity:0.9"/>
</svg>





Code explanation:

    The x attribute defines the left position of the rectangle (e.g. x="50" places the rectangle 50 px from the left margin)
    The y attribute defines the top position of the rectangle (e.g. y="20" places the rectangle 20 px from the top margin)
    The CSS fill-opacity property defines the opacity of the fill color (legal range: 0 to 1)
    The CSS stroke-opacity property defines the opacity of the stroke color (legal range: 0 to 1)

Example 3



Here is the SVG code:
Example
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150"
  style="fill:blue;stroke:pink;stroke-width:5;opacity:0.5"/>
</svg>

NEXT 

Sunday, 22 April 2012

php datatypes

PHP consists of 4 basic data types:
boolean - a boolean is actually much like an integer, but with only two possible values: 0 or 1, which is either false or true.

integer - a number with no decimals, e.g 3 or 42.

float (sometimes referred to as double) - a number that may include decimals, e.g. 42.3 or 10.9.

string - A number of characters, which combined makes a text string.

Besides that, there are a couple of more complex datatypes:

array - holds an array of items, e.g. several strings or several integers. An array may contain variables which are arrays which are arrays and so on.

object - a reference to an instance of a class. This is related to Object Oriented programming, which we will talk more about later on in this tutorial.

There are also a couple of special types:

resource - holds a reference to a special external resource. It may be a file resource, or perhaps an open database connection.

NULL - a value of null is nothing. It's not the same as 0 (zero), because that's actually a value. Null is truly nothing. Variables which have not yet been assigned a value, or which you have used the unset() method on, will carry the NULL value. This is useful if you wish to check whether or not a variable contains any value - you may compare it against the NULL constant.

In the next couple of chapters, we will look into working with both strings and numbers (integers and floats), and later on, we will look into both arrays and objects.


In this chapter, we will work with some numbers. As mentioned in a previous chapter, PHP have two different data types related to numbers: Integers and floats. Integers are whole numbers, without a decimal separator, while floats always carry a fractional part as well. In most cases, integers will be sufficient, and they are faster and simpler to work with.

Let's try some simple calculations, to show you how easy it is to do math with PHP. Here are a couple of examples.

<?php
$number1 = 6;
$number2 = 2;

echo "Addition: " . ($number1 + $number2);
echo "<br /><br />";
echo "Substraction: " . ($number1 - $number2);
echo "<br /><br />";
echo "Multiplication: " . ($number1 * $number2);
echo "<br /><br />";
echo "Division: " . ($number1 / $number2);
echo "<br /><br />";
?>


Now that's simple! Basic math with PHP, and it looks kinda like using a simple calculator. But what about numbers which comes from the outside world, e.g. from a submitted form? We will dig into in a later chapter, and one of the techniques we will be using, is checking if a variable holds a value that we can use for math. The is_numberic() function will help us with this. It checks whether a variable is an integer, or if it can be converted to one. For instance, "42" can be converted to 42, but "Hello World", well, that's a tough one. is_numberic will return true in the first case and false in the second case. Here is an example:

<?php
$number1 = "10";
$number2 = 20;

if((is_numeric($number1)) && (is_numeric($number2)))
    echo "Result: " . ($number1 + $number2);
else
    echo "Both variables have to be numbers!";
?>

Now, try changing "10" to a word or a sentence, e.g. "Hello world". You will see that the condition fails, and our warning will be printed. This comes in handy when validating user input, as we will see later on.

In some situations, you may need a real integer instead of a string that is numeric, like in the above example. Even though PHP is loosely typed, type casting does exist - you may cast one type to another. Have a look at this example:

<?php
$var = "30";
echo "The current datatype of var is: " . gettype($var) . "<br /><br />";
$var = (int)$var;
echo "The current datatype of var is: " . gettype($var);
?>

We use the int keyword, inside a set of parentheses, to define a new type for the variable. Obviously, it works the other way around as well - you may cast an integer to become a string and so on.
Floats
As mentioned, there are two different data types for working with numbers: Integers and floats. In the next example, I will try to show you the difference. Try running this piece of sample code:

<?php
$number1 = 10;
$number2 = 3;
$number3 = 5;

$result = $number1 / $number2;

echo "Result as a float: " . $result . "<br /><br />";
echo "Result as a float, rounded: " . round($result, 2) . "<br /><br />";
echo "Result as an integer: " . (int)$result . "<br /><br />";
echo "Multiplication as a float: " . ($result * $number3) . "<br /><br />";
echo "Multiplication as an integer: " . ((int)$result * $number3) . "<br /><br />";
?>

php functions

A function in PHP, and any other programming language, allows you to encapsulate a piece of code and call it from other parts of your code. This makes it possible to write code which can be re-used from different parts of your application, without actually writing the code over and over again. Here is an example of a simple PHP function:

<?php
function SayHello($to)
{
    echo "Hello, ".$to;
}
?>

A function should always start with the keyword function, followed by the name of the function you wish to declare. In this case, we name our function SayHello. It should be followed by a set of parentheses, which allows you to define parameters for the function. Parameters are not required, but if you don't have any, you should still write the parentheses, like SayHello(). With our function, we define the $to parameter. Since PHP is a typeless language, you don't have to define a type for the parameter, and you may send any kind of datatype through the function. The content of our function is between a set of curly braces, in this case a simple echo statement, where we use the $to parameter to send a greeting to a specific person or thing.

You use the function simply by writing the name and the required set of parameters, like this:

<?php
function SayHello($to)
{
    echo "Hello, ".$to;
}

SayHello("World");
?>

Functions may return values as well. In the first example we don't, since it's not required, but it is possible and very useful as well. If you have used other programming languages, you might be used to declaring whether or not a function should return anything, and if so, which type it will be. However, this is not needed with PHP. Let's change our function so it returns the required string instead of outputting it:

<?php
function SayHello($to)
{
    return "Hello, ".$to;
}

echo SayHello("World");
?>

As you can see, we simply have the function return the string instead of outputting it, and then we do the actual output once we call the function. This is normally how it's done, since outputting stuff directly from the string requires it to be positioned where we want the output, instead of in the top of our document or an include file.

A very important aspect of functions is the scope. Once you enter a function, you enter a new scope, and while functions and classes are automatically global, variables are not. This means that a variable declared outside a function is not automatically available inside it. Try this example to see it for your self:

<?php
$var = "test";

function SayHello()
{
    return "Current value of var: ".$var;
}

echo SayHello();
echo "<br /><br />";
echo "Current value of var: ".$var;
?>

The result will be that the first output won't have a value for $var, because it's simply not known within the function. You could declare it inside the function, and assign a value to it, but it would not be reflected outside the function. However, it is possible to get access to the outside variables within a function - you simply need to declare them as globals inside the scope of the function, like this:

<?php
$var = "test";
function SayHello()
{
    global $var;
    return "Current value of var: ".$var;
}
?>

When declaring a function, you may define one or several parameters to be optional. It's done by giving them a default value in the declaration. More than one parameter can be optional, but only the last X number of parameters can be optional - you can't have an optional parameter followed by a required parameter. In the next example, we define a couple of optional parameters to show you how it's done.

<?php
function GreetCoder($name, $msg = "Hello, coder!")
{
    echo "A message to " . $name . ": " . $msg;
}

GreetCoder("John Doe");
echo "<br /><br />";
GreetCoder("John Doe", "This is a custom message!");
?>

As you can see, we can call the function with only one parameter or with both parameters. The output is affected by what we do, but no matter what, $msg will have a value. It can come in handy in a lot of situations, which you will experience your self once you write more PHP.
Next 

php abstract class

Abstract classes are special because they can never be instantiated. Instead, you typically inherit a set of base functionality from them in a new class. For that reason, they are commonly used as the base classes in a larger class hierarchy. In the chapter on inheritance, we created an Animal class and then a Dog class to inherit from the Animal class. In your project, you may very well decide that no one should be able to instantiate the Animal class, because it's too unspecific, but instead use a specific class inheriting from it. The Animal class will then serve as a base class for our own little collection of animals.

A method can be marked as abstract as well. As soon as you mark a class function as abstract, you have to define the class as abstract as well - only abstract classes can hold abstract functions. Another consequence is that you don't have to (and can't) write any code for the function - it's a declaration only. You would do this to force anyone inheriting from your abstract class to implement this function and write the proper code for it. If you don't, PHP will throw an error. However, abstract classes can also contain non-abstract methods, which allows you to implement basic functionality in the abstract class. Let's go on with an example. Here is the abstract class:

abstract class Animal
{
    public $name;
    public $age;
   
    public function Describe()
    {
        return $this->name . ", " . $this->age . " years old";   
    }
   
    abstract public function Greet();
}

As you can see, it looks like a regular exception, but with a couple of differences. The first one is the abstract keyword, which is used to mark both the class it self and the last function as abstract. As mentioned, an abstract function can't contain any body (code), so it's simply ended with a semi-colon as you can see. Now let's create a class that can inherit our Animal class:

class Dog extends Animal
{
    public function Greet()
    {
        return "Woof!";   
    }
   
    public function Describe()
    {
        return parent::Describe() . ", and I'm a dog!";   
    }
}


As you can see, we implement the both functions from the Animal class. The Greet() function we are forced to implement, since it's marked as abstract - it simply returns a word/sound common to the type of animal we are creating. We are not forced to implement the Describe() function - it's already implemented on the Animal class, but we would like to extend the functionality of it a bit. Now, the cool part is that we can re-use the code implemented in the Animal class, and then add to it as we please. In this case, we use the parent keyword to reference the Animal class, and then we call Describe() function on it. We then add some extra text to the result, to clarify which type of animal we're dealing with. Now, let's try using this new class:

$animal = new Dog();
$animal->name = "Bob";
$animal->age = 7;
echo $animal->Describe();
echo $animal->Greet();
Next 

connecting to mysql using php

 Connecting to a MySQL database with PHP is very easy. It can be done using a single function from the nice array of MySQL related functions in PHP:

mysql_connect("localhost", "username", "password");

If default values have been configured in your configuration file, you can leave out these parameters, but otherwise you will need to specify a host and typically a username and a password for it. Both the username and password has been set by yourself or by your hosting company. If you host MySQL on your own machine, or if you run your PHP code on your hosting company's server, you can usually just specify localhost as the host value. If in doubt, ask your hosting company or check their support pages.

The mysql_connect() function returns a resource, a direct link to the database server, which should be used to access the database server each time you use one of the MySQL functions. However, if this resource is not specified, PHP will just use the last opened connection, allowing you to write less code. In most cases you will only need one MySQL connection per page, so this should work just fine for you.

To work with a database, you need to call one more function, the mysql_select_db() function. The name really tells it all - for a specific connection, it selects a database that you will be working with. It's very simple to use:

mysql_select_db("my_database");

This should be called after you have established the connection using mysql_connect(). It takes one or two parameters. The first should be the name of the database you wish to use. The second one is optional and allows you to specify which MySQL resource link the function should be performed on. Here is an example where we use these two essential functions together:


mysql_connect("localhost", "username", "password");
mysql_select_db("my_database"); 
 
And here is the same example, but where we get the resource link from mysql_connect() and use it. This is the way you should do it mainly if you need to connect to more than one database server on the same page:
 
 
$dbConnection = mysql_connect("localhost", "username", "password");
mysql_select_db("my_database", $dbConnection);


With this, we now have a connection to the database server and we have selected the desired database. In the next chapter, we will use this connection, but before we do so, we should talk a bit about closing the connection again. A connection to a database server is costly, so it should obviously be closed once we're done using it. However, PHP can and will do this for us automatically, if we choose not to do it, once the page is fully executed. If we for some reason want to close a MySQL connection before the page is done executing, we can do it by using the mysql_close() function:

mysql_close();

This will close the last opened connection. If we want to close a specific connection, just pass its link to the function:

mysql_close($dbConnection);

Friday, 20 April 2012

Basics of network



network

In general, the term network can refer to any interconnected group or system. More specifically, a network is any method of sharing information between two systems (human, electrical or mechanical).


classification of network

1. According to the size of the Network:
LAN 
MAN 
WAN 
PAN 
CAN
2. According to type of connection used:
Wired Network
Wireless Network
lan(local area network)


Characteristics:
1) 
A Local Area Network is a group of computers and network 
2) Communication devices within a limited geographic area, such as an office building. For example, a library will have a wired or wireless LAN for users to interconnect local devices(e.g., printers, and servers).
3) Local area networking uses switches, bridges and/or repeaters, and hubs to interconnect LANs and increase overall size. Routers are used to connect a LAN to a WAN or MAN.
4) LAN are characterized by the following:
5) High data transfer speeds.
6) Generally less expensive technologies 
7) Limited geographic area
8) Security 
9) Scalability 
10) Reliability
man(metropolitan area network)

A Metropolitan Area Network is a network that connects two or more Local Area Networks or Campus Area Networks together but does not extend beyond the boundaries of the immediate town, city, or metropolitan area. A MAN can range anywhere from 5 to 50km in diameter.
wan(wide area network)

A WAN is a data communications network that covers a relatively broad geographic area (i.e. one country to another country) and that often uses transmission facilities provided by common carriers, such as telephone companies. They are generally connected with each other using routers.
WAN are characterized by the following:
1) Multiple interconnected LANs. 
2) Generally more expensive technology.
3) More sophisticated to implement than LANs.
4) Exist in an unlimited geographic area.

pan(personal area network)

A personal area network (PAN) is a computer network used for Communication among computer devices close to one person. 
Some examples of devices that may be used in a PAN are printers, fax machines, telephones, scanners. The reach of a PAN is typically within about 20-30 feet (approximately 6-9 Meters).
san(storage area network)

We have a lot of data in the form of audio and video. We need to store data for quick access and transfer on special storage devices.
SAN may be referred to as a sub network or special purpose network. Its special purpose is to allow users on a larger network to connect various data storage devices with clusters of data servers.
vpn(virtual private network)

VPN is a private network that lets you access public networks remotely. 
VPN uses encryption and security protocols to retain privacy while it accesses outside resources by creating a virtual network.
according to the type of connection used

1) Wired Network: A network that connects devices using cables (wires) like Coaxial Cable, Twisted pair Cable, Optical Fiber Cable etc.
2) Wireless Network: A network that connects devices using wireless technologies like Bluetooth, infrared, radio frequency etc.
according to the type of functional group


peer to peer network(workgroup)


A workgroup is a collection of computers on a LAN that share common resources and responsibilities. 
Workgroups provide easy sharing of files, printers and other network resources.
client-server network(domain)


1) A Domain is a "Network Architecture" in which each computer or process on the network is either a client or a server.
2) servers are powerful computers or processes dedicated to managing disk drives (file servers), printers (print servers) etc. 
3) Clients are PCs or workstations on which users run applications.
4) Clients rely on servers for resources, such as files, devices, and even processing power.


Friday, 13 April 2012

Network attacks

NETWORK ATTACKS

attacks on network

Men in middle attack
Attackers position themselves between two systems and actively participate
in the connection to gather data. The attacker may also run program which
spoofs dns reply, configured to send false DNS information so that a DNS query
for a given website will resolve to the attacker's IP address. Then the attacker will
activate a program such that it will transparently proxy all HTTP and HTTPS traffic it receives. The DNS spoof program detects DNS request for www.abc.com and redirects the client to
attacker's machine. The ARP table convinces the victim's machine that it is indeed talking
to the intended web server. The victim's browser starts to establish a secure connection.



All messages for establishing SSL connection are sent to MITM running on the attacker's machine.
Hacker's system acts as a SSL proxy, establishing two SSL connections-one from victim to the attacker's
machine and the other from attacker's machine to the actual web server. When establishing the SSL session
between the victim machine and the attacker machine, MITM program will send the attacker's own certificate. The victim's browser will notice that the certificate is not signed by a trusted Certificate Authority and show
a message to the user asking the user whether to accept this un-trusted certificate or not. The normal tendency is to accept
it, thinking it is some error message.
denial of service(DOS)
A denial of service attack (DOS) is an attack through which a person can render
a system unusable or significantly slow down the system for legitimate users by overloading
the resources, so that no one can access it. If an attacker is unable to gain access to a machine, the attacker most probably will
just crash the machine to accomplish a denial of service attack.

Network Attacks

NETWORK ATTACKS
Attacks on network


Attacking a network means either defacing it to ground or accessing a data which
you should not. In a network there are mainly two types of attacks are possible.
1). Denial of Service (DOS) attack.
2). Data Stealing.
network-infrastructure attacks
Hacker attacks against network infrastructures can be easy, because many
networks can be reached from anywhere in the world via the Internet. Here are some examples of network-infrastructure attacks: Connecting into a network through a rogue modem attached to a computer behind
a firewall Exploiting weaknesses in network transport mechanisms, such as TCP/IP and NetBIOS Flooding a network with too many requests, creating a denial of service (DoS)
for legitimate requests installing a network analyzer on a network and capturing every packet that travels across it, revealing confidential information in clear text.
common network attacks

1) Sniffing Attack.
2) Man in middle attack.
3) DOS attacks.
sniffing attacks

Sniffers monitor network data. A sniffer can be a self-contained software program or a hardware device with
the appropriate software or firmware programming.
Sniffers usually act as network probes or "snoops" examining network traffic but
not intercepting or altering it. Some sniffers work only with TCP/IP packets, but the more sophisticated tools can work with many other protocols and at lower levels such as the Ethernet frame.
concept

A sniffer is a piece of software that captures the traffic on a network. They are available for
several platforms in both commercial and open-source variations. Some of simplest packages use a command line interface and dump captured data to the screen, while sophisticated ones use GUI, graph traffic statistics, track multiple sessions and offer several configuration options.
Sniffers are also the engines for other programs. Network Intrusion Detection Systems (NIDS)
use sniffers to match packets against a rule-set designed to flag anything malicious or strange. Network utilization and monitoring programs often use sniffers to gather data necessary for metrics and analysis. It is to be noted that sniffers do not intercept or alter the data it captures.
The most common way of networking computers is through Ethernet. The Ethernet protocol works by broadcasting packets to all
hosts on the network, with the packet header containing the MAC address of the machine that is meant to receive the packet. All others are supposed to ignore it. A NIC (Network Interface Card, also known as Ethernet card) that is accepting all packets, regardless of the intended machine is said to be in promiscuous mode. A sniffer is a program that sets the desired NIC into promiscuous mode.
note
A packet sniffer is known for its ability to "sniff" plain text passwords. On a normal LAN there are thousands
of packets being conversed by numerous machines every minute. Therefore, anything transmitted in plaintext, such as passwords, web pages, database queries and messaging over the network will be vulnerable to sniffing. man in the middle

Database concepts

DATABASE CONCEPTS

DBMS(DATABASE MANAGEMENT SYSTEM)

DBMS contains information about a particular enterprise
Collection of interrelated data
Set of programs to access the data
An environment that is both convenient and efficient to use
Database Applications:
Banking: all transactions
Airlines: reservations, schedules
Universities: registration, grades
Sales: customers, products, purchases
Online retailers: order tracking, customized recommendations
Manufacturing: production, inventory, orders, supply chain
Human resources: employee records, salaries, tax deductions
Databases touch all aspects of our lives

Purpose of Database Systems
In the early days, database applications were built directly on top of file systems
Drawbacks of using file systems to store data:
Data redundancy and inconsistency
Multiple file formats, duplication of information in different files
Difficulty in accessing data
Need to write a new program to carry out each new task
Data isolation multiple files and formats
Integrity problems
Integrity constraints (e.g. account balance > 0) become buried in program code rather than being stated explicitly
Hard to add new constraints or change existing ones

Drawbacks of using file system
Atomicity of updates
Failures may leave database in an inconsistent state with partial updates carried out
Example: Transfer of funds from one account to another should either complete or not happen at all
Concurrent access by multiple users Concurrent accessed needed for performance
Uncontrolled concurrent accesses can lead to inconsistencies
Example: Two people reading a balance and updating it at the same time
Security problems
Hard to provide user access to some, but not all, data
Database systems offer solutions to all the above problems

Levels of Abstraction

Physical level: describes how a record (e.g., customer) is stored.

Logical level: describes data stored in database, and the relationships among the data.
type customer = record
customer_id : string; customer_name : string; customer_street : string; customer_city : string;
end; View level: application programs hide details of data types.
Views can also hide information (such as an employees salary) for security purposes.
DBMS(DATABASE MANAGEMENT SYSTEM)

An architecture for a database system

configuring apache server

Configuring of Apache server
Listed below is information on how to configure the Apache web server to run PHP programs on Windows machines.
For information on installing and configuring Apache for Windows, please see the following:
Installing and Configuring Apache for Windows

1. Install PHP
PHP needs to be downloaded and installed before continuing. You can download PHP
from the PHP download page at http://www.php.net/downloads.php. Download the zip package from the "Windows Binaries" section. This guide will assume the PHP version is version 5.x.
Create a folder on your machine for PHP. For example, c:\php. Extract all
of the files from the zip file to the c:\php directory.
Copy the file called c:\php\php.ini-recommended to c:\php\php.ini
If you want to be able to see error messages from your PHP pages,
open EditRocket and open the php.ini file. Search for the line display_errors,
and make sure the value is set to On.

2. Configure Apache to run PHP as a Module
This guide assumes you are using apache 2.2. To configure Apache to run PHP
, the httpd.conf file needs to be modified. This file is located in the apache installation directory under the conf folder. Open the httpd.conf file in EditRocket and do the following:
A. Add the following line after all of the LoadModule statements:
LoadModule php5_module "c:/php/php5apache2_2.dll"
B. Search for AddType, and add the following after the last AddType line:
AddType application/x-httpd-php .php
C. Add the PHP location to the end of the httpd.conf file.
For example, at the end of the file, add the following: PHPIniDir "c:/php"

3. Restart Apache Now, the apache web server needs to be restarted.
You can do this either via the Apache service located in the services control
panel or via the Start -> All Programs -> Apache . . . -> Control Apache Server menu option. 4. Run a test PHP page You can use the EditRocket hello world PHP template
for a test PHP page. This is located in File -> New From Template ->php ->Hello_World_Program.
Save this file as test.php to your htdocs folder under your apache installation directory. Open your web browser and type in your apache host (and :port if the port is something other than 80) followed by test.php, for example http://localhost/test.php
If u are using xampp server than put all your php files in htdocs folde

RSS

Categories

Followers

Blog Archive

rTechIndia

RtechIndia->technology ahead

rtech

rtechindia

RtechIndia

Go rtechindia

Go rtechindia

RtechIndia

Monday, 23 April 2012

Scalable vector Graphics

SVG Shapes

SVG has some predefined shape elements that can be used by developers:

    Rectangle <rect>
    Circle <circle>
    Ellipse <ellipse>
    Line <line>
    Polyline <polyline>
    Polygon <polygon>
    Path <path>

The following chapters will explain each element, starting with the rect element.
SVG Rectangle - <rect>
Example 1

The <rect> element is used to create a rectangle and variations of a rectangle shape:

Here is the SVG code:
Example
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect width="300" height="100"
  style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"/>
</svg>




.

Code explanation:

    The width and height attributes of the rect element define the height and the width of the rectangle
    The style attribute is used to define CSS properties
    The CSS fill property defines the fill color of the rectangle
    The CSS stroke-width property defines the width of the border of the rectangle
    The CSS stroke property defines the color of the border of the rectangle

Example 2

Let's look at another example that contains some new attributes:

Here is the SVG code:
Example
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150"
  style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;
  stroke-opacity:0.9"/>
</svg>





Code explanation:

    The x attribute defines the left position of the rectangle (e.g. x="50" places the rectangle 50 px from the left margin)
    The y attribute defines the top position of the rectangle (e.g. y="20" places the rectangle 20 px from the top margin)
    The CSS fill-opacity property defines the opacity of the fill color (legal range: 0 to 1)
    The CSS stroke-opacity property defines the opacity of the stroke color (legal range: 0 to 1)

Example 3



Here is the SVG code:
Example
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150"
  style="fill:blue;stroke:pink;stroke-width:5;opacity:0.5"/>
</svg>

NEXT 

Sunday, 22 April 2012

php datatypes

PHP consists of 4 basic data types:
boolean - a boolean is actually much like an integer, but with only two possible values: 0 or 1, which is either false or true.

integer - a number with no decimals, e.g 3 or 42.

float (sometimes referred to as double) - a number that may include decimals, e.g. 42.3 or 10.9.

string - A number of characters, which combined makes a text string.

Besides that, there are a couple of more complex datatypes:

array - holds an array of items, e.g. several strings or several integers. An array may contain variables which are arrays which are arrays and so on.

object - a reference to an instance of a class. This is related to Object Oriented programming, which we will talk more about later on in this tutorial.

There are also a couple of special types:

resource - holds a reference to a special external resource. It may be a file resource, or perhaps an open database connection.

NULL - a value of null is nothing. It's not the same as 0 (zero), because that's actually a value. Null is truly nothing. Variables which have not yet been assigned a value, or which you have used the unset() method on, will carry the NULL value. This is useful if you wish to check whether or not a variable contains any value - you may compare it against the NULL constant.

In the next couple of chapters, we will look into working with both strings and numbers (integers and floats), and later on, we will look into both arrays and objects.


In this chapter, we will work with some numbers. As mentioned in a previous chapter, PHP have two different data types related to numbers: Integers and floats. Integers are whole numbers, without a decimal separator, while floats always carry a fractional part as well. In most cases, integers will be sufficient, and they are faster and simpler to work with.

Let's try some simple calculations, to show you how easy it is to do math with PHP. Here are a couple of examples.

<?php
$number1 = 6;
$number2 = 2;

echo "Addition: " . ($number1 + $number2);
echo "<br /><br />";
echo "Substraction: " . ($number1 - $number2);
echo "<br /><br />";
echo "Multiplication: " . ($number1 * $number2);
echo "<br /><br />";
echo "Division: " . ($number1 / $number2);
echo "<br /><br />";
?>


Now that's simple! Basic math with PHP, and it looks kinda like using a simple calculator. But what about numbers which comes from the outside world, e.g. from a submitted form? We will dig into in a later chapter, and one of the techniques we will be using, is checking if a variable holds a value that we can use for math. The is_numberic() function will help us with this. It checks whether a variable is an integer, or if it can be converted to one. For instance, "42" can be converted to 42, but "Hello World", well, that's a tough one. is_numberic will return true in the first case and false in the second case. Here is an example:

<?php
$number1 = "10";
$number2 = 20;

if((is_numeric($number1)) && (is_numeric($number2)))
    echo "Result: " . ($number1 + $number2);
else
    echo "Both variables have to be numbers!";
?>

Now, try changing "10" to a word or a sentence, e.g. "Hello world". You will see that the condition fails, and our warning will be printed. This comes in handy when validating user input, as we will see later on.

In some situations, you may need a real integer instead of a string that is numeric, like in the above example. Even though PHP is loosely typed, type casting does exist - you may cast one type to another. Have a look at this example:

<?php
$var = "30";
echo "The current datatype of var is: " . gettype($var) . "<br /><br />";
$var = (int)$var;
echo "The current datatype of var is: " . gettype($var);
?>

We use the int keyword, inside a set of parentheses, to define a new type for the variable. Obviously, it works the other way around as well - you may cast an integer to become a string and so on.
Floats
As mentioned, there are two different data types for working with numbers: Integers and floats. In the next example, I will try to show you the difference. Try running this piece of sample code:

<?php
$number1 = 10;
$number2 = 3;
$number3 = 5;

$result = $number1 / $number2;

echo "Result as a float: " . $result . "<br /><br />";
echo "Result as a float, rounded: " . round($result, 2) . "<br /><br />";
echo "Result as an integer: " . (int)$result . "<br /><br />";
echo "Multiplication as a float: " . ($result * $number3) . "<br /><br />";
echo "Multiplication as an integer: " . ((int)$result * $number3) . "<br /><br />";
?>

php functions

A function in PHP, and any other programming language, allows you to encapsulate a piece of code and call it from other parts of your code. This makes it possible to write code which can be re-used from different parts of your application, without actually writing the code over and over again. Here is an example of a simple PHP function:

<?php
function SayHello($to)
{
    echo "Hello, ".$to;
}
?>

A function should always start with the keyword function, followed by the name of the function you wish to declare. In this case, we name our function SayHello. It should be followed by a set of parentheses, which allows you to define parameters for the function. Parameters are not required, but if you don't have any, you should still write the parentheses, like SayHello(). With our function, we define the $to parameter. Since PHP is a typeless language, you don't have to define a type for the parameter, and you may send any kind of datatype through the function. The content of our function is between a set of curly braces, in this case a simple echo statement, where we use the $to parameter to send a greeting to a specific person or thing.

You use the function simply by writing the name and the required set of parameters, like this:

<?php
function SayHello($to)
{
    echo "Hello, ".$to;
}

SayHello("World");
?>

Functions may return values as well. In the first example we don't, since it's not required, but it is possible and very useful as well. If you have used other programming languages, you might be used to declaring whether or not a function should return anything, and if so, which type it will be. However, this is not needed with PHP. Let's change our function so it returns the required string instead of outputting it:

<?php
function SayHello($to)
{
    return "Hello, ".$to;
}

echo SayHello("World");
?>

As you can see, we simply have the function return the string instead of outputting it, and then we do the actual output once we call the function. This is normally how it's done, since outputting stuff directly from the string requires it to be positioned where we want the output, instead of in the top of our document or an include file.

A very important aspect of functions is the scope. Once you enter a function, you enter a new scope, and while functions and classes are automatically global, variables are not. This means that a variable declared outside a function is not automatically available inside it. Try this example to see it for your self:

<?php
$var = "test";

function SayHello()
{
    return "Current value of var: ".$var;
}

echo SayHello();
echo "<br /><br />";
echo "Current value of var: ".$var;
?>

The result will be that the first output won't have a value for $var, because it's simply not known within the function. You could declare it inside the function, and assign a value to it, but it would not be reflected outside the function. However, it is possible to get access to the outside variables within a function - you simply need to declare them as globals inside the scope of the function, like this:

<?php
$var = "test";
function SayHello()
{
    global $var;
    return "Current value of var: ".$var;
}
?>

When declaring a function, you may define one or several parameters to be optional. It's done by giving them a default value in the declaration. More than one parameter can be optional, but only the last X number of parameters can be optional - you can't have an optional parameter followed by a required parameter. In the next example, we define a couple of optional parameters to show you how it's done.

<?php
function GreetCoder($name, $msg = "Hello, coder!")
{
    echo "A message to " . $name . ": " . $msg;
}

GreetCoder("John Doe");
echo "<br /><br />";
GreetCoder("John Doe", "This is a custom message!");
?>

As you can see, we can call the function with only one parameter or with both parameters. The output is affected by what we do, but no matter what, $msg will have a value. It can come in handy in a lot of situations, which you will experience your self once you write more PHP.
Next 

php abstract class

Abstract classes are special because they can never be instantiated. Instead, you typically inherit a set of base functionality from them in a new class. For that reason, they are commonly used as the base classes in a larger class hierarchy. In the chapter on inheritance, we created an Animal class and then a Dog class to inherit from the Animal class. In your project, you may very well decide that no one should be able to instantiate the Animal class, because it's too unspecific, but instead use a specific class inheriting from it. The Animal class will then serve as a base class for our own little collection of animals.

A method can be marked as abstract as well. As soon as you mark a class function as abstract, you have to define the class as abstract as well - only abstract classes can hold abstract functions. Another consequence is that you don't have to (and can't) write any code for the function - it's a declaration only. You would do this to force anyone inheriting from your abstract class to implement this function and write the proper code for it. If you don't, PHP will throw an error. However, abstract classes can also contain non-abstract methods, which allows you to implement basic functionality in the abstract class. Let's go on with an example. Here is the abstract class:

abstract class Animal
{
    public $name;
    public $age;
   
    public function Describe()
    {
        return $this->name . ", " . $this->age . " years old";   
    }
   
    abstract public function Greet();
}

As you can see, it looks like a regular exception, but with a couple of differences. The first one is the abstract keyword, which is used to mark both the class it self and the last function as abstract. As mentioned, an abstract function can't contain any body (code), so it's simply ended with a semi-colon as you can see. Now let's create a class that can inherit our Animal class:

class Dog extends Animal
{
    public function Greet()
    {
        return "Woof!";   
    }
   
    public function Describe()
    {
        return parent::Describe() . ", and I'm a dog!";   
    }
}


As you can see, we implement the both functions from the Animal class. The Greet() function we are forced to implement, since it's marked as abstract - it simply returns a word/sound common to the type of animal we are creating. We are not forced to implement the Describe() function - it's already implemented on the Animal class, but we would like to extend the functionality of it a bit. Now, the cool part is that we can re-use the code implemented in the Animal class, and then add to it as we please. In this case, we use the parent keyword to reference the Animal class, and then we call Describe() function on it. We then add some extra text to the result, to clarify which type of animal we're dealing with. Now, let's try using this new class:

$animal = new Dog();
$animal->name = "Bob";
$animal->age = 7;
echo $animal->Describe();
echo $animal->Greet();
Next 

connecting to mysql using php

 Connecting to a MySQL database with PHP is very easy. It can be done using a single function from the nice array of MySQL related functions in PHP:

mysql_connect("localhost", "username", "password");

If default values have been configured in your configuration file, you can leave out these parameters, but otherwise you will need to specify a host and typically a username and a password for it. Both the username and password has been set by yourself or by your hosting company. If you host MySQL on your own machine, or if you run your PHP code on your hosting company's server, you can usually just specify localhost as the host value. If in doubt, ask your hosting company or check their support pages.

The mysql_connect() function returns a resource, a direct link to the database server, which should be used to access the database server each time you use one of the MySQL functions. However, if this resource is not specified, PHP will just use the last opened connection, allowing you to write less code. In most cases you will only need one MySQL connection per page, so this should work just fine for you.

To work with a database, you need to call one more function, the mysql_select_db() function. The name really tells it all - for a specific connection, it selects a database that you will be working with. It's very simple to use:

mysql_select_db("my_database");

This should be called after you have established the connection using mysql_connect(). It takes one or two parameters. The first should be the name of the database you wish to use. The second one is optional and allows you to specify which MySQL resource link the function should be performed on. Here is an example where we use these two essential functions together:


mysql_connect("localhost", "username", "password");
mysql_select_db("my_database"); 
 
And here is the same example, but where we get the resource link from mysql_connect() and use it. This is the way you should do it mainly if you need to connect to more than one database server on the same page:
 
 
$dbConnection = mysql_connect("localhost", "username", "password");
mysql_select_db("my_database", $dbConnection);


With this, we now have a connection to the database server and we have selected the desired database. In the next chapter, we will use this connection, but before we do so, we should talk a bit about closing the connection again. A connection to a database server is costly, so it should obviously be closed once we're done using it. However, PHP can and will do this for us automatically, if we choose not to do it, once the page is fully executed. If we for some reason want to close a MySQL connection before the page is done executing, we can do it by using the mysql_close() function:

mysql_close();

This will close the last opened connection. If we want to close a specific connection, just pass its link to the function:

mysql_close($dbConnection);

Friday, 20 April 2012

Basics of network



network

In general, the term network can refer to any interconnected group or system. More specifically, a network is any method of sharing information between two systems (human, electrical or mechanical).


classification of network

1. According to the size of the Network:
LAN 
MAN 
WAN 
PAN 
CAN
2. According to type of connection used:
Wired Network
Wireless Network
lan(local area network)


Characteristics:
1) 
A Local Area Network is a group of computers and network 
2) Communication devices within a limited geographic area, such as an office building. For example, a library will have a wired or wireless LAN for users to interconnect local devices(e.g., printers, and servers).
3) Local area networking uses switches, bridges and/or repeaters, and hubs to interconnect LANs and increase overall size. Routers are used to connect a LAN to a WAN or MAN.
4) LAN are characterized by the following:
5) High data transfer speeds.
6) Generally less expensive technologies 
7) Limited geographic area
8) Security 
9) Scalability 
10) Reliability
man(metropolitan area network)

A Metropolitan Area Network is a network that connects two or more Local Area Networks or Campus Area Networks together but does not extend beyond the boundaries of the immediate town, city, or metropolitan area. A MAN can range anywhere from 5 to 50km in diameter.
wan(wide area network)

A WAN is a data communications network that covers a relatively broad geographic area (i.e. one country to another country) and that often uses transmission facilities provided by common carriers, such as telephone companies. They are generally connected with each other using routers.
WAN are characterized by the following:
1) Multiple interconnected LANs. 
2) Generally more expensive technology.
3) More sophisticated to implement than LANs.
4) Exist in an unlimited geographic area.

pan(personal area network)

A personal area network (PAN) is a computer network used for Communication among computer devices close to one person. 
Some examples of devices that may be used in a PAN are printers, fax machines, telephones, scanners. The reach of a PAN is typically within about 20-30 feet (approximately 6-9 Meters).
san(storage area network)

We have a lot of data in the form of audio and video. We need to store data for quick access and transfer on special storage devices.
SAN may be referred to as a sub network or special purpose network. Its special purpose is to allow users on a larger network to connect various data storage devices with clusters of data servers.
vpn(virtual private network)

VPN is a private network that lets you access public networks remotely. 
VPN uses encryption and security protocols to retain privacy while it accesses outside resources by creating a virtual network.
according to the type of connection used

1) Wired Network: A network that connects devices using cables (wires) like Coaxial Cable, Twisted pair Cable, Optical Fiber Cable etc.
2) Wireless Network: A network that connects devices using wireless technologies like Bluetooth, infrared, radio frequency etc.
according to the type of functional group


peer to peer network(workgroup)


A workgroup is a collection of computers on a LAN that share common resources and responsibilities. 
Workgroups provide easy sharing of files, printers and other network resources.
client-server network(domain)


1) A Domain is a "Network Architecture" in which each computer or process on the network is either a client or a server.
2) servers are powerful computers or processes dedicated to managing disk drives (file servers), printers (print servers) etc. 
3) Clients are PCs or workstations on which users run applications.
4) Clients rely on servers for resources, such as files, devices, and even processing power.


Friday, 13 April 2012

Network attacks

NETWORK ATTACKS

attacks on network

Men in middle attack
Attackers position themselves between two systems and actively participate
in the connection to gather data. The attacker may also run program which
spoofs dns reply, configured to send false DNS information so that a DNS query
for a given website will resolve to the attacker's IP address. Then the attacker will
activate a program such that it will transparently proxy all HTTP and HTTPS traffic it receives. The DNS spoof program detects DNS request for www.abc.com and redirects the client to
attacker's machine. The ARP table convinces the victim's machine that it is indeed talking
to the intended web server. The victim's browser starts to establish a secure connection.



All messages for establishing SSL connection are sent to MITM running on the attacker's machine.
Hacker's system acts as a SSL proxy, establishing two SSL connections-one from victim to the attacker's
machine and the other from attacker's machine to the actual web server. When establishing the SSL session
between the victim machine and the attacker machine, MITM program will send the attacker's own certificate. The victim's browser will notice that the certificate is not signed by a trusted Certificate Authority and show
a message to the user asking the user whether to accept this un-trusted certificate or not. The normal tendency is to accept
it, thinking it is some error message.
denial of service(DOS)
A denial of service attack (DOS) is an attack through which a person can render
a system unusable or significantly slow down the system for legitimate users by overloading
the resources, so that no one can access it. If an attacker is unable to gain access to a machine, the attacker most probably will
just crash the machine to accomplish a denial of service attack.

Network Attacks

NETWORK ATTACKS
Attacks on network


Attacking a network means either defacing it to ground or accessing a data which
you should not. In a network there are mainly two types of attacks are possible.
1). Denial of Service (DOS) attack.
2). Data Stealing.
network-infrastructure attacks
Hacker attacks against network infrastructures can be easy, because many
networks can be reached from anywhere in the world via the Internet. Here are some examples of network-infrastructure attacks: Connecting into a network through a rogue modem attached to a computer behind
a firewall Exploiting weaknesses in network transport mechanisms, such as TCP/IP and NetBIOS Flooding a network with too many requests, creating a denial of service (DoS)
for legitimate requests installing a network analyzer on a network and capturing every packet that travels across it, revealing confidential information in clear text.
common network attacks

1) Sniffing Attack.
2) Man in middle attack.
3) DOS attacks.
sniffing attacks

Sniffers monitor network data. A sniffer can be a self-contained software program or a hardware device with
the appropriate software or firmware programming.
Sniffers usually act as network probes or "snoops" examining network traffic but
not intercepting or altering it. Some sniffers work only with TCP/IP packets, but the more sophisticated tools can work with many other protocols and at lower levels such as the Ethernet frame.
concept

A sniffer is a piece of software that captures the traffic on a network. They are available for
several platforms in both commercial and open-source variations. Some of simplest packages use a command line interface and dump captured data to the screen, while sophisticated ones use GUI, graph traffic statistics, track multiple sessions and offer several configuration options.
Sniffers are also the engines for other programs. Network Intrusion Detection Systems (NIDS)
use sniffers to match packets against a rule-set designed to flag anything malicious or strange. Network utilization and monitoring programs often use sniffers to gather data necessary for metrics and analysis. It is to be noted that sniffers do not intercept or alter the data it captures.
The most common way of networking computers is through Ethernet. The Ethernet protocol works by broadcasting packets to all
hosts on the network, with the packet header containing the MAC address of the machine that is meant to receive the packet. All others are supposed to ignore it. A NIC (Network Interface Card, also known as Ethernet card) that is accepting all packets, regardless of the intended machine is said to be in promiscuous mode. A sniffer is a program that sets the desired NIC into promiscuous mode.
note
A packet sniffer is known for its ability to "sniff" plain text passwords. On a normal LAN there are thousands
of packets being conversed by numerous machines every minute. Therefore, anything transmitted in plaintext, such as passwords, web pages, database queries and messaging over the network will be vulnerable to sniffing. man in the middle

Database concepts

DATABASE CONCEPTS

DBMS(DATABASE MANAGEMENT SYSTEM)

DBMS contains information about a particular enterprise
Collection of interrelated data
Set of programs to access the data
An environment that is both convenient and efficient to use
Database Applications:
Banking: all transactions
Airlines: reservations, schedules
Universities: registration, grades
Sales: customers, products, purchases
Online retailers: order tracking, customized recommendations
Manufacturing: production, inventory, orders, supply chain
Human resources: employee records, salaries, tax deductions
Databases touch all aspects of our lives

Purpose of Database Systems
In the early days, database applications were built directly on top of file systems
Drawbacks of using file systems to store data:
Data redundancy and inconsistency
Multiple file formats, duplication of information in different files
Difficulty in accessing data
Need to write a new program to carry out each new task
Data isolation multiple files and formats
Integrity problems
Integrity constraints (e.g. account balance > 0) become buried in program code rather than being stated explicitly
Hard to add new constraints or change existing ones

Drawbacks of using file system
Atomicity of updates
Failures may leave database in an inconsistent state with partial updates carried out
Example: Transfer of funds from one account to another should either complete or not happen at all
Concurrent access by multiple users Concurrent accessed needed for performance
Uncontrolled concurrent accesses can lead to inconsistencies
Example: Two people reading a balance and updating it at the same time
Security problems
Hard to provide user access to some, but not all, data
Database systems offer solutions to all the above problems

Levels of Abstraction

Physical level: describes how a record (e.g., customer) is stored.

Logical level: describes data stored in database, and the relationships among the data.
type customer = record
customer_id : string; customer_name : string; customer_street : string; customer_city : string;
end; View level: application programs hide details of data types.
Views can also hide information (such as an employees salary) for security purposes.
DBMS(DATABASE MANAGEMENT SYSTEM)

An architecture for a database system

configuring apache server

Configuring of Apache server
Listed below is information on how to configure the Apache web server to run PHP programs on Windows machines.
For information on installing and configuring Apache for Windows, please see the following:
Installing and Configuring Apache for Windows

1. Install PHP
PHP needs to be downloaded and installed before continuing. You can download PHP
from the PHP download page at http://www.php.net/downloads.php. Download the zip package from the "Windows Binaries" section. This guide will assume the PHP version is version 5.x.
Create a folder on your machine for PHP. For example, c:\php. Extract all
of the files from the zip file to the c:\php directory.
Copy the file called c:\php\php.ini-recommended to c:\php\php.ini
If you want to be able to see error messages from your PHP pages,
open EditRocket and open the php.ini file. Search for the line display_errors,
and make sure the value is set to On.

2. Configure Apache to run PHP as a Module
This guide assumes you are using apache 2.2. To configure Apache to run PHP
, the httpd.conf file needs to be modified. This file is located in the apache installation directory under the conf folder. Open the httpd.conf file in EditRocket and do the following:
A. Add the following line after all of the LoadModule statements:
LoadModule php5_module "c:/php/php5apache2_2.dll"
B. Search for AddType, and add the following after the last AddType line:
AddType application/x-httpd-php .php
C. Add the PHP location to the end of the httpd.conf file.
For example, at the end of the file, add the following: PHPIniDir "c:/php"

3. Restart Apache Now, the apache web server needs to be restarted.
You can do this either via the Apache service located in the services control
panel or via the Start -> All Programs -> Apache . . . -> Control Apache Server menu option. 4. Run a test PHP page You can use the EditRocket hello world PHP template
for a test PHP page. This is located in File -> New From Template ->php ->Hello_World_Program.
Save this file as test.php to your htdocs folder under your apache installation directory. Open your web browser and type in your apache host (and :port if the port is something other than 80) followed by test.php, for example http://localhost/test.php
If u are using xampp server than put all your php files in htdocs folde