0% found this document useful (0 votes)
2 views26 pages

PRIYA OSS RECORD

The document outlines various programming tasks including creating web pages with frames and tables, incorporating CSS, writing shell programs for factorial and palindrome checks, and developing a simple calculator and a scrolling message in JavaScript. Each task includes an aim, algorithm, and program coding with specific file names. The results confirm the successful execution of each program.

Uploaded by

lovelyboys833
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views26 pages

PRIYA OSS RECORD

The document outlines various programming tasks including creating web pages with frames and tables, incorporating CSS, writing shell programs for factorial and palindrome checks, and developing a simple calculator and a scrolling message in JavaScript. Each task includes an aim, algorithm, and program coding with specific file names. The results confirm the successful execution of each program.

Uploaded by

lovelyboys833
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 26

1. Create a web page with Frames and Tables.

AIM: To create a web page with Frames and Tables...

ALGORITHM:

Step 1: Start the Program


Step 2: Create a Web page using <html> tags.
Step 3: Using <frame> tag, divide the window into partitions save this file as
(ex1frames.html).
Step 4: Using the Heading tags <h1>, <h2>,… create the heading on the top frame
and save this file as (ex1top.html).
Step 5: Using <ol>, <li> and <ul> List tags create a list of items on the left frame and
this file as (ex1.left.html).
Step 6: Create a table using <table> tag on the right frame by dividing the table into
rows and column using rows pan and cols pan and save this file as
(ex1right.html)
Step 7: Execute the file (ex1frames.html) by opening either in Internet Explorer or
Google Chrome.
Step 8: Stop the Execution.

PROGRAM CODING:

File Name: ex1frames.html

<html>
<head>
<title>PROGRAM FOR FRAMES</title></head>
<frameset rows="30%,*">
<frame src="E:\OSS\ex1\ex1top.html">
<frameset cols="20%,*">
<frame src="E:\OSS\ex1\ex1left.html">
<frame src="E:\OSS\ex1\ex1right.html">
</frameset>
</frameset>
</html>
--------------------------------------------------------------------------------------------------------
File Name: ex1top.html

<html>
<body bgcolor="yellow">
<img src="E:\OSS\ex1\tuvlogo.bmp" align="LEFT">
<h1><center>THIRUVALLUR UNIVERSITY COLLEGE OF ARTS & SCIENCE
</center></h1>
<br><h2><center>Gajalnaickenpatti,Tirupattur
<br>Vellore District,Pincode:635 901.</center></h2>
</body>
</html>
---------------------------------------------------------------------------------------------------------
File Name: ex1left.html

<html>
<body bgcolor="pink">
<h2>UG COURSE DETAILS</h2>
<h3>
<ol type="1">
<li><a href="E:\OSS\ex1\cs.html">B.Sc. Computer Science</a>
<li><a href="E:\OSS\ex1\maths.html">B.Sc. Mathematics
<li><a href="E:\OSS\ex1\english.html">B.A. English</a>
<li><a href="E:\OSS\ex1\tamil.html">B.A. Tamil</a>
<li><a href="E:\OSS\ex1\bcom.html">B.Com.</a>
<li><a href="E:\OSS\ex1\bca.html">B.C.A.</a>
<li><a href="E:\OSS\ex1\bba.html">B.B.A.</a>
</ol></h3>
<h2>PG COURSE DETAILS</h2>
<ul type=fillround>
<li><a href="E:\OSS\ex1\ma.html">M.A. English</a>
<li><a href="E:\OSS\ex1\mcom.html">M.Com.</a>
</ul>
</body>
</html>
---------------------------------------------------------------------------------------------------------

File Name: ex1right.html

<html>
<body bgcolor="green"><br><br>
<center> <table border=5 width=50%>
<caption align=top><b><h3>Students Strength Details</h3></b></caption>

<tr><th>COURSES</th><th>I YEAR</th><th>II YEAR</th><th>III YEAR</th></tr>

<tr><td>B.Sc. Computer Science</td><td align=center>102</td><td


align=center>54</td><td align=center>46</td></tr>
<tr><td>B.Sc. Mathematics</td><td align=center>70</td><td align=center>67</td><td
align=center>65</td></tr>

<tr><td>B.A. English</td><td align=center>142</td><td align=center>134</td><td


align=center>140</td></tr>

<tr><td>B.A. Tamil</td><td align=center>40</td><td align=center> - </td><td


align=center> - </td></tr>

<tr><td>B.C.A.</td><td align=center>55</td><td align=center>54</td><td


