1-9 WebProgramming
1-9 WebProgramming
a) Program to display various Server Information like- Server Name, Server Software, Server
protocol, CGI Revision etc.
HTML
<html>
<form action="http://localhost/cgi-bin/1a.pl">
<center>
</center>
</form>
</html>
PERL FILE
#!C:\xampp\perl\bin\perl.exe
#this is a here-document
print "<tr><td>$i</td><td>$ENV{$i}</td></tr>";
print "</table></html>";
OUTPUT
b) Program to accept UNIX command from a HTML form and to display the output of the
command executed.
HTML
<html>
<form action="http://localhost/cgi-bin/1ba.pl">
</form>
</html>
PERL FILE
#!"\xampp\perl\bin\perl.exe"
use CGI':standard';
print "Content-type:text/html\n\n";
$c=param('com');
system($c);
exit(0);
OUTPUT
PROGRAM-2
HTML
<html>
<form action="http://localhost/cgi-bin/2a.pl">
<center>
</center>
</form>
</html>
PERL FILE
#!C:\xampp\perl\bin\perl.exe
use strict;
use warnings;
my $cmd=param('name');
print"Content-type: text/html;charset=iso-8859-1;\n\n";
print<<"here";
<html>
<center>
<h2>$cmd,$greet[$index]</h2>
</center>
</html>
here
OUTPUT
b) Program to keep track of the number of visitors visited the webpage and display the
counter with proper headings.
HTML
<html>
<body>
<form action="http://localhost/cgi-bin/2b.pl">
</form>
</body>
</html>
PERL FILE
#!C:\xampp\perl\bin\perl.exe
use CGI':standard';
$count=<FILE>;
close(FILE);
$count++;
open(FILE,'>count.txt');
OUTPUT
PROGRAM-3
Program to display a greeting based on the access time of the Web server. Also to verify
whether the webmaster is currently logged in.
HTML
<form action="http://localhost/cgi-bin/3.pl">
<center>
</center>
</form>
PERL FILE
#!C:\xampp\perl\bin\perl.exe
use CGI;
my $cgi=CGI->new;
my $cookie_name = 'webmaster_logged_in';
my $status=$cgi->cookie($cookie_name);
print "Content-type:text/html;\n\n";
if($status){
}else{
($s,$m,$h)=localtime(time);
print "<br>";
if($h<12){
}else{
OUTPUT
4. Program to display a digital clock which displays the
current time of the server.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="1">
<style>
body {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: black;
color: white;
font-size: 50px;
}
</style>
</head>
<body>
<div>
<?php
date_default_timezone_set("Asia/Calcutta");
echo date("h:i:s a");
?>
</div>
</body>
</html>
Output:
02 : 25 : 31 pm
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "books";
$table = "book";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($result->num_rows > 0) {
echo "<table><tr>";
$conn->close();
?>
</body>
</html>
(NOTE: Create a database and change the $books to the database name accordingly. Same
for the table within the database)
Output:
// Create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Form</title>
</head>
<body>
<h2>Enter Student Details</h2>
<form action="" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age" required>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Output:
// Create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Query Student Table</title>
</head>
<body>
<h2>Execute SQL Query</h2>
<form action="" method="post">
<label for="query">SQL Query:</label><br>
<textarea id="query" name="query" rows="4" cols="50" required>
</textarea>
<br><br>
<input type="submit" value="Execute">
</form>
Output:
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert Book</title>
</head>
<body>
<h2>Enter Book Details</h2>
<form action="" method="post">
<label for="access_number">Access Number:</label>
<input type="number" id="access_number" name="access_number"
required>
<br><br>
<label for="title">Title:</label>
<input type="text" id="title" name="title" required>
<br><br>
<label for="authors">Authors:</label>
<input type="text" id="authors" name="authors" required>
<br><br>
<label for="edition">Edition:</label>
<input type="number" id="edition" name="edition" required>
<br><br>
<label for="publication">Publication:</label>
<input type="text" id="publication" name="publication" required>
<br><br>
Output:
9. Program to search a book for a title given by the user
on a webpage and display the search results with proper
headings.
<?php
// Database credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "books";
// Create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Initialize variables
$bookDetails = null;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Book</title>
</head>
<body>
<h2>Search for a Book</h2>
<form action="" method="post">
<label for="title">Book Title:</label>
<input type="text" id="title" name="title" required>
<br><br>
<input type="submit" value="Search">
</form>
Output: