Web Technologies prog11
Web Technologies prog11
Program -1
Write an HTML page that has one input, which can take multi-line text and a submit button.Once
the user clicks the submit button ,it should show the number of characters ,lines and words in the
text entered using an alert message.Words are seperated with white space and lines are seperated
with new line character.
Count.html
<!DOCTYPE html>
<html>
<head>
<title>Try me</title>
</head>
<body>
<header>
FIRST PROGRAM IN PHP
</header>
<hr>/
<?php // form field ?>
<fieldset class>
<legend>ENTER THE TEXT</legend>
<form action="index1.php" method="get">
<labe>TYPE IN HERE</label>
<input type="text" name="name" value=" " size="30" placeholder="typehere"></br></br>
<input id="button" type="submit" name="submit" value="Submit" size="10">
</form>
</fieldset>
<hr>
</body>
<html>
Count1.html
<!DOCTYPE html>
<html>
<head>
<title>Try me</title>
</head>
<body>
<header>
FIRST PROGRAM IN PHP
</header>
<hr>
<h3>Your input:(<?php echo $_GET["name"]; ?>) </h3>
<input id="button" type="submit" name="submit" value="Submit" size="10"
onclick="alert('<?php echo
($_GET["name"]);?>')">
<p>Counting The Words:<h2><?php echo str_word_count($_GET["name"]); ?></h2></p>
<input id="button" type="submit" name="submit" value="Submit" size="10"
onclick="alert('<?php echo str_word_count($_GET["name"]);?>')">
<p>Counting The number of char :</p>
<p>Counting the white spaces:</p><h2><?php echo substr_count($_GET["name"],' '); ?></h2>
2
Program -2
Write an HTML page that contains a selection box with a list of 5 countries In the above page
when the user selects a country, its capital should be printed next to the list, and add CSS to
customize the properties of the font of the capital.
Country.html
<!DOCTYPE html>
<html>
<head>
<title>Try me</title>
</head>
<body>
<header>
FIRST PROGRAM IN PHP
</header>
<hr>/
<?php // form field ?>
<fieldset class>
<legend>ENTER THE COUNTRY HERE</legend>
<form action="display.php" method="get">
<label>What are ur Hobies?</label>
<select name="name">
<option value="INDIA: New delhi">India</option>
<option value="Afganistan: Kabul">Afganistan</option>
<option value="Sri Lanka: Colombo">Sri Lanka</option>
<option value="Russia: Moscow">Russia</option>
<option value="U.S.A: Washiton DC">U.S.A</option>
</select>
<input id="button" type="submit" name="submit" value="Submit" size="10">
</form></fieldset></body>
</html>
4
display.php
<!DOCTYPE html>
<html>
<head>
<title>Your captials</title>
<link href="country.css" rel="stylesheet">
</head>
<body>
<header>
FIRST PROGRAM IN PHP
</header>
<hr>
<h3> Captial:</h3>
<h1> (<?php echo $_GET["name"]; ?>)</h1>
</body>
</html>
5
Program -3
Login.html
chkusr.php
<?php
$user = $_POST['user'];
$pass = $_POST['pass'];
$server = "localhost";
$username = "root";
$password = "mysql";
$database = "users";
$tablename = "user"; if ($user&&$pass)
$connect = mysql_connect($server,$username,$password) or die("not connecting");
mysql_select_db($database) or die("no db :");
$query = mysql_query("SELECT * FROM $tablename WHERE username='$user' and
password='$pass'");
$numrows = mysql_num_rows($query); if ($numrows!=0)
{
print "Hello " . $user;
}
Else
6
Program -4
ii) modify the above program to use an xml file instead of database
users.xml
<users>
<user>
<username>aaa</username>
<password>aaa</password>
</user>
<user>
<username>bbb</username>
<password>bbb</password>
</user>
<user>
<username>ccc</username>
<password>ccc</password>
</user>
</users>
Login.html
<form action='chkusr.php' method='post'> Login<br>
User name: <input type='text' name='user'><br> Password: <input type='password'
name='pass'><br>
<input type='submit'value='Login'>
</form>
8
chkusr.php
<?php
$user = $_POST['user'];
$pass = $_POST['pass'];
$flag = 0;
if ($user&&$pass)
{
$xml = simplexml_load_file("users.xml"
$cnt = count($xml->user); for($i = 0; $i < $cnt; $i++)
{
$username = $xml->user[$i]->username;
$password = $xml->user[$i]->password;
if ($user == $username && $pass == $password)
{
print "Hello " . $user;
$flag = 0;
break;
}
else
$flag = 1;
}
if ($flag == 1)
print "user does not exist!";
}
else
die("please enter a username and password!");
?>
9
Program -5
A simple calculator web application that takes 2 numbers and an operator (+,-,*,/,%)
from an HTML page and returns the result page with the operation performed on the operands.
Form1.html
<form name='f1' action='add.php' method='post'> 1st Number<input type='text' name='t1'><br>
2nd Number<input type='text' name='t2'><br>
<input type='submit' name='add' value='add'>
<input type='submit' name='sub' value='sub'>
<input type='submit' name='mul' value='mul'>
<input type='submit' name='div' value='div'>
</form>
add.php
<?php
$a = $_POST['t1'];
$b = $_POST['t2'];
if (isset($_POST['add']))
{
$c = $a + $b;
print $a . "+" . $b . "=" . $c;
}
if (isset($_POST['sub']))
{
$c = $a - $b;
print $a . "-" . $b . "=" . $c;
}
if (isset($_POST['mul']))
{
$c = $a * $b;
print $a . "*" . $b . "=" . $c;
}
if (isset($_POST['div']))
{
$c = $a / $b;
print $a . "/" . $b . "=" . $c;
}
?>
10
11
Program -6
iii) A web application takes a name as input and on submit it shows a hello<name> page where
<name> is taken from the request.and it shows a start time at the right top corner of the page and
provides the logout button on clicking this button it should shoe a logout page with
thankyou<name> message with the duration of Usage.
Login.html
<html>
<form action="home.php" method="post"> Username<input type="text" name="text1"><br>
<input type="submit" value="SignIn" name="submit">
</form>
</html>
Home.php
<?php
session_start(); date_default_timezone_set("Asia/Calcutta");
$_SESSION['luser'] = $_POST['text1'];
$_SESSION['start'] = time();
$tm=$_SESSION['start'];
print "<p align='right'>Session started at " . date("h:i:sa",$tm) . "<br>"; print "<form
action='logoutpage.php' method='post'>";
print "<input type='submit' value='Logout'></p>"; print "</form>";
print "Hello " . $_SESSION['luser'];
?>
12
Logoutpage.php
<?php
session_start();
date_default_timezone_set("Asia/Calcutta");
session_destroy();
?>
13
Program -7
A web application that takes name and age from an HTML page. If the age is less than 18, it
should send a page with “hello <name>,and u are not authorized to visit this site” otherwise it
should send “welcome <name> to this site” message where name should be replaced with the
entered name otherwise it should send welcome<name> to the site message.
Form2.html
<form action='home.php' method='post'> Login<br>
User name: <input type='text' name='name'><br> age: <input type='text' name='age'><br>
<input type='submit'value='Login'>
home.php
<?php
$name = $_POST['name'];
$age = $_POST['age']; if ($age < 18)
print "Hello " . $name . " you are not authorized to visit this site."; else
print "Welcome " . $name . " to this site."
?>
14
15
Program-8
Write an HTML page with Javascript that takes a number from one text field in the range 0-999 and
display it in other text field in words.If the number is out of range ,it shold show “out of range” and
if it is not a number ,it should show “not a number” message in the result box.
Conver.html
<script language="javascript">
function convert_number_to_words(number)
{
hyphen = '-'; conjunction = ' and '; separator = ', ';
dictionary =
{
0 : 'zero',
1 : 'one',
2 : 'two',
3 : 'three',
4 : 'four',
5 : 'five',
6 : 'six',
7 : 'seven',
8 : 'eight',
9 : 'nine',
10 : 'ten',
11 : 'eleven',
12 : 'twelve',
13 : 'thirteen',
14 : 'fourteen',
15 : 'fifteen',
16 : 'sixteen',
17 : 'seventeen',
18 : 'eighteen',
19 : 'nineteen',
20 : 'twenty',
30 : 'thirty',
40 : 'fourty',
50 : 'fifty',
60 : 'sixty',
70 : 'seventy',
80 : 'eighty',
90 : 'ninety',
100 : 'hundred',
16
};