align=center>50</td></tr>

<tr><td>B.Com.</td><td align=center>140</td><td align=center>120</td><td


align=center>135</td></tr>

<tr><td>B.B.A.</td><td align=center>45</td><td align=center>40</td><td


align=center>43</td></tr>

</body>
</html>
---------------------------------------------------------------------------------------------------------
RESULT: Thus Frames and Tables have been created.
------------------------------------------------------------------------------------------------------------
OUTPUT
2. Create a web page incorporating CSS ( Cascading Style Sheets)

AIM: To create a web page incorporating CSS (Cascading Style Sheets).

ALGORITHM:

Step 1: Start the Program


Step 2: Create an html document to incorporate style sheet.
Step 3: To implement external style sheet, create a (ex2.css) file by defining various
styles.
Step 4: Insert the style sheet (ex2.css file) in our web page using <link rel> tag.
Step 5: Save the file with html as the extension (eg: ex2css.html).
Step 6: Execute the file (ex2css.html) by opening either in Internet Explorer or
Google Chrome.
Step 7: Stop the Execution.

PROGRAM CODING:

File Name: ex2css.html

<html>
<head>
<link rel="stylesheet" type="text/css" href="E:\OSS\ex2\ex2.css">
</head>
<body>
<img src="E:\OSS\ex2\tuvlogo.bmp" width="160 height="160" align="left">
<h1>THIRUVALLUVAR UNIVERSITY COLLEGE OF ARTS & SCIENCE
</h1>
<h2>Gajalnaickenpatti , Tirupattur(via),<br>
Vellore, Pincode no:635 901. </h2> <br>

<h3>BONAFIDE CERTIFICATE </h3> <br>


<p>This is to that Selvan/Selvi .....................................................................
son/daughter of, Shri ....................................................................... is a bonafide
student of our college. Studying .......................................................... He/She
has appeared for ............ attendance of academic year 2012-2015. His/Her Date of
Birth is..................................... as per our college records.
</p>
<h4>Admission No:.............................. <br> SEAL </h4>
<h5 align="right">PRINCIPAL</h5> <br>
<h4>Date: ........................ <br>
Place: ........................ </h4>
</body>
</html>

------------------------------------------------------------------------------------------------------
File Name: ex2.css

h1
{
font-size:30pt;
text-align:center;
color:red;
font-style:bold;
}

body
{
background-color:yellow;
}

h2
{
text-align:center;
font-style:italic;
color:green;
}

h3
{
text-align:center;
font-style:bold;
color:black;
font-size:20pt;
text-decoration:underline;
}

P
{
text-align:justify;
color:blue;
font-size:18pt;
}

h4,h5
{
font-style:bold;
font-size:18;
}

---------------------------------------------------------------------------------------------------------
RESULT: Thus created a web page, by incorporating cascading style sheet.
---------------------------------------------------------------------------------------------------------

OUTPUT
3. Write a shell program to find the factorial of an integer positive number

AIM: To write a shell program to find the factorial of an integer positive number.

ALGORITHM:

Step 1: Start the Program


Step 2: Read a number ‘n’ to find the factorial value.
Step 3: Set f = 1.
Step 4: Execute the loop until n is less the 1.
(i) Calculate f = f * n.
(ii) Calculate n = n – 1.
Step 5: Print the result of the factorial in f.
Step 6: Save and execute the program.
Step 7: Stop the Execution.

PROGRAM CODING:

File Name: fact.sql

echo "Enter the positive input number"


read n
f=1
until [ $n -lt 1 ]
do
f = ' expr $f \* $n '
n = ' expr $n - 1 '
done
echo " The result is $f "

--------------------------------------------------------------------------------------------------
OUTPUT

Enter the positive input number 5


The result is 120
-----------------------------------------------------------------------------------------------------
Enter the positive input number 3
The result is 6
-----------------------------------------------------------------------------------------------------
Enter the positive input number 4
The result is 24
-----------------------------------------------------------------------------------------------------
RESULT: Thus the shell program to find the factorial of a given number has been
executed successfully.
------------------------------------------------------------------------------------------------------
4. Write a shell program for checking whether a given string is a palindrome or not

AIM: To Write a shell program for checking whether a given string is a palindrome or
not.

