Fybscit Div B Roll No 212 Web Programming All Practicals
Fybscit Div B Roll No 212 Web Programming All Practicals
b. Design a web page with links to different pages and allow
navigation between web pages.
c. Design a web page with different tables. Design a web page using a
table so that the content appears well placed.
d. Design a web page with a form that uses all types of controls.
b. Design a form and validate all the controls placed on the form using
Java Script.
c. Write a JavaScript program to display all the prime numbers between 1
and 100.
d. Write a JavaScript program to accept a number from the user and
display the sum of its digits.
e. Write a program in JavaScript to accept a sentence from the user and
display the number of words in it. (Do not use split () function).
WEB PROGRAMMING 1
FYBSC.IT DIV:-B ROLL NO:-212
a. Write a PHP Program to accept a number from the user and print it
factorial.
b. Write a PHP program to accept a number from the user and print
whether it is prime or not.
a. Write a PHP code to find the greater of 2 numbers. Accept the no.
from the user.
WEB PROGRAMMING 2
FYBSC.IT DIV:-B ROLL NO:-212
10. Email
WEB PROGRAMMING 3
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 1 (a)
Use of Basic Tags
AIM : a)Design a web page using different text formatting tags.
CODE :
<html>
<head>
<title>vidhan_Practical 1a_</title>
</head>
<body>
</body>
</html>
Output:
WEB PROGRAMMING 4
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 1 (b)
AIM: Design a web page with links to different pages and allow navigation between web pages.
<html>
<head>
<title>vidhan_practical1(b)</title>
</head>
<body> <h2> WELCOME<h2></br>
<strong> Web Navigation Practical</strong></br>
<a href="home.html">Home</a></br>
<div align="center">
WELCOME TO THE HOME PAGE</br>
This is the practical no.1(b) of web navigation
</body>
</html>
Output:-
WEB PROGRAMMING 5
FYBSC.IT DIV:-B ROLL NO:-212
<html>
<head>
<title>vidhan_Home</title>
</head>
<body>
<div align="center">
<strong>About Environment</strong>
</div>
Environment means anything that surrounds us. </br> It can be living
(biotic) or non-living (abiotic) things. </br> It includes physical,
chemical and other natural forces. </br> Living things live in their
environment. </br> They constantly interact with it and adapt
themselves to conditions in their environment. </br>
<a href="Noisepollution.html">Noise pollution</a>
</body>
</html>
Output:-
WEB PROGRAMMING 6
FYBSC.IT DIV:-B ROLL NO:-212
<html>
<head>
<title>vidhan_Noise pollution</title>
</head>
<body>
<div align="center">
<strong>About Environment</strong>
</div>
Noise pollution is considered to be any unwanted or disturbing
sound that affects the health and well-being of humans and other
organisms. Sound is measured in decibels. ... </br> Noise pollution
impacts millions of people on a daily basis. </br> The most common
health problem it causes is Noise Induced Hearing Loss (NIHL).</br>
</body>
</html>
Output:-
WEB PROGRAMMING 7
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 1 (C)
CODE:
<html>
<head>
<title> vidhan_stylesheet</title>
</head>
<style>
body
{bg-color: yellow;
color:grey;
}
h1
{color:maroon;
margin-left:40px;
}
p{font-family:"Algerian";
}
ul.a
{
list-style-type:circle
}
ul.b
WEB PROGRAMMING 8
FYBSC.IT DIV:-B ROLL NO:-212
{
list-style-type:square
}
</style>
<body>
<h1>This is Heading</h1>
<p> List of programming language</p>
<ul class ="a">
<li>HTML</li>
<li>C</li>
<li>java</li></ul>
<ul class ="b">
<li>HTML</li>
<li>C</li>
<li>java</li></ul>
</body>
<html>
Output:-
WEB PROGRAMMING 9
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 2 (a)
Image maps (Tables, Forms and Media)
CODE :
<!DOCTYPE html>
<html>
<head>
<title>vidhan_Imagemap</title>
</head>
<h3>Mapping an Image</h3>
<body>
<img src="planets.gif"
usemap="#Solarmap">
<map name="Solarmap">
<area shape="circle" coords="60,60,40" alt="mercury"
href="https://en.wikipedia.org/wiki/Mercury_(planet)">
WEB PROGRAMMING
10
FYBSC.IT DIV:-B ROLL NO:-212
</map>
</body>
</html>
WEB PROGRAMMING
11
FYBSC.IT DIV:-B ROLL NO:-212
Output:-
PRACTICAL NO 2 (b)
AIM: B)Design a web page demonstrating different semantics.
<figure>
<img src="times.png" alt="" align="center" style="width: 100%"> <figcaption>TIMES OF
INDIA</figcaption>
</figure>
</main>
<footer>
<article><h3>Maharashtra News Live Updates:</h3>
<aside>
<p>Mumbai will be unlocked by end of this month, says mayor Kishori Pednekar
</p>
</aside>
<p>There is good news for Mumbaikars. Mumbai will be unlocked by the end of this month. We have
made up our minds, but it is essential for the people to wear masks and observe social distancing:
Mumbai Mayor Kishori Pednekar (ANI)
</p>
</article>
<details>
<summary class="GFG">Details</summary>
</br>
<p></br>Mumbai Mayor Kishori Pednekar on Tuesday said the city would be unlocked by the end of
this month. She said, "We have made up our minds, but it is essential for the people to wear masks
and observe social distancing." Stay with TOI for all the latest updates:
</p>
</details>
<p>Posted by:Times of India</p>
<p>Contact: <a href="https://timesofindia.indiatimes.com/city/mumbai/mumbai-news-live-updates-
covid-19-cases-omicron-maharashtra-bmc-pollution-uddhav-thackeray-shiv-sena-8-february-2022/
liveblog/89413105.cms">
<a>Times of india </a>.
</p>
</footer>
</main>
</body>
</html>
WEB PROGRAMMING
13
FYBSC.IT DIV:-B ROLL NO:-212
OUTPUT:-
WEB PROGRAMMING
14
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 2 (c)
AIM:Design a web page with different tables. Design a web pages using table so that the
content appears well placed.
CODE:
<html>
<body>
<div class="one" align="center">
<p>Chikitsak Samuhas's</p>
<p>Sir Sitaram & Lady shamtaramPatkar College of Arts and
Science</p>
<p>and V.P. Varde College Commerce & Economics </p>
<p>An Autonomous college, Affiliated to University of Mumbai </p>
<b><p>F.Y.B.Sc.IT Divison B Semester 2nd YEAR 2021-2022</p></b>
</div>
<head>
<style>
.two table {
background-color:green;
}
</style>
</head>
WEB PROGRAMMING
15
FYBSC.IT DIV:-B ROLL NO:-212
<section>
<div class="two" align="center" >
<table height="100px" width="200px" table border="1px">
<div class="ok">
<tr>
<th>Timing</th>
<th>Monday</th>
<th>Tuesday </th>
<th>Wednesay</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
</tr>
</div>
<tr>
<th>8:00 to 8:50</th>
<th>Microprocessor architecture </th>
<th>Microprocessor architecture </th>
<th>green computing</th>
<th>Web programming </th>
<th>Microprocessor architecture</th>
<th> holiday</th>
</tr>
WEB PROGRAMMING
16
FYBSC.IT DIV:-B ROLL NO:-212
<tr>
<th>9:00 to 9:50</th>
<th>Microprocessor architecture</th>
<th>Microprocessor architecture </th>
<th>Numerical and Statistical Methods</th>
<th>Object Oriented Programming </th>
<th>green computing </th>
<th>holiday</th>
</tr>
<tr>
<th>10:10 to 11:00</th>
<th>Web programming</th>
<th>Object Oriented Programming </th>
<th>Object Oriented Programming</th>
<th>Numerical and Statistical Methods</th>
<th>Numerical and Statistical Methods</th>
<th>holiday</th>
</tr>
<tr>
<th>11:30 to 12:20</th>
<th> </th>
<th> </th>
<th>Microprocessor architecture</th>
<th></th>
WEB PROGRAMMING
17
FYBSC.IT DIV:-B ROLL NO:-212
<th> </th>
<th> </th>
</tr>
<tr>
<th>12:35 to 1:25</th>
<th> </th>
<th> </th>
<th>web programming </th>
<th></th>
<th></th>
<th> </th>
</tr>
<tr>
<th>11:30 to 2:00(practical session)</th>
<th>Numerical and Statistical Methods</th>
<th>Web programming </th>
<th> </th>
<th>Object Oriented Programming</th>
<th>Web programming</th>
<th> holiday</th>
</tr>
WEB PROGRAMMING
18
FYBSC.IT DIV:-B ROLL NO:-212
</tr>
</table>
</div>
</body>
</html>
Output:-
WEB PROGRAMMING
19
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 2 (d)
AIM : d)Design a web page with a form that uses all types of controls.
CODE :
<html>
<head>
<title>vidhan practical 2D</title>
</head>
<body bgcolor="white">
<div align="center">
<br>
<h1>Enter Your Personal Information</h1>
<p><i>Creating form practicals</i></p>
</div>
<hr>
<div align="center">
<form>
<table>
<tr>
<td width="100">First Name: </td>
<td width="100"><input type="text"
name="fname"/></td><br><br>
</tr>
<tr>
<td width="100">Last Name: </td>
WEB PROGRAMMING
20
FYBSC.IT DIV:-B ROLL NO:-212
<td width="100">
<input type="radio" name="hobbies">Singing
<input type="radio" name="hobbies">Dancing
<input type="radio" name="hobbies">Playing
cricket
</td>
<br><br>
</tr>
<tr>
<td width="100">Upload your image:</td>
<td width="100">
<input type='file' accept='image/*'></td
<br><br>
</tr>
<tr>
<td width="100">Comments:</td>
<td width="100"><textarea
name="comments" rows="4" cols="50">
Your Comments...
</textarea>
<br><br>
</tr>
</table>
<br>
WEB PROGRAMMING
22
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
23
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL 2E
CODE:
<html>
<head>
<title>vidhan practical2E</title>
</head>
<body>
<div id="masthead">
<h1 class="pagetitle">Incorporating Audio and Video Practical</h1>
<h5 class="tagline"><i>Using HTML5 tags</i></h5>
<hr>
</div>
</body>
</html>
OUTPUT:-
WEB PROGRAMMING
24
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
25
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 3 (a)
Java Script
AIM : a) Using JavaScript design, a web page that prints factorial/Fibonacci series/any
given series.
CODE :
<html>
<head>
<title>VIDHAN practical3A</title>
</head>
<body>
<br>
<h1>Factorial of number using java script</h1>
<h2>Enter valid number...!</h2>
<script>
function submit(){
var num =
parseInt( document.getElementById("num").value);
WEB PROGRAMMING
26
FYBSC.IT DIV:-B ROLL NO:-212
if( isNaN(num) ){
alert("Enter valid number");
return;
}
var factorial = calcFact(num);
document.getElementById("answer").innerHTML = factorial;
}
function calcFact(num){
var i;
var fact=1;
for(i=1;i<=num;i++){
fact=fact*i;
}
return fact;
}
</script>
</body>
</html>
WEB PROGRAMMING
27
FYBSC.IT DIV:-B ROLL NO:-212
Output:-
PRACTICAL NO 3 (b)
AIM : b) Design a form and validate all the controls placed on the form using Java Script.
CODE :
<html>
<head>
<title>vidhan_PRAC3B </title>
<script>
function Validation () {
var name = document.forms["RegForm"]["Name"];
var email = document.forms["RegForm"]["EMail"];
var phone = document.forms["RegForm"]["Telephone"];
var what = document.forms["RegForm"]["Subject"];
var password = document.forms["RegForm"]["Password"];
var address = document.forms["RegForm"]["Address"];
if (name.value == "") {
window.alert("Please enter your name.");
WEB PROGRAMMING
28
FYBSC.IT DIV:-B ROLL NO:-212
name.focus();
return false;
}
if (address.value == "") {
window.alert("Please enter your address.");
address.focus();
return false;
}
if (email.value == "") {
window.alert(
"Please enter a valid e-mail address.");
email.focus();
return false;
}
if (password.value == "") {
window.alert("Please enter your password");
password.focus();
return false;
}
if (phone.value == "") {
WEB PROGRAMMING
29
FYBSC.IT DIV:-B ROLL NO:-212
window.alert(
"Please enter your telephone number.");
phone.focus();
return false;
}
if (what.selectedIndex < 1) {
alert("Please enter your course.");
what.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<h1 style="text-align: center;">REGISTRATION FORM</h1>
<form name="RegForm"
onsubmit="return Validation ()" method="post">
<p>Name: <input type="text"
size="65" name="Name" /></p>
<br />
<p>Address: <input type="text"
WEB PROGRAMMING
30
FYBSC.IT DIV:-B ROLL NO:-212
<p>
SELECT YOUR COURSE
<select type="text" value="" name="Subject">
<option> </option>
<option>BSc(IT)</option>
<option>BBA</option>
<option>BCA</option>
<option>B.COM</option>
<option>MSc(IT)</option>
</select>
</p>
WEB PROGRAMMING
31
FYBSC.IT DIV:-B ROLL NO:-212
<br />
<p>Comments: <textarea cols="55"
name="Comment"> </textarea></p>
<p>
<input type="submit"
value="send" name="Submit" />
<input type="reset"
value="Reset" name="Reset" />
</p>
</form>
</body>
<style>
div {
box-sizing: border-box;
width: 100%;
border: 100px solid black;
float: left;
align-content: center;
align-items: center;
}
form {
margin: 0 auto;
width: 600px;
}
WEB PROGRAMMING
32
FYBSC.IT DIV:-B ROLL NO:-212
</style>
</html>
Output:-
PRACTICAL NO 3 (c)
AIM : c) Write a JavaScript program to display all the prime numbers between 1 and 100.
CODE :
<script>
function checkprimenumber(n)
{
for (c=2; c<=n-1; C++){
if (n%c== 0 ) {
return false;
}
return true;
}
}
WEB PROGRAMMING
33
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
34
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
35
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 3 (d)
AIM : d) Write a JavaScript program to accept a number from the user and display the sum
of its digits.
CODE :
<html>
<body>
<h1>JS Sum of Digits</h1>
<script>
function myfun()
{
var n;
n=document.getElementById("no").value;
var R,S=0;
while(n!=0)
{
R=n%10;
S=S+R;
n=Math.floor(n/10);
}
document.write("THE SUM IS OF THE DIGIT IS : " + S);
}
</script>
<form>
Enter The No. To Find Sum of Digits:<input type="number"
id="no"><br><br>
WEB PROGRAMMING
36
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 3 (e)
AIM : e)Write a program in JavaScript to accept a sentence from the user and display the
number of words in it. (Do not use split () function).
CODE :
<html>
<title>vidhan_practical3E</title>
<body>
<div align= "center">
<h1>Count of Words</h1>
<p>Type in the text box and click on the button to count th
words</p>
<textarea id="inputField" cols="58" rows="8" > </textarea>
<p>
<button onclick="countWords()"> Count words </button>
WEB PROGRAMMING
37
FYBSC.IT DIV:-B ROLL NO:-212
document.getElementById("show")
.innerHTML = numWords;
}
</script>
</body>
</html>
WEB PROGRAMMING
38
FYBSC.IT DIV:-B ROLL NO:-212
Output:-
PRACTICAL NO 3 (f)
AIM : f) Write a java script program to design simple calculator.
CODE :
<html>
<head>
<style>
div input[type=button]{
background-color: grey;
border: none;
color: #000000;
padding: 15px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
WEB PROGRAMMING
39
FYBSC.IT DIV:-B ROLL NO:-212
}
</style>
</head>
<body>
<form id="xyz" name="abc" align="center">
<input name="result"><br>
<input name="answ"><br><br>
<div>
WEB PROGRAMMING
40
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
41
FYBSC.IT DIV:-B ROLL NO:-212
</div>
</form>
<script>
function run1(){
document.abc.result.value+="1";
}
function run2(){
document.abc.result.value+="2";
}
function run3(){
document.abc.result.value+="3";
}
function run4(){
document.abc.result.value+="4";
}
function run5(){
document.abc.result.value+="5";
}
function run6(){
document.abc.result.value+="6";
}
function run7(){
document.abc.result.value+="7";
WEB PROGRAMMING
42
FYBSC.IT DIV:-B ROLL NO:-212
}
function run8(){
document.abc.result.value+="8";
}
function run9(){
document.abc.result.value+="9";
}
function run0(){
document.abc.result.value+="0";
}
function runadd(){
document.abc.result.value+="+";
}
function runsub(){
document.abc.result.value+="-";
}
function runmul(){
document.abc.result.value+="*";
}
function rundiv(){
document.abc.result.value+="/";
}
function runpoint(){
document.abc.result.value+=".";
WEB PROGRAMMING
43
FYBSC.IT DIV:-B ROLL NO:-212
}
function runresl(){
var ans=eval(document.abc.result.value);
document.abc.answ.value=ans;
}
function runreset(){
document.getElementById("xyz").reset();
}
</script>
</body>
</html>
Output:-
WEB PROGRAMMING
44
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 4 (a)
AIM : a) Control and looping statements and Javascript references.
CODE :
<html>
<head>
<title>vidhan_practical4A</title>
<script type="text/javascript">
var age = prompt("Please enter your age");
if(age>=18)
document.write("You are an adult <br />");
if(age<18)
document.write("You are NOT an adult <br />");
two = parseInt(two);
if (one == two)
document.write(one + " is equal to " + two + ".");
else if (one<two)
document.write(one + " is less than " + two + ".");
else
document.write(one + " is greater than " + two + ".");
</script>
</head>
<body>
</body>
</html>
Output:-
WEB PROGRAMMING
46
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 4 (b)
AIM : b) Design a web page demonstrating different looping statements.
CODE:
<!DOCTYPE html>
<html>
<head>
<title>vidhan_practical4B</title>
</head>
<body>
<form>
<h1 align="center">FOR LOOP</h1>
ENTER THE NO.TO PRINT SERIES UPTO THAT NO:<input
type="number" id="no1"><br><br>
<input type="submit" value="Check" onclick="myforloop()">
<h1 align="center">WHILE LOOP</h1>
ENTER THE NO.TO PRINT SERIES UPTO THAT NO:<input
type="number" id="no2"><br><br>
WEB PROGRAMMING
47
FYBSC.IT DIV:-B ROLL NO:-212
<script>
function myforloop() {
var n;
n=document.getElementById("no1").value;
for(i=1;i<=n;i++)
{
document.write( i+" <br>");
}
}
function mywhileloop() {
var n,i=1;
n=document.getElementById("no2").value;
while(i<n)
{
document.write(i + "<br>");
i++;
WEB PROGRAMMING
48
FYBSC.IT DIV:-B ROLL NO:-212
}
}
function mydowhileloop()
{
var n,i=1;
n=document.getElementById("no3").value;
do
{
document.write(i + "<br>");
i++;
}
while(i<n);
}
</script>
</body>
</html>
Output:-
WEB PROGRAMMING
49
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
50
FYBSC.IT DIV:-B ROLL NO:-212
(c2) Boolean
<!DOCTYPE html>
<html>
<head>
<title>vidhan_practical4C_2</title>
<script language="javascript">
function myFunction() {
document.getElementById("demo").innerHTML=Boolean (10
> 9);
}
WEB PROGRAMMING
52
FYBSC.IT DIV:-B ROLL NO:-212
</script>
</head> <body>
<p>Display the value of Boolean (10 > 9):
</p>
<button onclick="myFunction()">Try it</button>
<p id="demo" ></p>
</body>
</html>
(c3) Date
CODE:-
<!DOCTYPE html>
<html>
<head>
<title>vidhan_practical4c_3</title>
WEB PROGRAMMING
53
FYBSC.IT DIV:-B ROLL NO:-212
<script language="javascript">
document.write("date is :");
document.write(currentDate.getDate()+"/"+
(currentDate.getMonth()+1)+"/"+currentDate.getFullYear()
+"<br>");
document.write("Time is :");
document.write(currentDate.getHours()
+":"+currentDate.getMinutes()
+":"+currentDate.getSeconds());
</script>
</head>
<body>
</body>
</html>
OUTPUT:-
WEB PROGRAMMING
54
FYBSC.IT DIV:-B ROLL NO:-212
(C4) Function
CODE:- <!DOCTYPE html>
<html>
<head>
<title>vidhan_prac4c_4</title>
<script language="javascript">
addBraces=new Function("s","return'['+s+']'");
document.write (addBraces ("Have"));
document.write(addBraces("a"));
document.write(addBraces ("great"));
document.write(addBraces ("life"));
</script>
</head>
<body>
</body>
</html>
OUTPUT:-
WEB PROGRAMMING
55
FYBSC.IT DIV:-B ROLL NO:-212
(C5) MathNumber
CODE:-
<html>
<head>
<title>vidhan_practical4c_5</title>
<script language="javascript">
document.write("Random number:
"+Math.random(4)+"<br>");
document.write("Minimum number: "+Math.min
(777,27,67,-77)+"<br>");
document.write("Maximum number: "+Math.max
(999,299,399,899)+"<br>");
document.write("Round (77.6): "+Math.round
(77.6)+"<br>");
document.write("Ceil(5.6): "+Math.ceil(5.6) +"<br>");
document.write("Floor (7.4): "+Math.floor(7.4)+"<br>");
document.write("Square root of 5: "+Math.SQRT5+"<br>");
document.write("Square root of 2/4:
"+Math.SQRŢ2_4+"<br>");
WEB PROGRAMMING
56
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
57
FYBSC.IT DIV:-B ROLL NO:-212
</script>
</head>
<body>
</body>
</html>
OUTPUT:-
(C7) regExp
CODE:-
<html>
<head>
<title>vidhan_practical4c_7</title>
<script language="javascript">
var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.write(txt.length);
document.write("<br>");
document.write("<br>");
var str = "Please locate where 'locate' occurs!";
var pos = str.indexOf("locate");
document.write(pos);
document.write("<br>");
var str = "Please locate where 'locate' occurs!";
var pos = str.lastIndexOf("locate");
document.write(pos);
document.write("<br>");
var str = "Please locate where locate' occurs!";
var pos = str.search("locate");
document.write(pos);
document.write("<br>");
var str = "guawa, orange, papaya";
var res = str.slice (7, 13);
document.write(res);
document.write("<br>");
var str = "guawa, orange, papaya";
var res= str.substring(7, 13);
document.write(res);
document.write("<br>");
var str = "guawa, orange, papaya";
WEB PROGRAMMING
59
FYBSC.IT DIV:-B ROLL NO:-212
</script>
</head>
</body>
</html>
OUTPUT:-
WEB PROGRAMMING
61
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 5 (a)
Basic PHP I
AIM : a) Write a PHP Program to accept a number from the user and print it factorial.
<html>
<head>
<title>Factorial of a number</title>
</head>
<body>
<form method="post" action=" 5a wp.php">
Enter a number: <input type="text" name="n1"><br>
<input type="submit" value="Factorial">
</form>
</body>
</html>
Source code for PHP:
<?php
$n1=(int)$_POST['n1'];
$fact=1;
for ($i=1;$i<=$n1;$i++)
{
$fact=$fact*$i;
WEB PROGRAMMING
62
FYBSC.IT DIV:-B ROLL NO:-212
}
echo "Factorial of ".$n1." is: ".$fact;
?>
Output:-
PRACTICAL NO 5 (b)
AIM : b) Write a PHP program to accept a number from the user and print whether it is
prime or not.
Code:
<html>
<head>
<title>212 vidhan 5b</title>
</head>
<body>
<form method="post" action="
wp 5a.php">
Enter a number: <input type="text" name="n1"><br>
<input type="submit" value="CheckPrime">
WEB PROGRAMMING
63
FYBSC.IT DIV:-B ROLL NO:-212
</form>
</body>
</html>
Source code for PHP:
<?php
$n1=(int)$_POST['n1'];
$flag=0;
for($i=2;$i<=$n1/2;$i++)
{
if($n1%$i==0)
{
$flag=1;
break;
}
}
if($flag==0)
echo "Number is prime";
else
echo "Number is not prime";
?>
OUTPUT:-
WEB PROGRAMMING
64
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
65
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 6 (a)
AIM : a) Write a PHP code to find the greater of 2 numbers. Accept the no. from the
user.
Source code for HTML:
<html>
<head>
<title>Greater of two numbers</title>
</head>
<body>
<form method="post" action=" wp 6a.php">
1st Number: <input type="text" name="n1"><br>
2nd Number: <input type="text" name="n2"><br>
<input type="submit" value="Check">
</form>
</body>
</html>
Source code for PHP:
Source code for PHP:
<?php
$n1=(int)$_POST['n1'];
$n2=(int)$_POST['n2'];
if($n1>$n2)
echo $n1." is greater than ".$n2;
else if($n2>$n1)
WEB PROGRAMMING
66
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 6 (b)
Code:
<?php
for($i=0;$i<4;$i++)
{
for($j=0;$j<=$i;$j++)
{
WEB PROGRAMMING
67
FYBSC.IT DIV:-B ROLL NO:-212
if(($i+$j)%2==0)
echo "1 ";
else
echo "0 ";
}
echo "<br>";
}
?>
OUTPUT:-
WEB PROGRAMMING
68
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 7 (a)
String Functions and arrays
Code:
<?php
echo strlen("VIDHAN \n");
echo "<br />";
echo strchr("Hello world!","world");
echo "<br />";
echo str_replace("world","mam","Hello world!");
echo "<br />";
echo str_word_count("Hello world!");
echo "<br />";
echo strpos("I love php, I love php too!","php");
echo "<br />";
echo substr_count("Hello world. The world is nice","world");
echo "<br />";
echo substr("Hello world",6);
echo "<br />";
echo strtolower("Hello WORLD.");
echo "<br />";
echo strtoupper("Hello WORLD.");
WEB PROGRAMMING
69
FYBSC.IT DIV:-B ROLL NO:-212
?>
OUTPUT:-
PRACTICAL NO 7 (b)
Code:
<?php
$cars = array("LAMBO", "MASERATI", "RR");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
echo "<br>";
echo "Total number of car: " . count($cars);
echo "<br>";
$arrlength = count($cars);
for($x = 0; $x < $arrlength; $x++)
{
echo $cars[$x];
echo "<br>";
}
//Associative arrays
$age = array("HARSHAD"=>"18", "GWEN"=>"37", "OMI"=>"43");
WEB PROGRAMMING
70
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
71
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 8 (a)
PHP and Database
CODE:
<?php
//connecting to the database
$servername = "localhost";
$username = "root";
$password = "";
//create a connection
$conn = mysqli_connect($servername, $username,
$password);
if(!$conn){
WEB PROGRAMMING
72
FYBSC.IT DIV:-B ROLL NO:-212
//create a database
$sql = "CREATE DATABASE Patkar_College1";
$result = mysqli_query($conn, $sql);
?>
WEB PROGRAMMING
73
FYBSC.IT DIV:-B ROLL NO:-212
OUTPUT:-
PRACTICAL NO 8 (a)(part2)
CODE:
<?php
//connecting to the database
$servername = "localhost";
$username = "root";
$password = "";
$databse = "Patkar_College1";
//create a connection
WEB PROGRAMMING
74
FYBSC.IT DIV:-B ROLL NO:-212
if(!$conn){
die("Sorry we failed to connect: ". mysqli_connect_error());
}
else{
echo "Connection was succesful";
echo "<br>";
}
}
?>
OUTPUT:-
PRACTICAL NO 8 (b)
CODE:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$databse = "Patkar_College";
//create a connection
if(!$conn){
else{
echo "<br>";
$sql = "INSERT INTO `student` (`sno`, `name`, `percentage`) VALUES (NULL, 'Balmukund', '67')";
if($result){
else{
?>
OUTPUT:
WEB PROGRAMMING
77
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
78
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 8 (c)
CODE:
Source code for HTML:
<html>
<head>
<title>User authentication</title>
</head>
<body>
<form method="post" action="wp practical php file 8c.php">
Username: <input type="text" name="t1"><br>
Password: <input type="password" name="p1"><br>
<input type="submit" value="Submit">
<input type="reset" value="Clear">
</form>
</body>
</html>
<?php
$user=$_POST['t1'];
WEB PROGRAMMING
79
FYBSC.IT DIV:-B ROLL NO:-212
$pass=$_POST['p1'];
if($user=="vidhan" && $pass=="123")
echo "Welcome ".$user;
else
echo "Invalid username and password";
?>
OUTPUT:
WEB PROGRAMMING
80
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 9
AIM : Design an XML document and display it in browser using XSL
CODE:
OUTPUT:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="rule.xsl" ?>
<student>
<s>
<name>vidhan pawar</name>
<board>HSC</board>
<age>18</age>
<city>MUMBAI</city>
</s>
<s>
<name>harshad pawar</name>
<board>HSC</board>
<age>18</age>
<city>MUMBAI</city>
</s>
<s>
WEB PROGRAMMING
81
FYBSC.IT DIV:-B ROLL NO:-212
<name>vaibhav pednekar</name>
<board>HSC</board>
<age>19</age>
<city>MUMBAI</city>
</s>
</student>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1 align="center">STUDENT DETAILS</h1>
<table border="3" align="center">
<tr>
<th>NAME</th>
<th>BOARD</th>
<th>AGE</th>
<th>CITY</th>
</tr>
<xsl:for-each select="student/s">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="board"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="city"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
WEB PROGRAMMING
82
FYBSC.IT DIV:-B ROLL NO:-212
<html>
<body>
<h1 align="center">Students' Basic Details</h1>
<table border="3" align="center">
<tr>
<th>NAME</th>
<th>BOARD</th>
<th>AGE</th>
<th>CITY</th>
</tr>
<tr>
<td>vidhan pawar</td>
<td>HSC</td>
<td>18</td>
<td>MUMBAI</td>
</tr>
<tr>
<td>harshad pawar</td>
<td>HSC</td>
<td>18</td>
<td>MUMBAI</td>
</tr>
<tr>
<td>Vaibhav pednekar</td>
<td>HSC</td>
<td>18</td>
<td>MUMBAI</td>
</tr>
</table>
</body>
</html>
OUTPUT:-
WEB PROGRAMMING
83
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL NO 10
Email
CODE:
<?php
// Recipient
$to = '[email protected]';
// Sender
$from = '[email protected]';
$fromName = 'vidhan';
// Email subject
$subject = 'PHP Email with Attachment by Ayush';
// Attachment file
$file = "prac.pdf";
// Email body content
$htmlContent = '
<h3>PHP Email with Attachment by vidhan</h3>
<p>This email is sent from the PHP script with attachment.</p>
';
// Header for sender info
$headers = "From: $fromName"." <".$from.">";
// Boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Headers for attachment
WEB PROGRAMMING
84
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
85
FYBSC.IT DIV:-B ROLL NO:-212
OUTPUT:
WEB PROGRAMMING
86
FYBSC.IT DIV:-B ROLL NO:-212
PRACTICAL 11
AIM: Demonstrate use of sessions and cookies
<?php
session_start();
?>
<html>
<body>
<?php
$_SESSION["favcar"] = "RR";
$_SESION["favfruit"] = "DRAGON FRUIT";
echo "Session variables are set.";
?>
</body>
</html>
OUTPUT:-
WEB PROGRAMMING
87
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
88
FYBSC.IT DIV:-B ROLL NO:-212
WEB PROGRAMMING
89