Say you want to execute a block of code upon some condition, well, that’s were conditional statements comes handy.

PHP supports the following conditional statements :

1. if statement : Codes in the block (codes within {…}) are executed only if the specified condition is true.

if (condition) {
//codes to be executed.

//1. if statement.
echo "1. if statement.";
echo "<br>";
if ($x > 0) {
echo "This is true <br>";

2. if… else statement : Execute one of the block. Block1 if the condition is true. Block2 if the condition is false.

if (condition) {
//codes to be executed.
else {
//codes to be executed.

//2. if... else statement.
echo "2. if... else statement.";
echo "<br>";
if ($x == 2013) {
echo "We are in 2013 <br>";
else {
echo "We are not in 2013 <br>";

3. if…elseif…else statement : Select one of the blocks to be executed out of many.

if (condition) {
//codes to be executed.
elseif {
//codes to be executed.
else {
//codes to be executed.

//3. if...elseif...else statement.
echo "3. if...elseif...else statement. <br>";
$mood = "boring";
if ($mood == "sleepy") {
echo "Save the code, and go to sleep <br>";
elseif ($mood == "boring") {
echo "Go browse something fun and get back <br>";
else {
echo "continue...";

4. Switch statement : Select one of the blocks to be executed out of many.

switch (pattern) {
case label1 :
//execute the codes in here if label1==pattern.
case label2 :
//execute the codes in here if label2==pattern.
case labelN :
//execute the codes in here if labelN==pattern.
default :
//execute the codes in here if none of the above label’s match the pattern.

//4. Switch statement.
echo "4. Switch statement. <br>";
$language = "php";
switch ($language) {
case "perl":
echo "We are coding using perl";
case "python":
echo "we are coding using python";
case "javascript":
echo "we are coding using javascript";
echo "We are coding using php";

4. PHP – Operators.

Posted: September 20, 2013 in Hypertext Preprocessor (PHP)
Tags: ,

==>Arithmetic operators.

We can perform various arithmetic operations like addition (+), subtraction (-), multiplication (*), division (/) and modulus (%).
$variable (or a constant value) operator $variable (or a constant value).
Here is the code that demonstrates various arithmetic operations.

//Arithmetic operators.
echo "<strong>Arithmetic operations</strong> <br>";
echo "Additon <br>";
echo ($x + $y); //Addition.
echo "<br>Subtraction <br>";
echo ($x - $y); //Subtraction.
echo "<br>Multiplication <br>";
echo ($x * $y); //Multiplication.
echo "<br>Division <br>";
echo ($x / $y); //Division.
echo "<br>Modulus <br>";
echo ($x % $y); //Modulus.

==>Assignment Operator.

We use ‘=’ to assign.
$variable = <value>
The example code :

//Assignment Operator.
echo "<br> <br><strong>Assignment operations</strong> <br>";
$x = $y;
echo "\$x has been assigned the value of \$y. Now \$x=$x";

==>String Operators.

Concatenation : We use the dot (.) operator to achieve concatenation.
$variable (or a string).$variable (or a string)

//String Operators.
echo "<br> <br><strong>String operations</strong> <br>";
echo "Concatenation.<br>";
$a = "open ";
$b = "source";
$c = $a.$b; //concatenation.
echo "$c";

==>Increment/Decrement Operators.

1. Pre-increment (++$variable).
2. Post-increment ($variable++).
3. Pre-decrement (–$variable).
4. Post-decrement ($variable–).

//Increment/Decrement Operators.
echo "<br> <br><strong>Increment/Decrement operations</strong> <br>";
echo "1.Pre-increment.<br>";
echo ++$x; // Pre-increment
echo "<br>2.Post-increment.<br>";
echo $y++; // Post-increment
echo "<br>3.Pre-decrement.<br>";
echo --$z; // Pre-decrement
echo "<br>4.Post-decrement.<br>";
echo $a--; // Post-decrement

==>Comparison Operators.

1. Equal (==) :  Data types are not considered, just the values are considered.
2. Identical (===) : Data types are considered.
3. Not equal (!= ).
4. Not identical (!==).
5. Less than (<).
6. Less than or equal (<=).
7. Greater than (>).
8. Greater than or equal (>=).

//Comparison Operators.
echo "<br> <br><strong>Comparison operations</strong> <br>";
echo "1.Equal.<br>";
var_dump($x == $y); //Equal
echo "<br>2.Identical.<br>";
var_dump($x === $y); // Identical
echo "<br>3.Not equal.<br>";
var_dump($x != $y); // Not equal
echo "<br>4.Not identical.<br>";
var_dump($x !== $y); // Not identical
echo "<br>5.Greater than.<br>";
var_dump($a > $b); //Greater than
echo "<br>6.Less than<br>";
var_dump($a < $b); //Less than

==>Logical Operators.

1. AND ($variable and $variable / $variable && $variable).
2. OR ($variable or $variable / $variable || $variable).
3. XOR ($variable xor $variable).
4. NOT (!$variable).

//Logical Operators.
echo "<br> <br><strong>Logical operations</strong> <br>";
echo "1.AND<br>";
var_dump($x && $y); // And
echo "<br>2.OR<br>";
var_dump($x || $y); // Or
echo "<br>3.XOR<br>";
var_dump($x xor $y); // Xor
echo "<br>4.NOT<br>";
var_dump(!$x); // Not

==>Array operators.

1. Union (+) : Duplicates are removed.
2. Equality (==).
3. Identity (===).
4. Inequality (!=).
5. Inequality (<>).
6. Non-identity (!==).

//Array operators.
echo "<br> <br><strong>Array operations</strong> <br>";
$x = array("a" => "mango", "b" => "cherry");
$y = array("b" => "cherry", "c" => "apple");
$z = $x + $y; // union of $x and $y
echo "1.union<br>";
echo "<br>2.Equality<br>";
var_dump($x == $y);
echo "<br>3.Identity<br>";
var_dump($x === $y);
echo "<br>4.Inequality<br>";
var_dump($x != $y);
echo "<br>5.Inequality<br>";
var_dump($x <> $y);
echo "<br>6.Non-identity<br>";
var_dump($x !== $y);

Constants :

Constants as the name indicates, as they are defined they cannot be changed during the script. A constant is an identifier. A valid constant starts with a letter of underscore, and are automatically global across the script. To set a constant, we use the function, define(). For an instance :

define (“constnt”,”This is a constant and cannot be changed”);
echo constnt;

Comments :

PHP supports three different types of comments.

  • Multi-line comment as in C.
  • Single-line comment (//) as in C and C++.
  • Single-line comment (#) as in Perl.

Here is the code to demonstrate the above :

<!DOCTYPE html>

define ("constnt","This is a constant and cannot be changed");
echo constnt;



//single-line comment.

#And also the single-line comment using #, as in perl.



Posted: September 15, 2013 in Networks/Administration


1 ) Introduction

A) What is network


A network is nothing more than two or more computers or machines connected by cables or by wireless connection so that they can exchange information and use the resource.The connection that is link could be in anyway like cables,satellite,infrared beams,telephone cables and radio waves also.

The best know computer network is the internet.

B) Why we use network

We use networking for exchange of information and messages etc..

Benefits of networking:

File sharing :  Network of computers helps the user  to share data files.

Hardware sharing : Users can share hardware’s like printer’s and scanner.

 User Sharing : Networks, Allows user to communicate user to communicate using e-mail, video conferencing etc

Network gaming : Lots of games  are available with multiplayer options now, by connecting network we can use this option.

2) Creating a network and types of network

View original post 1,276 more words


What are Networking Cables :

Networking cables are used to connect one network device to other network devices or to connect two or more computers to share printer, scanner etc


A ) Twisted Pair :  Twisted pair cables are mainly classified into 2 types

1.a)  Shielded Twisted Pair





1. STP is a type of copper wiring in which each of the two copper wires that are twisted together are coated with an insulting coating that functions as a ground for the wires.

2.The extra covering in shielded twisted pair wiring protects the transmission lines from electromagnetic interference leaking into or out of the cable.

1.b)  Unshielded Twisted Pair



1. UTP is a type of copper wiring cable that consists of two unshielded wires twisted around each other.

B ) Coaxial Cable




Coaxial cable is a…

View original post 237 more words


Posted: September 15, 2013 in Networks/Administration
Tags: ,


Network topology is the arrangement of the various elements (links,nodes, etc.) of a computer or biological network.

Essentially, it is the topological structure of a network, and may be depicted physically or logically,

Physical topology refers to the placement of the network’s various components,including device location and cable  installation,while logical topology shows how data flows within a network,regardless of its physical design.

There are many types of Network topologies but i’ll be explaining 4 types :

a) BUS : 


A Bus network topology is a network architecture in which a set of clients are connected via a shared communications line/cables,called a bus.

Bus networks are the simplest way to connect multiple clients,but may have problems when two clients went to transmit at the same time on the same bus.

Thus systems which use bus network architectures normally have some scheme of collision handling or collision avoidance for communication on the…

View original post 237 more words

Monitor the incoming and outgoing traffic in your network using the IPTables.

IPTables by Netfilter organization is the firewall for Linux systems and is the successor of the popular Linux firewalls, IPChains and IPfwadm. In the Linux distributions RedHat and Fedora, IPTables is the default pre-installed firewall package. Download IPTables from freecode or for the ones interested in the source code, here is the git tree.

Once your IPTables is set, you can start defining your policies. You must be the root/super user to do this. So, lets begin. Let us start with the help command.
#iptables –help

To check the version :
#iptables –version
#iptables -V

Screenshot from 2013-09-15 00:56:54

Packet Processing :

There are basically four Tables, or the built-in queues for processing. Each table has its own functionality and is handled by a filtering chain (the firewall policies are placed in here).

To enlist all the available rules under the targeted table, use the following :
#iptables -L -t <table_name>

1. Filter table : Default table. Associated with the packet filtering and has three in-built chains.

#iptables -L -t filter

  • Input chain controls the traffic entering the system.
  • Forward chain controls the traffic being routed through the system.
  • Output chain controls the traffic leaving the system.

Screenshot from 2013-09-15 00:58:06

2. NAT (Network Address Translation) Table : For alternating the source and/or destination IP address and has four in-built chains.

#iptables -L -t nat

  • Prerouting chain used to NAT packets after changing their destination address.
  • Input chain handles packet that are entering the system.
  • Output chain handles packet that are leaving the system.
  • Postrouting chain used to NAT packets after changing their source address.

Screenshot from 2013-09-15 00:58:38

3. Mangle Table : It is related to modification of the Quality of Service bits in the TCP header. It is a combination of filter and NAT tables and has five chains.

#iptables -L -t mangle

  • Prerouting chain.
  • Input chain.
  • output chain.
  • Forward chain.
  • Postrouting chain.

Screenshot from 2013-09-15 00:59:36

4. Raw Table : Associated with the packets that are not traced. It contains two chains.

#iptables -L -t raw

  • Prerouting chain.
  • Output chain.

Screenshot from 2013-09-15 01:00:08

Insert New Rule(s) :

To insert new rule(s), use :

#iptables -I <target_chain> <rule_position> -t <target_table> <the_rule> -j <action>

Here -I indicates insert a rule in target chain at a specified position (this is for priority) and -j indicates jump to the action indicated, and the action can be, drop, reject and accept.

Let me demonstrate to reject the packets from a specific IP. Here I will be using backtrack machine running on the VirtualBox on my Ubuntu machine. Let us define all the rules for our Ubuntu 12.04 machine. I have set my Backtrack’s IP as, and my Ubuntu’s IP as To reject the packets :

#iptables -I INPUT 1 -t filter -s -j REJECT

Now that the policy is places, lets see how it works. Lets send some ICMP packets, go ahead and ping the Ubuntu machine (

Screenshot from 2013-09-15 01:18:43

As you can see, all the packets are rejected and we are getting ICMP error message. If you don’t want to reply with an error message, you can just DROP the packets. This will give the user no information dropping the packets silently. To silently drop the packets :

#iptables -I INPUT 1 -t filter -s -j DROP

Try pinging now.

Screenshot from 2013-09-15 01:20:31

As you can see in the screenshot, the sent 28 packets are dropped silently and the user gets no error message.

Not necessarily you must stick to the positioning. You can also append your rules using the option -A. To append your policy :

#iptables -A <target_chain> -t <target_table> <the_rule> -j <action>

Let us append the following rule :

#iptables -A INPUT -t filter -d -j REJECT

This rule prevents any packet reaching the destination IP, generated by the host. Let us try sending few packets to the destination IP,


Screenshot from 2013-09-15 01:24:17

As you can see, no packets reach the destination IP from the host.  similarly you can append more rules :

#iptables -A INPUT -t filter -d -j DROP

But instead of packets, sometimes it is necessary to define rules for a specific protocol or port. This can be done using :

#iptables -A <target_chain> -t <target_table> -p <protocol_name> -j <action>

For an instance,

#iptables -A INPUT -t filter -s -p tcp –dport 80 -j REJECT

The above rule will reject all the http (port 80) packets from the specified IP.

Screenshot from 2013-09-15 01:33:52

Delete a rule or Flush all the rules :

You can delete the rule by :

#iptables -D <target_chain> <rule_position> -t <target_table>

#iptables -D INPUT 1 -t filter

will delete the first rule defined in the INPUT chain of the filter table.

To remove/flush all the rules :

#iptables -F -t <target_table>

#iptables -F -t filter

will flush all the rules defined in the filter table.

Screenshot from 2013-09-15 01:27:45

Saving the rules :

The rules we set are all volatile, and will be flushed once the system is restarted. To save these changes permanently, use the following :

for ubuntu : #iptables-save > /etc/iptables,rules

Screenshot from 2013-09-15 01:35:44