ALGORITHM:
Step 1: Start the Program.
Step 2: Read a string str to check whether it is palindrome or not.
Step 3: Find the length of the string and store it in len.
Step 4: Calculate len = len – 1.
Step 5: Set i = 1.
Step 6: Extract the desired column of value i from the string str using cut -c option
and store it in ch.
Step 7: Extract the desired column of value len from the string str using cut -c option
and store it in ch1.
Step 8: Check whether ch is not equal to ch1. If it is true then print the “Given input
string is not Palindrome”.
Step 9: Calculate len = len – 1.
Step 10: Calculate i = i +1.
Step 11: Otherwise Print the “Given input string is Palindrome”.
Step 12: Save and execute the file.
Step 13: Stop The Execution.

PROGRAM CODING:

File Name: palin.sql

echo " Enter the input string "


read str
len = ' echo $str | wc -c '
len = ' expr $len - 1 '
i=1
do
ch = 'echo $str | cut -c $i '
ch1 = 'echo $str | cut -c $len '
if [ $ch != $ch1 ]
then
echo "Given input string is not Palindrome "
exit
fi
len = ' expr $len - 1'
i = ' expr $i + 1 '
done
echo " Given input string is Palindrome "
------------------------------------------------------------------------------------------------------
OUTPUT
Enter the input string madam
Given input string is Palindrome
-------------------------------------------------------------------------------------------------------
Enter the input string college
Given input string is not Palindrome
--------------------------------------------------------------------------------------------------------
RESULT: Thus a shell program for checking whether a given string is a palindrome or
not has been executed successfully.
---------------------------------------------------------------------------------------------------------

5. Create a simple calculator in Java script.

AIM: To create a simple calculator in Java script.

ALGORITHM:

Step 1: Create an html document using <html> tags.


Step 2: Using Java Script Language <script> tag insert the script coding.
Step 3: Declare a variable a.
Step 4: Create a function calc(value):
a. Calculate a = a + value.
b. Input the value for a.
Step 5: Design a calculator using <form> and <table>tag.
Step 6: Create the Output text box and buttons for the calculator.
Step 7: Write functions to do arithmetic operations.
Step 8: Call the functions accordingly.
Step 9: Save and execute the file.
Step 10: Stop the execution

PROGRAM CODING:

File Name: ex5cal.html

<html>
<head> <title> CALCULATOR</title>
<center>
<h1> CALCULATOR </h1>
<script language="javascript">
var a=" "
function calc(value)
{
a+=value;
document.calculator.input.value=a;
}
</script> </head>

<body bgcolor=yellow>
<form name="calculator">
<table border=25 bordercolor=pink bgcolor=green cellpadding=12 cellspacing=10>
<tr><td>
<input type="text" name="input" fontsize=20 size=42>
<tr><td>
<input type="button" value=" CLEAR " onclick="input.value=' ';a=' ' ">
<input type="button" value=" MOD " onclick="calc('%')">
<input type="button" value=" * " onclick="calc('*')"> <br>

<input type="button" value=" 7 " onclick="calc('7')">


<input type="button" value=" 8 " onclick="calc('8')">
<input type="button" value=" 9 " onclick="calc('9')">
<input type="button" value=" / " onclick="calc('/')"> <br>

<input type="button" value=" 4 " onclick="calc('4')">


<input type="button" value=" 5 " onclick="calc('5')">
<input type="button" value=" 6 " onclick="calc('6')">
<input type="button" value=" - " onclick="calc('-')"> <br>

<input type="button" value=" 1 " onclick="calc('1')">


<input type="button" value=" 2 " onclick="calc('2')">
<input type="button" value=" 3 " onclick="calc('3')">
<input type="button" value=" + " onclick="calc('+')"> <br>

<input type="button" value=" 0 " onclick="calc('0')">


<input type="button" value=" 00 " onclick="calc('00')">
<input type="button" value=" . " onclick="calc('.')">
<input type="button" value=" = " onclick="input.value=eval(a)">

</tr></td> </table>
</form> </body>
</html>
OUTPUT

RESULT: Thus created a simple calculator using Java script.


6. Write a JavaScript program to scroll your name in the scroll bar

AIM: To Write a JavaScript program to scroll your name in the scroll bar.

ALGORITHM:

Step 1: Create an html document using <html> tag.


Step 2: Insert java script coding in html document using <script> tag.
Step 3: Set msg ="WELCOME TO TUCAS-TIRUPATTUR", spacer="............" and
pos = 0.
Step 4: Create a function scrollmessage(), which helps to print the msg and spacer on
the scroll bar using windows.status and windows.setTimeout command.
Step 5: Save the file as ex6scr.html and execute the program.
Step 6: Stop the execution.

