Today session on Network Configuration

Today session on Network Configuration.

To know the connection and ip address.

$ /sbin/ifconfig | less


eth0 Link encap:Ethernet  HWaddr 00:0f:ea:93:c3:bd


RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Interrupt:21 Base address:0xc400

Here the interfaces like eth0, lo and pp0 interfaces will be displayed. From this sir explained each and every information displayed for a particular interface.

The following basic things related to network like:

  • Hub –  Layer 1 [Physical layer]
  • Switches –  Layer 2 [Datalink layer]
  • Bridges –  Layer 2 [Datalink layer]
  • Routers –  Layer 3 [Network layer]
  • Gateways –  Layer 4 [Transport layer]

To get information about the network devices.

Ex: ip addr show

Turn On/Off an interface using either ifconfig command or ip command.

Using ifconfig:

Turn off –  $ ifconfig  eth0 down

Turn on –  $ ifconfig  eth0  up

Using ip command:

Turn off  –  $ ip  link  set  eth0  down

Turn on –  $ ip  link  set  eth0  up

$ ifconfig  eth0  netmask //set the ip address

DHCP(Dynamic Host Configuration Protocol). //if it is on it will get ip address from network provider.

To Assigning Multiple IP address for an single interface for web hosting:

$ ifconfig  eth0 : 0

$ ifconfig  eth0 : 0

To Add and Removing IP address using ip cmd:

Add –  $ ip  addr  add  dev  eth0

Remove –  $ ip  addr  del  dev  eth0

MAC address:

Change the MAC address using ip command.

$ ip  link  show // the information of all the interfaces.

$ ip  link  show  dev  iown thenterfacename // the information about particular interfaces.

$ ip  link  set  eth0  down // to set interface down

$ ip  link  set  address  00:c0:b0:a0:66:77  dev  eth0 // to set hardware address

$ ip  link  set  eth0  up // to set interface up

STONITH (Shoot The Other Node In The Head) In a network if the master host is down then its slave host takes over the place of the master by this STONITH.

$traceroute – used to trace the route ip address.

$netstat – this will display the routing table, net state.

Today Internship Class on PHP

Today the class continue with last PHP session.

Array comparison with identity operator:

/* The O/P will be in Boolean */
$c=array(4,5,6);print($a===$b); /* return true as 1 */
print($a===$c); /* return false as 0 */

String as Integer and Integer as String:
PHP consider the input string as integer and integer as string according place of operator used. We can differentiate it by following Examples.

Addition operator:

$c=$a+$b; /* it try’s to convert the sting as integer to add, if the first char is not integer unless it will took directly if it is integer */                                                                 print $c; /* the O/P will be 7 */

$a=”a 4apple”;
$b=” b 3apple”;
$c=$a+$b; /* it try’s to convert the sting as integer to add, because the starting char is not integer */
print $c; /* the O/P will be 0 */

Concatenate operator:

<?php                                                                                                                                   $a=”a 4apple”;
$b=” b 3apple”;
$e=$a.$b; /* it will concatenate the string */
$f=$c.$d; /* it convert the integer as string the it will concatenate the string */          print $e; /* the O/P will be a 4appleb 3apple */
print $f; /* the O/P will be 333666 */

Finding length string and Integer(digits:
print strlen($name); /* count the string length */
print strlen($num); /* it convert the num to string and then it count the string length */?>

Pass the variable to another page :

We only able to phase a variable or its value to another page by server side only, not possible in client side using PHP. The following examples shows a way of passing variable to another page in different type of values.

page1.php(The URL looks like http://localhost/sample/page1.php)
echo(“This Page 1″);
<html><body><a href=”page2.php?uname=mani&password=mani123”>Go To Page2</a></body></html>
page2.php(The URL looks like http://localhost/sample/page2.php?uname=mani&password=mani123)
echo(“user name = “.$username);
echo(“<br>password = “.$passsword);
/* see the O/P and you can change the passed value in URL instead mani and mani123 , then refresh the page2.php to see the changes */

We can not able to pass the special character directly to the URL .
Eg: Replace the link tag<a href=”page2.php?uname= mani&password=mani123″> as <a href=”page2.php?uname= mani#$%^kandan&password=mani123″> in page1.php then see the O/P, it wont took special character .

Using urlencode() function
change the code in page1.php.

<html><a href=”<?=($url); ?>”>Go to page2</a></html>

They are following variables
local variable -> able to access inside particular function where you
created it
global variable-> able to access to another functions also in a single
supper global variable -> able to access to all document used in the

Today Session On PHP

Yesterday class handled on PHP session. This is the starting session on PHP.
Require XAMPP
Download xampp and extrat it to /opt/ folder
Write a shell script in to export the path.
vi  /etc/profile.d/
export PATH=/opt/lampp/bin:/opt/lampp/sbin:/opt/lampp:$PATH
This is done because by default the path of php, mysql and apache should refer to path mentioned above.
Copy my.cnf file from /etc/ folder
mv  /etc/my{.cnf, .old}
Start the lampp.
$/opt/lampp/lampp  start
Now the lampp is started. To check it open the browser and type http://localhost. It will load php home page of the xampp.
Save the .php file in /opt/lampp/htdocs/.
There are is also another way store your .php files in home folder itself.
$ mkdir  public_html //create a folder in home dir.
$ chmod  a+rx  ~ //change the permission home dir.
$ chmod  a+rx  public_html /change the permission public_html dir.
$ su  – login as root user
$ cd  /opt/lampp/etc/
$ ls  extra/
$ vi  extra/httpd-userdir.conf
$ vi  /opt/lampp/etc/httpd.conf
Include httpd_userdir.conf // uncomment this line as //include httpd_userdir.conf.
Now you can save php files in home/public_html folder and need run the url as http://localhost/~manikandan/file.php in browser.
We tried working on the procedure explained by sir. Great its working.
Array display.
We can print thr array elements in two ways using single line
print_r($arrayname) ;

Jquery Ajax

Instead of Using direct Ajax coding in your document , we may also use load(“file name”); function of jQuery. Which is easy and short function compare to Ajax code 10 to 15 lines.

Also we put the arguments as call back function in load function. The call back function behaves as execute after the file loaded.

Syntax: load(“file name”,callback  function());

Upload File Using Ajax and PHP

I tried to upload a file to current PHP working directory. I have create a form and input type is file and enctype=”multipart/form-data”to upload different type of files. I put the action=”file.php” and target to a iframe which is hidden. When the submit button is clicked I call a function using Ajax to show the status as loading file to server. After getting response from the file.php it call the function status ,executes to display the file is loaded status.


$dir= getcwd().DIRECTORY_SEPARATOR;//detecting current directory
$file = $dir.basename( $_FILES[‘myfile’][‘name’]);//get file by its name.
if(@move_uploaded_file($_FILES[‘myfile’][‘tmp_name’], $file))//save the file
$result = 1;
<script language=”javascript” type=”text/javascript”><?php echo $result; ?>);</script>/* passing variable result as a argument to status function. */

Simple Ajax To Display Text File From MySQL

I started to learn the Ajax from First  I tried to simple one, When I clicked a button it will call a PHP file. The PHP file will print an echo statement only. I get the displaying value of PHP file as a return value to Ajax. Ya its working.

Then I tried to display a value from PHP file which is imported from the MySQL table , wow it’s also working good. Then tried to import a file from table and get it as a return value to Ajax. It did not worked.

Then remove “header” line which is representing the content application type.Wow it display the file , but if  it is a text file only.Other than text file is displayed as encrypted format.