OSL Lab 17 18
OSL Lab 17 18
Laboratory Manual
For
Manual Prepared by
Prof. P.M.Pawar
To achieve and evolve as a center of academic excellence and research center in the field of
Computer Science and Engineering. To develop computer engineers with necessary analytical
ability and human values who can creatively design, implement a wide spectrum of Computer
systems for welfare of the society.
Technical Document
This technical document is a series of Laboratory manuals of Computer Science & Engineering
Department and is a certified document of College of Engineering, Osmanabad. The care has been taken to
make the document error-free. But still if any error is found. Kindly bring it to the notice of subject teacher
and HOD.
Recommended by,
HOD
Approved by,
Principal
Copies:
1. Departmental Library
2. Laboratory
3. HOD
4. Principal
FOREWORD
It is my great pleasure to present this laboratory manual for second year engineering students for the
subject of Open Source Laboratory keeping in view the vast coverage required for visualization of
concepts of Signals and Systems.
As a student, many of you may be wondering with some of the questions in your mind regarding the
subject and exactly what has been tried is to answer through this manual.
Faculty members are also advised that covering these aspects in initial stage itself, will greatly relived
them in future as much of the load will be taken care by the enthusiasm energies of the students once they
are conceptually clear.
H.O.D.
LABORATORY MANUAL CONTENTS
This manual is intended for the Second year students of engineering branches in the subject of Open
Source Laboratory. This manual typically contains practical/Lab Sessions related Open Source Laboratory
covering various aspects related to the subject to enhance understanding.
Students are advised to thoroughly go through this manual rather than only topics mentioned in the
syllabus as practical aspects are the key to understanding and conceptual visualization of theoretical
aspects covered in the books.
Prof.P.M.Pawar
SUBJECT INDEX
2. Lab Experiments:
1. Maintain Punctuality of time for lab and also for works and assignment completion.
2. Make entry in the Log Book as soon as you enter the Laboratory.
3. All the students should sit according to their roll numbers starting from their left to right.
4. All the students are supposed to enter the terminal number in the log book.
6. All the students are expected to get at least the algorithm of the program/concept to be
implemented.
9. Turn off the machine once you are done using it.
12. Do not plug in external devices without scanning them for computer viruses.
1. Submission related to whatever lab work has been completed should be done during the
next lab session.
2. The immediate arrangements for printouts related to submission on the day of practical
assignments.
3. Students should be taught for taking the printouts under the observation of lab teacher.
THEORY:
LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux,
Apache, MySQL, and PHP.
1. Boot your system with OpenSUSE 12.3 installation media i.e CD/DVD or ISO image.
4. Welcome screen, From where we can select Language and keyboard layout. Read license
agreement and proceed further installation once agreed.
5. Clock and timezone settings.
6. Please click on change if you want custom setting of date and time. You can change it
manually or sync with NTP Server as show below. Click Accept once done.
7. File system partitioning. We opted default filesystem partition. You may choose manual
filesystem partitioning as options provided.
OpenSuse File System Partitioning
8. Create new user and it’s password. Uncheck all three options. Click on change to select
authentication method.
11. Verify settings, you may change settings after clicking on headlines or click
on Change button. Once done click on Install.
Verify OpenSuse Settings
14. Installation completed, remove installation media and click on Reboot Now.
16. Login screen. Supply password for user created during installation.
Apache is a free open source software which runs over 50% of the world’s web servers.
Install MySQL
MySQL is a powerful database management system used for organizing and retrieving data on a virtual
server
During the installation, MySQL will ask you for your permission twice. After you say Yes to both,
MySQL will install.
Install PHP
PHP is an open source web scripting language that is widely used to build dynamic webpages.
To install PHP on your virtual private server, open terminal and type in this command:
Once you answer yes to the PHP prompt, PHP will be installed.
THEORY:
Both GET and POST create an array (e.g. array( key => value, key2 => value2, key3 => value3, ...)). This
array holds key/value pairs, where keys are the names of the form controls and values are the input data from
the user.
Both GET and POST are treated as $_GET and $_POST. These are superglobals, which means that they are
always accessible, regardless of scope - and you can access them from any function, class or file without
having to do anything special.
$_GET is an array of variables passed to the current script via the URL parameters.
$_POST is an array of variables passed to the current script via the HTTP POST method.
Information sent from a form with the GET method is visible to everyone (all variable names and
values are displayed in the URL). GET also has limits on the amount of information to send. The
limitation is about 2000 characters. However, because the variables are displayed in the URL, it is
possible to bookmark the page. This can be useful in some cases.
Note: GET should NEVER be used for sending passwords or other sensitive information!
Information sent from a form with the POST method is invisible to others (all names/values are
embedded within the body of the HTTP request) and has no limits on the amount of information to
send.
Moreover POST supports advanced functionality such as support for multi-part binary input while
uploading files to server.
However, because the variables are not displayed in the URL, it is not possible to bookmark the page.
<html>
<body>
</body>
</html>
When the user fills out the form above and clicks the submit button, the form data is sent for processing
to a PHP file named "welcome.php". The form data is sent with the HTTP POST method.
To display the submitted data you could simply echo all the variables. The "welcome.php" looks like
this:
<html>
<body>
</body>
</html>
Result:
Welcome John
Your email address is [email protected]
THEORY:
PHP Variables
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
A variable starts with the $ sign, followed by the name of the variable
A variable name must start with a letter or the underscore character
A variable name cannot start with a number
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Variable names are case-sensitive ($age and $AGE are two different variables)
The scope of a variable is the part of the script where the variable can be referenced/used.
local
global
static
What is an Array?
An array is a special variable, which can hold more than one value at a time.
If you have a list of items (a list of car names, for example), storing the cars in single variables
could look like this:
$cars1 = "Volvo";
$cars2 = "BMW";
$cars3 = "Toyota";
However, what if you want to loop through the cars and find a specific one? And what if you had
not 3 cars, but 300?
The solution is to create an array!
An array can hold many values under a single name, and you can access the values by referring
to an index number.
array();
Associative arrays are arrays that use named keys that you assign to them.
or:
$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";
The dimension of an array indicates the number of indices you need to select an element.
PROGRAM:
<?php
$txt = "W3Schools.com";
echo "I love $txt!";
?>
OUTPUT:
I love W3Schools.com!
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
OUTPUT:
I like Volvo, BMW and Toyota.
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
OUTPUT:
Peter is 35 years old.
<!DOCTYPE html>
<html>
<body>
<?php
$cars = array
(
array("Volvo",22,18),
array("BMW",15,13),
array("Saab",5,2),
array("Land Rover",17,15)
);
</body>
</html>
OUTPUT:
Volvo: In stock: 22, sold: 18.
BMW: In stock: 15, sold: 13.
Saab: In stock: 5, sold: 2.
Land Rover: In stock: 17, sold: 15.
OBJECTIVE: To learn different types of built-in functions related to array, string, date-time and calendar in PHP.
THEORY:
Function Description
array_column() Returns the values from a single column in the input array
array_combine() Creates an array by using the elements from one "keys" array and one
"values" array
array_diff() Compare arrays, and returns the differences (compare values only)
array_diff_key() Compare arrays, and returns the differences (compare keys only)
strchr() Finds the first occurrence of a string inside another string (alias of strstr())
The date/time functions allow you to get the date and time from the server where your PHP script runs.
You can then use the date/time functions to format the date and time in several ways.
Function Description
date_add() Adds days, months, years, hours, minutes, and seconds to a date
date_parse_from_format() Returns an associative array with detailed info about a specified date,
according to a specified format
date_parse() Returns an associative array with detailed info about a specified date
The calendar extension contains functions that simplifies converting between different calendar formats.
It is based on the Julian Day Count, which is a count of days starting from January 1st, 4713 B.C.
Note: To convert between calendar formats, you must first convert to Julian Day Count, then to the
calendar of your choice.
Note: The Julian Day Count is not the same as the Julian Calendar!
Function Description
cal_days_in_month() Returns the number of days in a month for a specified year and calendar
easter_date() Returns the Unix timestamp for midnight on Easter of a specified year
easter_days() Returns the number of days after March 21, that the Easter Day is in a specified
year
PROGRAM:
<?php
echo "The time is " . date("h:i:sa");
?>
OUTPUT:
The time is 01:33:17am
OBJECTIVE: To learn Mysql database connectivity using PHP and performing operations using PHP.
TOOLS REQUIRED: Linux Operating system, PHP, Mysql and web browser.
THEORY:
After a database and a table have been created, we can start adding data in them.
The INSERT INTO statement is used to add new records to a MySQL table:
The SELECT statement is used to select data from one or more tables:
PROGRAM:
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->close();
?>
The following example selects the id, firstname and lastname columns from the MyGuests table and displays it on the page:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
OUTPUT:
id: 1 - Name: John Doe
id: 2 - Name: Mary Moe
id: 3 - Name: Julie Dooley
The following examples delete the record with id=3 in the "MyGuests" table:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->close();
?>
After the record is deleted, the table will look like this:
Conclusion: Hence we have implemented Mysql connectivity and basic operations on database
with PHP.
EXPERIMENT NO. 5
AIM: PHP Mysqli connectivity.
THEORY:
To connect PHP to MySQL database you need to know following important things:
1. Host name.
2. MySQL user name.
3. MySQL password.
PROGRAM:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully"
?>
Output:
Connected successfully
THEORY:
In your "php.ini" file, search for the file_uploads directive, and set it to On:
file_uploads = On
Without the requirements above, the file upload will not work.
The type="file" attribute of the <input> tag shows the input field as a file-select control, with a
"Browse" button next to the input control
$target_dir = "uploads/" - specifies the directory where the file is going to be placed
$imageFileType holds the file extension of the file (in lower case)
PROGRAM:
Create The HTML Form
Next, create an HTML form that allow users to choose the image file they want to upload:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
THEORY:
An alternative way to make data accessible across the various pages of an entire website is to use a
PHP Session.
A session creates a file in a temporary directory on the server where registered session variables and
their values are stored. This data will be available to all pages on the site during that visit.
The location of the temporary file is determined by a setting in the php.ini file
called session.save_path. Before using any session variable make sure you have setup this path.
PHP first creates a unique identifier for that particular session which is a random string
of 32 hexadecimal numbers such as 3c7foj34c3jj973hjkop2fc937e3443.
A cookie called PHPSESSID is automatically sent to the user's computer to store unique
session identification string.
A file is automatically created on the server in the designated temporary directory and
bears the name of the unique identifier prefixed by sess_ ie
sess_3c7foj34c3jj973hjkop2fc937e3443.
When a PHP script wants to retrieve the value from a session variable, PHP automatically gets the
unique session identifier string from the PHPSESSID cookie and then looks in its temporary directory
for the file bearing that name and a validation can be done by comparing both values.
A session ends when the user loses the browser or after leaving the site, the server will terminate the
session after a predetermined period of time, commonly 30 minutes duration.
Session variables are stored in associative array called $_SESSION[]. These variables can be accessed
during lifetime of a session.
The following example starts a session then register a variable called counterthat is incremented each
time the page is visited during the session.
Make use of isset() function to check if session variable is already set or not.
Login Page
Login page should be as follows and works based on session. If the user close the session, it will erase
the session data.
PROGRAM:
<?php
ob_start();
session_start();
?>
<?
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
?>
<style>
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #ADABAB;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
color: #017572;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
height: auto;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
border-color:#017572;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-color:#017572;
}
h2{
text-align: center;
color: #017572;
}
</style>
</head>
<body>
<?php
$msg = '';
</div>
</body>
</html>
Logout.php
It will erase the session data.
<?php
session_start();
unset($_SESSION["username"]);
unset($_SESSION["password"]);
Result:
Conclusion: Hence we have implemented PHP script for-Session Management (login form).
EXPERIMENT NO. 9
AIM: AJAX Script using XMLHttpRequest PHP.
OBJECTIVE:
TOOLS REQUIRED:
THEORY:
What is AJAX ?
AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and
more interactive web applications with the help of XML, HTML, CSS and Java Script.
Conventional web application transmit information to and from the sever using synchronous requests. This
means you fill out a form, hit submit, and get directed to a new page with new information from the server.
With AJAX when submit is pressed, JavaScript will make a request to the server, interpret the results and
update the current screen. In the purest sense, the user would never know that anything was even transmitted
to the server.
PROGRAM:
<html>
<head>
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "gethint.php?q=" + str, true);
xmlhttp.send();
}
}
</script>
</head>
<body>
Result:
To clearly illustrate how easy it is to access information from a database using Ajax and PHP, we are
going to build MySQL queries on the fly and display the results on "ajax.html". But before we proceed,
lets do ground work. Create a table using the following command.
NOTE − We are assuming you have sufficient privilege to perform following MySQL operations.
Now dump the following data into this table using the following SQL statements.
PROGRAM:
<html>
<body>
try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e) {
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
</form>
<?php
$dbhost = "localhost";
$dbuser = "dbusername";
$dbpass = "dbpassword";
$dbname = "dbname";
//Select Database
mysql_select_db($dbname) or die(mysql_error());
//build query
$query = "SELECT * FROM ajax_example WHERE sex = '$sex'";
if(is_numeric($age))
$query .= " AND age <= $age";
if(is_numeric($wpm))
$query .= " AND wpm <= $wpm";
//Execute query
$qry_result = mysql_query($query) or die(mysql_error());
$display_string .= "</table>";
echo $display_string;
?>
Result:
Conclusion: Hence we have implemented PHP script to update and retrieve data stored in database
from user using Ajax.
3. Quiz on the Subject
What is Linux?
What is the difference between UNIX and LINUX?
Why we use LINUX?
What’s the difference between the include() and require() functions?
What is the difference between GET and POST?
What is PHP?
What is the use of "echo" in php?
How to include a file to a php page?
How to declare an array in php?
What is the use of 'print' in php?
What is use of in_array() function in php ?
What is the difference between Session and Cookie?
How to set cookies in PHP?
How to Retrieve a Cookie Value?
How to create a session? How to set a value in session ? How to Remove data from a
session?
How to create a mysql connection?
How to execute an sql query? How to fetch its result ?
How to create a text file in php?
What are the different types of errors in PHP ?
What is the purpose of php.ini file?
What are the different types of PHP variables?
Explain the syntax for 'foreach' loop.
What is associate array?
What is Multidimensional array?
How will you concatenate two strings in PHP?
How will you find the length of a string in PHP?
What is Ajax?
What are Ajax applications?
What are the advantages of Ajax?
What are all the technologies used by Ajax?
What are all the browsers support AJAX?
How can we cancel the XMLHttpRequest in AJAX?
What are the protocols used by Ajax?
What is XML?
What are the features of XML?
What are the differences between HTML and XML?
What is XML DOM Document?
What is XPath?
What is an attribute?
What is XML Element?
What is XML Parser?
4. Conduction of VIVA-VOCE Examinations:
Teacher should conduct oral exams of the students with full preparation. Normally the objective questions
with guess are to be avoided. To make it meaningful, the questions should be such that depth of the
student in the subject is tested. Oral Exams are to be conducted in co-cordial situation. Teachers taking
oral exams should not have ill thoughts about each other & courtesies should be offered to each other in
case of opinion, which should be critically suppressed in front of the students.
5. Evaluation and marking system:
Basic honesty in the evaluation and marking system is essential and in the process impartial nature of the
evaluator is required in the exam system. It is a primary responsibility of the teacher to see that right
students who really put their effort & intelligence are correctly awarded.
The marking pattern should be justifiable to the students without any ambiguity and teacher should see
that students are faced with just circumstance.