PROGRAM CODING

File Name: ex6scr.html

<html>
<head> <title>JAVA SCROLL TASK BAR</title>
<script language="javascript">
msg="WELCOME TO TUCAS-TIRUPATTUR";
spacer="............";
pos=0;
function scrollmessage()
{
window.status=msg.substring(pos,msg.length)+spacer+msg.substring(0,pos);
pos++;
if (pos>msg.length) pos=0;
window.setTimeout("scrollmessage()",300);
}
scrollmessage();
</script>
</head>

<body>
<p>THIRUVALLUVAR UNIVERSITY COLLEGE OF ARTS AND SCIENCE,
TIRUPATTUR</p>
<p>LOOK AT THE STATUS LINE AT THE BOTTOM OF THE PAGE</p>
</body>
</html>
OUTPUT

RESULT: Thus JavaScript program to scroll my name in the scroll bar has been
executed successfully.

7. Develop a program and check message passing mechanism between pages

AIM: To develop a program and check message passing mechanism between pages.

ALGORITHM:

Step 1: Create PHP document using <?php> <?> tag.


Step 2: Use session_start() to create session.
Step 3: Set session variables and values using super global variable $_SESSION.
Step 4: Save the first program in prescribed folder (eg.
c:\xampp\phpMyAdmin/ex7/page1.php)
Step 5: Create the session using session_start().
Step 6: Access session variables of the first page in the second page using super
global variable (eg. $_SESSION['Name'];) .
Step 7: Save the first program in prescribed folder (eg.
c:\xampp\phpMyAdmin/ex7/page2.php)
Step 8: Start execute the program on google chrome or internet explorer by setting
the path as http:/localhost/phpmyadmin/ex7/page1.php for the first file and
http:/localhost/phpmyadmin/ex7/page2.php for the second file
Step 9: Execute the two php files in two separate browser tabs.
Step 10: Stop the execution.
PROGRAM CODING:

File Name: c:\xampp\phpMyAdmin/ex7/page1.php

<?php
// page1.php
session_start();
echo 'Welcome to page #1';
$_SESSION['Name'] = 'PRIYA ';
$_SESSION['Dept'] = 'DEPT OF CS ';
$_SESSION['time'] = time();

// Or maybe pass along the session id, if needed


echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
?>
------------------------------------------------------------------------------------------------------
File Name: c:\xampp\phpMyAdmin/ex7/page2.php

<?php
// page2.php

session_start();
echo 'Welcome to page #2<br />';

echo $_SESSION['Name']; // PRIYA


echo $_SESSION['Dept']; // DEPT OF CS
echo date('d/m/y - h:m:s', $_SESSION['time']);

// You may want to use SID here, like we did in page1.php


echo '<br /><a href="page1.php">page 1</a>';
?>

OUTPUT:
RESULT: Thus developed the program to check message passing mechanism between
pages.

8. Develop a program and check file system functions, date &time functions

AIM: To develop a program and check file system functions, date &time functions.

ALGORITHM:

STEP 1: Create a PHP file using <?php> <?> tag.


STEP 2: Open a text file in “a+” mode to write into the file, using fopen() function.
STEP 3: Close the file.
STEP 4: Open the file created in step 2 to read from the file in “r+” mode, using fopen()
function.
STEP 5: Display the text from the file.
STEP 6: Display system date and time using Date() and Time() functions.
STEP 7: Save and execute the Program.
STEP 7: Stop the program.

PROGRAM CODING:

<html> <head> <title>Writing a file using PHP </title> </head>


<body>
<?php
$filename = "c:/xampp/htdocs/file/tmp.txt";
$file = fopen( $filename, "a+" );
fwrite( $file, "This is a simple test\n" );
fclose( $file );
$filename = "c:/xampp/htdocs/file/tmp.txt";
$file = fopen( $filename, "r+" );
$filesize = filesize( $filename );
$filetext = fread( $file, $filesize );
fclose( $file );
echo ( "File size : $filesize bytes" );
echo ( "<pre>$filetext</pre>" );
echo "Reading date is " . date("Y/m/d") . "<br>";
echo "The Reading file time is " . date("h:i:sa");
?> </body>
</html>

OUTPUT

RESULT:

Thus developed the program to check file system functions, date &time functions

9: Create a student database table in MYSQL and manipulate records (insert ,delete,
update) in a web browser

AIM: To create a student database table in MYSQL and manipulate records (insert ,delete,
update) in a web browser.

ALGORITHM:

STEP 1: Create a ‘student’ table in mysql.


STEP 2: Create a PHP file using <?php> <?> tag
STEP 3: Use mysql_query() function to execute the sql queries.
STEP 4: Insert records in the table.
STEP 5: Modify record.
STEP 6: Update record.
STEP 7: Stop the program.

PROGRAM CODING:

-------------------------------------------------------- Index.php -------------------------------------------

<?php
<html>
<head>
<title> Student </title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script>
function validateForm()
{
var x = document.forms["myForm"]["rollno"].value;
if(x==null || x=="")
{
alert("Roll No must be filled.");
return false;
}
var y = document.forms["myForm"]["name"].value;
if(y==null || y=="")
{
alert("Name must be filled.");
return false;
}
var z = document.forms["myForm"]["address"].value;
if(z==null || z=="")
{
alert("Address must be filled.");
return false;
}
var c = document.forms["myForm"]["contactno"].value;
if(c==null || c=="")
{
alert("Number must be filled.");
return false;
}
}
</script>
</head>
<body>
<?php
if (isset($_GET['msg']))
{
echo $_GET['msg'];
}
if(isset($_GET['msg1']))
{
echo $_GET['msg1'];
}
if(isset($_GET['msg2']))
{
echo $_GET['msg2'];
}
?>
<form name="myForm" action="create.php" onSubmit="return validateForm();"
method="post">
<table border="0" align="center" cellpadding="10" cellspacing="1" width="500">
<tr class="tableheader">
<td align="center" colspan="2">Student Registration</td>
</tr>
<tr class="tablerow" >
<td align="right">Roll No</td>
<td><input type="text" name="rollno" maxlength="5"></td>
</tr>
<tr class="tablerow">
<td align="right">Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr class="tablerow">
<td align="right">Address</td>
<td><textarea name="address" required> </textarea></td>
</tr>
<tr class="tablerow">
<td align="right">Contact No</td>
<td><input type="text" name="contactno" maxlength="10"></td>
</tr>
<tr class="tableheader">
<td align="center" colspan="2"><input type="submit" name="submit"
value="Submit"></td>
</tr>
</table>
</form>
<form action="deletechk.php" method="post" onSubmit="return validate();">
<center>
<table height="200px" style="border:3px black solid;border-radius:5px" width="600px">
<th colspan="7" height="40pxs" style="border-bottom:3px black solid">List of Records
</th></th>

<?php
$q="select count(*) \"total\" from stud";
$ros=mysql_query($q,$conn);
$row=(mysql_fetch_array($ros));
$total=$row['total'];
echo "Total number of rows : ";
echo $total;
$q="select * from stud";
$ros=mysql_query($q,$conn);
$serial=1;
while($row=mysql_fetch_array($ros))
{
echo '<tr>';
echo '<td align="center" width="10px" style="border-bottom:1px #a1a1a1 solid">'.
$serial++ .'.';
echo '<td align="center" style="border-bottom:1px #a1a1a1 solid">'.$row['rollno'];
echo '<td align="center" style="border-bottom:1px #a1a1a1 solid">'.$row['name'];
echo '<td align="center" style="border-bottom:1px #a1a1a1 solid">'.$row['address'];
echo '<td align="center" style="border-bottom:1px #a1a1a1 solid">'.$row['contactno'];
echo "<td>" . "<a href='update.php?id=$row[id]'> Update </a>" . "</td>";
echo "<td>" . "<a href='' onClick='ConfirmDelete($row[id])'> Delete </a>" . "</td>";
echo '</tr>';
}
echo '</table>';
echo '<br/>';
?>
</table>
</center>
</form>
</body>
</html>

------------------------------------------------------- Create.php -------------------------------------------

<?php
include 'include/connection.php';
$rollno = $_POST['rollno'];
$name = $_POST['name'];
$address = $_POST['address'];
$contactno = $_POST['contactno'];
if($_POST['submit']){
echo $query = "INSERT INTO stud (rollno,name,address,contactno)
VALUES('$rollno','$name','$address','$contactno')";
$exe = mysql_query($query);
header('Location: index.php?msg1=Details Added Successfully.');
}
?>

--------------------------------------------------- Update.php ------------------------------------------------

<?php
include 'include/connection.php';
$id = $_GET['id'];
$query = "SELECT * FROM stud WHERE id='$id'";
$result = mysql_query($query);
$person = mysql_fetch_object($result);
?>
<html>
<head>
<script>
function validateForm()
{
var x = document.forms["myForm"]["rollno"].value;
if(x==null || x=="")
{
alert("Roll No must be filled.");
return false;
}
var y = document.forms["myForm"]["name"].value;
if(y==null || y=="")
{
alert("Name must be filled.");
return false;
}
var z = document.forms["myForm"]["address"].value;
if(z==null || z=="")
{
alert("Address must be filled.");
return false;
}
var c = document.forms["myForm"]["contactno"].value;
if(c==null || c=="")
{
alert("Number must be filled.");
return false;
}
}
</script>
</head>
<body>
<center>
<h1> Student Registration </h1>
<form name ="myForm" action = "update1.php?id=<?php echo $id?>"
onSubmit="return validateForm()" method="post">
Roll No: <input type="text" name="rollno" maxlength="5" value="<?php echo
$person->rollno;?>"><br/><br>
Name: <input type="text" name="name" value="<?php echo
$person->name;?>"><br/><br>
Address: <textarea name="address" required><?php echo
$person->address;?></textarea><br/><br>
Contact No: <input type="text" name="contactno" maxlength="10" value="<?php echo
$person->contactno;?>"><br/><br>
<input type="submit" name="submit" value="Submit">
</form>
</center>
</body>
</html>

--------------------------------------------------- Delete.php -------------------------------------------------

<?php
include 'include/connection.php';
$id = $_GET['id'];
$query = "DELETE FROM stud WHERE id = '$id'";
$exe = mysql_query($query);
header('Location: index.php?msg1=Record Deleted Successfully.');
?>

--------------------------------------------------- Test.sql ------------------------------------------------------

CREATE TABLE IF NOT EXISTS `stud` (


`id` int(11) NOT NULL AUTO_INCREMENT,
`rollno` int(11) NOT NULL,
`name` varchar(250) NOT NULL,
`address` varchar(250) NOT NULL,
`contactno` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
INSERT INTO `stud` (`id`, `rollno`, `name`, `address`, `contactno`) VALUES
(5, 12345, 'Bharath kumar', 'Gudiyattam\r\nVellore\r\n', 9944806649),
(6, 11234, 'Ashokkumar', 'Gudiyattam', 9944806649),
(7, 11235, 'Bharath', 'Kmg ', 9912345641),
(8, 11233, 'Test', 'Test Disp ', 7898789878),
(9, 12346, 'amma', 'Ammanagkuppam', 1234566788),
(10, 12222, 'Kumar', 'Ammanag Kuppam\r\ngudiyattam', 2365478962);
OUTPUT:
RESULT: Thus created a student database table in MYSQL and manipulate records (insert,
delete, update) in a web browser.

10. Develop a program using cookies and session

AIM: To develop a program using cookies and session.

ALGORITHM:

STEP 1: Create a PHP file using <?php> <?> tag.


STEP 2: Enable cookie using set_cookie().
STEP 3: Set cookie variables and values using super globals $_COOKIE.
STEP 4: Access cookie variables, modify the values.
STEP 5: Delete cookie using set_cookie().
STEP 4: Stop the program.

PROGRAM CODING:
--------------------------------------------- main.html ------------------------------------------
<html>
<head> COOKIES </head>
<body>
<form action = "cookies.php" method ="post">
The last visited time was
<input type="submit" name="s" value = "click">
</form>
</body>
</html>

------------------------------------------- cookies.php -----------------------------------------


<?php
$var=60*60*24*60+time();
setcookie('lastvisit',date("G:i-m/d/y"),$var);
if(isset($_COOKIE['lastvisit']))
{
$visit=$_COOKIE['lastvisit'];
echo "Your last visit was :".$visit;
}
else
echo "you've got some stale cookies";
?>
---------------------------------------- session.php ---------------------------------------------

<?php
session_start();
?>
<html>
<head> SESSIONS </head>
<body bgcolor="cyan">
<font size="20" face=" broadway">
<h1> Tracking visitors with sessions </h1>
<?php
if (! isset($_SESSION))
{
$_SESSION[‘count’]=0;
}
else
{
$_SESSION[‘count’]++;
}
echo "You are visitor number :" ,$_SESSION['count'];
echo " <br> ";
echo "The session id is :", session_id();
?>
</font>
</body>
</html>

OUTPUT: FORM DESIGN IN HTML


COOKIES

SESSION: (Each time the user refreshes this page, the count is incremented by 1 )
RESULT: Thus developed the program using cookies and session.

You might also like