Download as pdf or txt
Download as pdf or txt
You are on page 1of 84

Department of Computer Science and Engineering

Laboratory Manual

of

IT4017 - Web Development

is submitted to

Ms. Ankita J Desai

Assistant Professor

Asha M. Tarsadia Institute of Computer Science and Technology


Uka Tarsadia University, Maliba Campus Bardoli, Gujarat

Semester — 3
(Winter 2022)
CERTIFICATE

Balkrishna Mehta
This is to certify that Mr. /Ms._________________________________________,

202103103510434
Enrollment No: ______________________ of B.Tech. Computer Science and

Engineering 3rd semester has satisfactorily completed his/her laboratory work of IT4017

- Web Dvelopment during regular term in academic year 2022-23.

Date of Submission:

Department Authority
Ms.Ankita J Desai
Subject Teacher
Assistant Professor
Department of Computer Science
and Engineering

Institute Stamp
Practical 1
Write a PHP scri pt to demonstrate the usage o f all the
basic data types.
1 <?php
2 // B.Tech Computer Science and Engineering
3 // Balkrishna Mehta
4 // 202103103510434
5
6 $str = "Hello";
7 $int = 20;
8 $float = 10.23;
9 $bool1 = true;
10 $array = array(1,2,3,4);
11 $null = null;
12 class class_ex{};
13 define("gravity",9.8,true); // FALSE - Case-sensitive (this is default)
14
15 echo var_dump($str);
16 echo var_dump($int);
17 echo var_dump($float);
18 echo var_dump($bool1);
19 echo var_dump(!$bool1);
20 echo var_dump($array);
21 echo var_dump($null);
22 echo var_dump(GRAVITY);
23 $obj = new class_ex;
24 echo var_dump($obj);
25
26 ?>
Practical 2
Write a PHP script to calculate percentage of a student using
switch case statement and accordingly award grade using
if...elseif ladder.
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $roll_no = [];
8 for ($i=1;$i<=3;$i++){
9 // Marks entry of each student
10 $roll_no[$i-1] = array("WD"=>readline("Enter student".$i."'s WD Marks:
"),"MAD"=>readline("Enter student".$i."'s MAD Marks: "),"SE"=>readline("Enter
student".$i."'s SE Marks: "),"JAVA"=>readline("Enter student".$i."'s JAVA
Marks: "),"DBMS"=>readline("Enter student".$i."'s DBMS Marks: "));
11
12 echo("\n");
13 }
14
15 $rollno = readline("Enter roll no: ");
16 echo "\n";
17 switch($rollno){
18 case 1:
19 $name="student 1";
20 extract($roll_no[0]);
21 $score = ($WD + $MAD + $SE + $JAVA + $DBMS)/5;
22 echo $name ,",Your percantage is: ",$score,"%\n";
23 break;
24 case 2:
25 $name="student 2";
26 extract($roll_no[1]);
27 $score = ($WD + $MAD + $SE + $JAVA + $DBMS)/5;
28 echo $name ,",Your percantage is: ",$score,"%\n";
29 break;
30 case 3:
31 $name="student 3";
32 extract($roll_no[2]);
33 $score = ($WD + $MAD + $SE + $JAVA + $DBMS)/5;
34 echo $name ,",Your percantage is: ",$score,"%\n";
35 break;
36 }
37 if($score >= 91){
38 echo $name, ",Your Grade is O.","\n";
39 }
40 elseif($score >= 75 && $score < 90){
41 echo $name, ",Your Grade is A.","\n";
42 }
43 elseif($score >= 60 && $score < 75){
44 echo $name, ",Your Grade is B.","\n";
45 }
46 elseif($score >= 50 && $score <60){
47 echo $name, ",Your Grade is c.","\n";
48 }
49 elseif($score >= 40 && $score <50){
50 echo $name, ",Your Grade is D.","\n";
51 }
52 else{
53 echo $name, ",Your Grade is E. You Failed.","\n";
54 }
55 ?>
56
Practical 3
a) Write a PHP script to calculate First 20 numbers of
Fibonacci series.
b) Write a PHP script to calculate sum of prime
numbers from 1 to 100.
c) Write a PHP script to draw pascal triangle till level
5.
d) Write a PHP script to take username and password
as input and print it as key- value pair.
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $first_term = 0;
8 $second_term = 1;
9 $next_term = $first_term + $second_term;
10 $i=0;
11 do{
12 if($i == 0){
13 echo "Fibonacci Series: ",$first_term;
14 echo " ",$second_term;
15 }
16 echo " " ,$next_term;
17 $first_term = $second_term;
18 $second_term = $next_term;
19 $next_term = $first_term + $second_term;
20 $i++;
21 }
22 while($i<18);
23 echo "\n";
24 ?>
25
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $i=2;
8 $sum=0;
9 do{
10 $j=2;
11 $tmp=1;
12 do{
13 if($i%$j==0) {
14 $tmp=0;
15 break;
16 }
17 $j++;
18 }
19 while($j<$i);
20 if($tmp==1 || $i==2) {
21 $sum+=$i;
22 }
23 $i++;
24 }
25 while($i<100);
26 echo "Sum of prime numbers from 1 to 100: ",$sum,"\n";
27 ?>
28
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $coef=1;
8 //$num = readline("Enter number of rows for triangle: ");
9 $num = 5;
10 $column = 0;
11 do{
12 $space = 1;
13 do{
14 echo(" ");
15 $space++;
16 }
17 while($space <= $num - $column);
18 $row = 0;
19 do{
20 if ($row == 0 || $column == 0)
21 $coef = 1;
22 else
23 $coef = $coef * ($column - $row + 1) / $row;
24 echo " ",$coef;
25 $row++;
26 }
27 while($row <= $column);
28 echo("\n");
29 $column++;
30 }
31 while($column < $num);
32
33 ?>
34
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $users = readline("No of user: ");
8 $user_array = [];
9 for($i=0;$i<$users;$i++){
10 $username = readline("Enter Username for user".($i+1).": ");
11 $password = readline("Enter Passwordfor user".($i+1).": ");
12
13 $user_array[$i] = array($username => $password);
14 }
15 echo "\n";
16 for($j=0;$j<$users;$j++){
17 echo "user".($j+1)." \n";
18 foreach($user_array[$j] as $key => $value){
19 echo "Key: ".$key."\nValue: ".$value."\n\n";
20 }
21 }
22 ?>
Practical 4
a) Write a PHP script to Find unique elements from two
associative arrays.
b) Write a PHP script to calculate matrix multiplication of
indexed array
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $teacher = array("Ashish"=>25, "Dev"=>37, "Dhruv"=>28, "Jeel"=>30);
8 $student = array("Ashish"=>20, "Ayush"=>18, "Neel"=>28, "Aryan"=>11,
"Jeel"=>30);
9
10 echo "Teacher array: ".json_encode($teacher)."\n";
11 echo "Student array: ".json_encode($student)."\n\n";
12
13 $teacher_unique = array_diff($teacher,$student);
14 $student_unique = array_diff($student,$teacher);
15
16 echo "Teacher unique elements: ".json_encode($teacher_unique)."\n";
17 echo "Student unique elements: ".json_encode($student_unique)."\n\n";
18
19 $unique_arrayTogether = $teacher_unique + $student_unique;
20
21 echo "Unique values are: ";
22 foreach($unique_arrayTogether as $key => $value){
23 echo $value," ";
24 }
25 echo "\n";
26 ?>
27
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $row1 = readline("Enter number of rows in Matrix1: ");
8 $column1 = readline("Enter number of column in Matrix1: ");
9 $row2 = readline("Enter number of rows in Matrix2: ");
10 $column2 = readline("Enter number of column in Matrix2: ");
11
12 echo "Entries for matrix1...\n";
13
14 $i = 0;
15 do {
16 $j = 0;
17 do {
18 $mat1[$i][$j] = (int) readline("Enter element at position
".($i+1).($j+1).": \n");
19 $j++;
20 } while($j< $column1);
21 $i++;
22 } while($i<$row1);
23
24 $i = 0;
25 echo "Entries for matrix2...\n";
26 do {
27 $j = 0;
28 do {
29 $mat2[$i][$j] = (int) readline("Enter element at position
".($i+1).($j+1).": \n");
30 $j++;
31 } while($j<$column2);
32 $i++;
33 }while($i<$row2);
34
35 $i = 0;
36 echo "\nMatrix Multiplication: \n\n";
37 do {
38 $j = 0;
39 printf("| ");
40
41 do {
42 $result = 0;
43 $k = 0;
44 do {
45 $result += $mat1[$i][$k] * $mat2[$k][$j];
46 $k++;
47 } while($k < $row2);
48 printf("%4d ", $result);
49 $j++;
50 } while($j < $column2);
51 printf("|\n");
52 $i++;
53 } while($i<$row1);
54
55 ?>
Practical 5
Write a PHP script to take input from an HTML
form.
1 <!DOCTYPE html>
2
3 <!-- B.Tech Computer Science and Engineering
4 Balkrishna Mehta
5 202103103510434 -->
6
7 <head>
8 <title>practical5a</title>
9 <style>
10 th{
11 text-align:left;
12 }
13 </style>
14 </head>
15 <body>
16 <p style="text-align: center; margin-top:8vh;">B.Tech Computer Science and
Engineering<br>Balkrishna Mehta<br>202103103510434</p>
17 <form action="practical5a.php" method="post" style="width:fit-content;
position:absolute; left:35vw; top:8vw;" enctype="multipart/form-data">
18 <fieldset>
19 <legend><h1>Form</h1></legend>
20 <table>
21 <tr>
22 <th><label for="uname">Username</label></th>
23 <td>: <input type="text" id="uname"placeholder="Enter username"
name="Name"/></td>
24 </tr>
25 <tr>
26 <th><label for="pass1">Password</label></th>
27 <td>: <input type="password" id="pass1" placeholder="Enter password"
name="Password"/></td>
28 </tr>
29 <tr>
30 <th><label for="num">Number</label></th>
31 <td>: <input type="tel" id="num" placeholder="Enter Number"
name="Number"
32 pattern="[0-9]{10}"/></td>
33 </tr>
34 <th><label for="birthdate">D.O.B</label></th>
35 <td>: <input type="date" id="birthdate" name="D-O-B"></td>
36 </tr>
37
38 <tr>
39 <th rowspan=2><label for="Gender">Gender</label></th>
40 <td>: <input type="radio"id="gender" name="Gender" value="male">
<label>Male</label><br></td>
41 </tr>
42 <tr>
43 <td>: <input type="radio"id="gender" name="Gender"value="female">
<label>Female</label></td>
44 </tr>
45
46 <tr>
47 <th><label for="department">Department</label></th>
48 <td>:
49 <select id="department" name="Department">
50 <option value="select">Select</option>
51 <option value="CSE">CSE</option>
52 <option value="SE">SE</option>
53 <option value="CC">CC</option>
54 </select>
55 </td>
56 </tr>
57
58 <tr>
59 <th rowspan=5><label for="hobby">Hobby</label></th>
60 <td>: <input type="checkbox" id="hobby" name="Hobby[]"
value="Cricket"><label>Cricket</label></td>
61 </tr>
62 <tr>
63 <td>: <input type="checkbox" id="hobby" name="Hobby[]"
value="Reading"><label>Reading</label></td>
64 </tr>
65 <tr>
66 <td>: <input type="checkbox" id="hobby" name="Hobby[]" value="Acting">
<label>Acting</label></td>
67 </tr>
68 <tr>
69 <td>: <input type="checkbox" id="hobby" name="Hobby[]"
value="Dancing"><label>Dancing</label></td>
70 </tr>
71 <tr>
72 <td>: <input type="checkbox" id="hobby" name="Hobby[]"
value="Singing"><label>Singing</label></td>
73 </tr>
74
75 <tr>
76 <th><label for="address">Address</label></th>
77 <td>: <textarea id="address" name="Address" rows="5" cols="50"
placeholder="Enter address"></textarea></td>
78 </tr>
79 <tr>
80 <td style="padding-left:4vw"><input type="submit"
value="submit"></td>
81 <td style="padding-left:4vw"><input type="reset" value="Reset"></td>
82 </tr>
83
84 </table>
85 </fieldset>
86 </form>
87 </body>
88 </html>
89
1 <!DOCTYPE html>
2 <title>practical5a</title>
3 <body style="width:fit-content;">
4 <?php
5
6 // B.Tech Computer Science and Engineering
7 // Balkrishna Mehta
8 // 202103103510434
9
10 echo "B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434<br><hr><br>";
11 foreach($_POST as $key => $value){
12 if($key == "Password" || $key == "Hobby"){
13 continue;
14 }
15 elseif($key == "Department" && $value == "select") {
16 echo "Department: Not Selected<br>";
17 }
18 else{
19 echo $key .": ". $value."<br>";
20 }
21
22 }
23 echo "Hobbies: ";
24 if(isset($_POST['Hobby'])){
25 foreach($_POST['Hobby'] as $value){
26 echo $value." ";
27 }
28 }
29 ?>
30 </body>
31 </html>
32
1 <!DOCTYPE HTML>
2
3 <!-- B.Tech Computer Science and Engineering
4 Balkrishna Mehta
5 202103103510434 -->
6
7 <head>
8 <title>practical5b</title>
9 </head>
10 <body style="text-align: center;">
11 <p>B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434</p>
12 <form action="practical5b.php" method="post" enctype="multipart/form-
data">
13 <label for="File">Insert File:</label>
14 <input type="file" id="File" name="myfile"/><br><br>
15 <input type="submit" value="submit">
16 </form>
17 </body>
18 </HTML>
19
20
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $filename=$_FILES['myfile']['tmp_name'];
8 header('Content-Description: File Transfer');
9 header('Content-Type: $_FILES[myfile][type]');
10 header('Content-Deposition: attachment;
filename="'.basename($filename).'"');
11
12 readfile($filename);
13 ?>
14
15
⬇️
⬇️
1 <!DOCTYPE html>
2 <title>practical5c</title>
3 <body style="text-align: center;">
4 <?php
5
6 // B.Tech Computer Science and Engineering
7 // Balkrishna Mehta
8 // 202103103510434
9
10 echo "B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434<br><hr><br>";
11 if(!empty($_POST)){
12 echo $_POST["img_x"]."<br>";
13 echo $_POST["img_y"]."<br>";
14 if($_POST["img_y"]>155 && $_POST["img_y"]<546){
15 if($_POST["img_x"]>31 && $_POST["img_x"]<252){
16 header("Location: http://localhost/index1.jpg");
17 }
18 elseif($_POST["img_x"]>271 && $_POST["img_x"]<490){
19 header("Location: http://localhost/index2.jpg");
20
21 }
22 elseif($_POST["img_x"]>511 && $_POST["img_x"]<731){
23 header("Location: http://localhost/index3.jpg");
24
25 }
26 elseif($_POST["img_x"]>750 && $_POST["img_x"]<971){
27 header("Location: http://localhost/index4.jpg");
28 }
29 else{
30 header("Location: https://en.wikipedia.org/wiki/Day");
31 }
32 }
33 }
34 ?>
35 <form method="post" action="">
36 <input type="image" src="index.jpg" name="img">
37 </form>
38 </body>
39 </html>
40
Practical 6
Write a PHP script using framework for storing and retrieving
user information from MySQL table.
a) Design a HTML registration and login page which takes name,
password, email and mobile number from user.
b) Store this data in MySQL database.
c) On next page display all user in HTML table using PHP.
d) Update/Delete details of user.
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $error = "";
8    if(isset($_REQUEST['submitbtn'])){
9        unset($_REQUEST['submitbtn']);
10 if(isset($_REQUEST['Hobby'])){
11 $hobby = $_REQUEST['Hobby'];
12 }
13        foreach($_REQUEST as $key => $value){
14            if($key=="Hobby"){
15                $_REQUEST[$key] = implode(",", $value);
16           }
17 if($key=="Number"){
18 $_REQUEST[$key] = intval($value);
19 }
20       }
21 if($_REQUEST['Department'] == "NULL") {
22 $error = "Department Not Selected";
23 }
24 if(empty($_REQUEST['Gender'])){
25 $error = "Select Gender";
26 }
27 if(empty($_REQUEST['Hobby'])){
28 $error =  "Select at least 1 Hobby";
29 }
30 foreach(array_reverse($_REQUEST) as $key => $value){
31 if(empty($value)){
32 $error = "$key is required";
33 }
34 }
35 if (!filter_var($_REQUEST['Password'], FILTER_VALIDATE_REGEXP, array(
"options"=> array( "regexp" => "/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?
&])[a-zA-Z\d@$!%*?&]{8,20}$/"))) ){
36 $error = "invalid Password";
37 $_REQUEST['Password'] = "";
38 }
39 if (!filter_var($_REQUEST['Email'], FILTER_VALIDATE_EMAIL)) {
40 $error = "invalid email address";
41 $_REQUEST['Email'] = "";
42 }
43 if(!preg_match("/^[6789]+\d{9}$/", $_REQUEST['Number'])){
44 $error = 'Invalid Mobile Number';
45 $_Request["Number"]="";
46 }
47
48 if(empty($error)){
49 $conn1 = mysqli_connect('localhost','root','') or die("connection
Failed: ". mysqli_connect_error());
50 $query1 = "CREATE DATABASE IF NOT EXISTS WD";
51 mysqli_query($conn1, $query1) or die("Error creating database: ".
mysqli_error($conn1));
52 mysqli_close($conn1);
53
54 $attribute = array_keys($_REQUEST);
55 $conn2 = mysqli_connect('localhost','root','','WD') or die("connection
Failed: ". mysqli_connect_error());
56 $query2 = "CREATE TABLE IF NOT EXISTS REGISTRATION (
57 id INT(5) AUTO_INCREMENT PRIMARY KEY,
58 $attribute[0] VARCHAR(255),
59 $attribute[1] VARCHAR(255),
60 $attribute[2] VARCHAR(255),
61 $attribute[3] BIGINT(10),
62 $attribute[4] DATE,
63 $attribute[5] ENUM ('Male','Female'),
64 $attribute[6] ENUM ('CSE','SE','CC'),
65 $attribute[7] VARCHAR(255),
66 $attribute[8] VARCHAR(255)
67 )";
68 mysqli_query($conn2, $query2) or die("Error creating table: ".
mysqli_error($conn2));
69 $value = array_values($_REQUEST);
70 $query3 = "INSERT INTO REGISTRATION
($attribute[0],$attribute[1],$attribute[2],$attribute[3],$attribute[4],$attri
bute[5],$attribute[6],$attribute[7],$attribute[8])
71 VALUES
('$value[0]','$value[1]','$value[2]',$value[3],'$value[4]','$value[5]','$valu
e[6]','$value[7]','$value[8]');";
72 mysqli_query($conn2, $query3) or die("Error in data entry: ".
mysqli_error($conn2));
73 mysqli_close($conn2);
74 header('Location: login.php');
75 }
76     }
77 ?>
78 <!DOCTYPE html>
79 <head>
80 <style>
81 th{
82 text-align:left;
83 }
84 </style>
85 </head>
86 <body>
87 <div style="margin-left:auto; margin-top:1.1em !important; text-
align:center;">B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434</div>
88 <?php
89 if(!empty($error)){
90 echo "<div style='position:absolute; left:35vw; top:5vw; border:1px
solid black; color:red;
91 width:29.2vw; padding:0.3em; margin:0.3em'>
92 $error
93 </div>";
94 }
95 ?>
96 <form action="" method="post" style="width:30vw;position:absolute;
left:35vw; top:8vw;" enctype="multipart/form-data">
97 <fieldset>
98 <legend><h1>Registration</h1></legend>
99 <table>
100 <tr>
101 <th><label for="uname">Username</label></th>
102 <td>: <input type="text" id="uname"placeholder="Enter username"
name="Name" value=<?php if(!empty($_REQUEST['Name'])){echo
$_REQUEST['Name'];}?>></td>
103 </tr>
104 <tr>
105 <th><label for="mail">Email</label></th>
106 <td>: <input type="text" id="mail" placeholder="Enter email"
name="Email"value=<?php if(!empty($_REQUEST['Email'])){echo
$_REQUEST['Email'];}?>></td>
107 </tr>
108 <tr>
109 <th><label for="pass1">Password</label></th>
110 <td>: <input type="password" id="pass1" placeholder="Enter
password" name="Password" value=<?php if(!empty($_REQUEST['Password'])){echo
$_REQUEST['Password'];}?>></td>
111 </tr>
112 <tr>
113 <th><label for="num">Number</label></th>
114 <td>: <input type="tel" id="num" placeholder="Enter Number"
name="Number" maxlength="10"
115 pattern="[0-9]{10}" value=<?php if(!empty($_REQUEST['Number']))
{echo $_REQUEST['Number'];}?>></td>
116 </tr>
117 <th><label for="birthdate">D.O.B</label></th>
118 <td>: <input type="date" id="birthdate" name="DOB" value=<?php
if(!empty($_REQUEST['DOB'])){echo $_REQUEST['DOB'];}?>></td>
119 </tr>
120
121 <tr>
122 <th rowspan=2><label for="Gender">Gender</label></th>
123 <td>: <input type="radio"id="gender" name="Gender" value="Male" <?php
if(isset($_REQUEST['Gender']) && $_REQUEST['Gender'] == 'Male') echo
'checked'; ?> ><label>Male</label><br></td>
124 </tr>
125 <tr>
126 <td>: <input type="radio"id="gender" name="Gender"value="Female" <?
php if(isset($_REQUEST['Gender']) && $_REQUEST['Gender'] == 'Female') echo
'checked'; ?> ><label>Female</label></td>
127 </tr>
128
129 <tr>
130 <th><label for="department">Department</label></th>
131 <td>:
132 <select id="department" name="Department">
133 <option value="NULL">Select</option>
134 <option value="CSE"<?php if(isset($_REQUEST['Department']) &&
$_REQUEST['Department'] == 'CSE') echo 'selected'; ?> >CSE</option>
135 <option value="SE"<?php if(isset($_REQUEST['Department']) &&
$_REQUEST['Department'] == 'SE') echo 'selected'; ?> >SE</option>
136 <option value="CC"<?php if(isset($_REQUEST['Department']) &&
$_REQUEST['Department'] == 'CC') echo 'selected'; ?> >CC</option>
137 </select>
138 </td>
139 </tr>
140
141 <tr>
142 <th rowspan=5><label for="hobby">Hobby</label></th>
143 <td>: <input type="checkbox" id="hobby" name="Hobby[]"
value="Cricket" <?php if(isset($hobby) && in_array("Cricket",$hobby))echo
"checked='checked'";?> ><label>Cricket</label></td>
144 </tr>
145 <tr>
146 <td>: <input type="checkbox" id="hobby" name="Hobby[]"
value="Reading" <?php if(isset($hobby) && in_array("Reading",$hobby)) echo
"checked='checked'"; ?> ><label>Reading</label></td>
147 </tr>
148 <tr>
149 <td>: <input type="checkbox" id="hobby" name="Hobby[]" value="Acting"
<?php if(isset($hobby) && in_array("Acting",$hobby)) echo
"checked='checked'"; ?> ><label>Acting</label></td>
150 </tr>
151 <tr>
152 <td>: <input type="checkbox" id="hobby" name="Hobby[]"
value="Dancing" <?php if(isset($hobby) && in_array("Dancing",$hobby)) echo
"checked='checked'"; ?> ><label>Dancing</label></td>
153 </tr>
154 <tr>
155 <td>: <input type="checkbox" id="hobby" name="Hobby[]"
value="Singing" <?php if(isset($hobby) && in_array("Singing",$hobby)) echo
"checked='checked'"; ?>><label>Singing</label></td>
156 </tr>
157
158 <tr>
159 <th><label for="address">Address</label></th>
160 <td>: <textarea id="address" name="Address" rows="5" cols="50"
placeholder="Enter address"><?php if(!empty($_REQUEST['Address'])){echo
$_REQUEST['Address'];}?></textarea></td>
161 </tr>
162 <tr>
163 <td style="padding-left:4vw"><input type="submit" name="submitbtn"
value="submit"></td>
164 <td style="padding-left:4vw"><input type="reset" value="Reset">
</td>
165 </tr>
166
167 </table>
168 </fieldset>
169 </form>
170 </body>
171 </html>
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $Mmsg = "Login Successful";
8 $Smsg = "";
9    if(isset($_REQUEST['submitbtn'])){
10        unset($_REQUEST['submitbtn']);
11 if (!filter_var($_REQUEST['npass'], FILTER_VALIDATE_REGEXP, array(
"options"=> array( "regexp" => "/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?
&])[a-zA-Z\d@$!%*?&]{8,20}$/"))) ){
12 $error = "Enter Password of requested format";
13 $_REQUEST['Password'] = "";
14 }
15 else{
16 $conn = mysqli_connect('localhost','root','','WD');
17 $query = "SELECT * FROM REGISTRATION";
18 $result = mysqli_query($conn,$query);
19 $prep_stat = mysqli_prepare($conn,$query);
20 mysqli_stmt_execute($prep_stat);
21 $result = mysqli_stmt_get_result($prep_stat);
22 while($row = mysqli_fetch_assoc($result)) {
23 $data[] = $row;
24 }
25 $qwe = 0;
26 for($i=0;$i<count($data);$i++){
27 if($data[$i]['Password']==$_REQUEST['ppass'] && $data[$i]
['id']==$_REQUEST['id']){
28 $qwe = 1;
29 }
30 }
31 if($qwe == 1){
32 $update_query = "UPDATE REGISTRATION SET Password = ? where id = ?";
33 $updateStatement = mysqli_prepare($conn,$update_query);
34 mysqli_stmt_bind_param($updateStatement,'ss',$npass,$_REQUEST['id']);
35
36 $npass = $_REQUEST['npass'];
37 $ppass = $_REQUEST['ppass'];
38 mysqli_stmt_execute($updateStatement);
39 $Smsg =  " ".mysqli_affected_rows($conn)."rows affected";
40 $Mmsg =  "Password Updated ";
41 mysqli_close($conn);
42 }
43 else{
44 $error = "Password does not match";
45 }
46 }
47   }
48 ?>
49 <!DOCTYPE html>
50 <head>
51 <style>
52 th{
53 text-align:left;
54 }
55 form{
56 padding:2em;
57 border: 1px solid black;
58 width:30vw;
59 position:absolute;
60 left:35vw;
61 top:8vw;
62 }
63 </style>
64 <link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css
" rel="stylesheet" integrity="sha384-
iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT"
crossorigin="anonymous">
65 </head>
66 <body>
67 <div class="alert alert-primary alert-dismissible fade show"
role="alert">
68 <strong><?php echo $Mmsg;?></strong><?php echo $Smsg;?>
69 <button type="button" class="btn-close" data-bs-dismiss="alert" aria-
label="Close"></button>
70 </div>
71 <div style="margin-left:auto; margin-top:1.1em !important; text-
align:center;">B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434</div>
72 <?php
73 if(!empty($error)){
74 echo "<div style='position:absolute; left:35vw; top:5vw; border:1px
solid black; color:red;
75 width:29.2vw; padding:0.3em; margin:0.3em'>
76 $error
77 </div>";
78 }
79 ?>
80 <form action="" method="post">
81 <fieldset>
82 <legend><h1>Update Password</h1></legend>
83 <table>
84 <tr>
85 <th><label for="pass1">Previous Password</label></th>
86 <td>: <input type="password" id="pass1"placeholder="Enter username"
name="ppass"/></td>
87 </tr>
88 <tr>
89 <th><label for="pass2">New Password</label></th>
90 <td>: <input type="password" id="pass2" placeholder="Enter
password" name="npass"/></td>
91 </tr>
92                <tr>
93                    <td></td>
94 <td style="padding-left:4vw"><input type="submit" name="submitbtn"
value="submit"></td>
95 </tr>
96
97 </table>
98 </fieldset>
99 </form>
100 <!-- JavaScript Bundle with Popper -->
101 <script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.mi
n.js" integrity="sha384-
u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8"
crossorigin="anonymous"></script>
102
103 </body>
104 </html
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $Mmsg = "Login Successful";
8 $Smsg = "";
9    if(isset($_REQUEST['submitbtn'])){
10        unset($_REQUEST['submitbtn']);
11 if (!filter_var($_REQUEST['npass'], FILTER_VALIDATE_REGEXP, array(
"options"=> array( "regexp" => "/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?
&])[a-zA-Z\d@$!%*?&]{8,20}$/"))) ){
12 $error = "Enter Password of requested format";
13 $_REQUEST['Password'] = "";
14 }
15 else{
16 $conn = mysqli_connect('localhost','root','','WD');
17 $query = "SELECT * FROM REGISTRATION";
18 $result = mysqli_query($conn,$query);
19 $prep_stat = mysqli_prepare($conn,$query);
20 mysqli_stmt_execute($prep_stat);
21 $result = mysqli_stmt_get_result($prep_stat);
22 while($row = mysqli_fetch_assoc($result)) {
23 $data[] = $row;
24 }
25 $qwe = 0;
26 for($i=0;$i<count($data);$i++){
27 if($data[$i]['Password']==$_REQUEST['ppass'] && $data[$i]
['id']==$_REQUEST['id']){
28 $qwe = 1;
29 }
30 }
31 if($qwe == 1){
32 $update_query = "UPDATE REGISTRATION SET Password = ? where id = ?";
33 $updateStatement = mysqli_prepare($conn,$update_query);
34 mysqli_stmt_bind_param($updateStatement,'ss',$npass,$_REQUEST['id']);
35
36 $npass = $_REQUEST['npass'];
37 $ppass = $_REQUEST['ppass'];
38 mysqli_stmt_execute($updateStatement);
39 $Smsg =  " ".mysqli_affected_rows($conn)."rows affected";
40 $Mmsg =  "Password Updated ";
41 mysqli_close($conn);
42 }
43 else{
44 $error = "Password does not match";
45 }
46 }
47   }
48 ?>
49 <!DOCTYPE html>
50 <head>
51 <style>
52 th{
53 text-align:left;
54 }
55 form{
56 padding:2em;
57 border: 1px solid black;
58 width:30vw;
59 position:absolute;
60 left:35vw;
61 top:8vw;
62 }
63 </style>
64 <link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css
" rel="stylesheet" integrity="sha384-
iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT"
crossorigin="anonymous">
65 </head>
66 <body>
67 <div style="margin-left:auto; margin-top:1.1em !important; text-
align:center;">B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434</div>
68 <div class="alert alert-primary alert-dismissible fade show"
role="alert">
69 <strong><?php echo $Mmsg;?></strong><?php echo $Smsg;?>
70 <button type="button" class="btn-close" data-bs-dismiss="alert" aria-
label="Close"></button>
71 </div>
72 <?php
73 if(!empty($error)){
74 echo "<div style='position:absolute; left:35vw; top:5vw; border:1px
solid black; color:red;
75 width:29.2vw; padding:0.3em; margin:0.3em'>
76 $error
77 </div>";
78 }
79 ?>
80 <form action="" method="post">
81 <fieldset>
82 <legend><h1>Update Password</h1></legend>
83 <table>
84 <tr>
85 <th><label for="pass1">Previous Password</label></th>
86 <td>: <input type="password" id="pass1"placeholder="Enter username"
name="ppass"/></td>
87 </tr>
88 <tr>
89 <th><label for="pass2">New Password</label></th>
90 <td>: <input type="password" id="pass2" placeholder="Enter
password" name="npass"/></td>
91 </tr>
92                <tr>
93                    <td></td>
94 <td style="padding-left:4vw"><input type="submit" name="submitbtn"
value="submit"></td>
95 </tr>
96
97 </table>
98 </fieldset>
99 </form>
100 <!-- JavaScript Bundle with Popper -->
101 <script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.mi
n.js" integrity="sha384-
u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8"
crossorigin="anonymous"></script>
102
103 </body>
104 </html
Practical 7
Implement session and cookie to maintain session during login
and implement visitor counter.
1 <?php
2 // B.Tech Computer Science and Engineering
3    // Balkrishna Mehta
4    // 202103103510434
5
6 $counter = 0;
7 session_start();
8    if(isset($_REQUEST['submitbtn'])){
9        unset($_REQUEST['submitbtn']);
10 $conn = mysqli_connect('localhost','root','','WD');
11 $query = "SELECT * FROM REGISTRATION";
12 $result = mysqli_query($conn,$query);
13 $prep_stat = mysqli_prepare($conn,$query);
14 mysqli_stmt_execute($prep_stat);
15 $result = mysqli_stmt_get_result($prep_stat);
16 while($row = mysqli_fetch_assoc($result)) {
17 $data[] = $row;
18 }
19 $qwe = 0;
20 for($i=0;$i<count($data);$i++){
21 if($data[$i]['Name']==$_REQUEST['Name'] && $data[$i]
['Password']==$_REQUEST['Password']){
22 $qwe = 1;
23 $row = $data[$i];
24 }
25 }
26 if($qwe == 1){
27 $_SESSION['data'] = $row;
28 //ip = $_SERVER['REMOTE_ADDR'];
29 $Name = $_REQUEST['Name'];
30 $query2 = "SELECT * FROM counter where Name ='$Name'";
31 $result2 = mysqli_query($conn,$query2);
32 $data2 = mysqli_num_rows($result2);
33 if($data2 < 1){
34 $query = "INSERT INTO counter(Name) values('$Name')";
35 $result = mysqli_query($conn,$query);
36 }
37
38 //$_SESSION['counter'] = $counter;
39 //setcookie('counter',$counter, time() + (86400*30),"/");
40 setcookie('Name',$Name, time() + (86400*30),"/");
41 header("Location: logout.php");
42 }
43 else{
44 $error = "login unsuccesfull";
45 }
46   }
47 ?>
48 <!DOCTYPE html>
49 <head>
50 <style>
51 th{
52 text-align:left;
53 }
54 </style>
55 </head>
56 <body>
57 <div style="margin-left:auto; margin-top:1.1em !important; text-
align:center;">B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434</div>
58 <?php
59 if(!empty($error)){
60 echo "<div style='position:absolute; left:35vw; top:5vw; border:1px
solid black; color:red;
61 width:29.2vw; padding:0.3em; margin:0.3em'>
62 $error
63 </div>";
64 }
65 ?>
66 <form action="" method="post" style="width:30vw; position:absolute;
left:35vw; top:8vw;">
67 <fieldset>
68 <legend><h1>Login</h1></legend>
69 <table>
70 <tr>
71 <th><label for="uname">Username</label></th>
72 <td>: <input type="text" id="uname"placeholder="Enter username"
name="Name"/></td>
73 </tr>
74 <tr>
75 <th><label for="pass1">Password</label></th>
76 <td>: <input type="password" id="pass1" placeholder="Enter password"
name="Password"/></td>
77 </tr>
78                <tr>
79                    <td></td>
80 <td style="padding-left:4vw"><input type="submit" name="submitbtn"
value="submit"></td>
81 </tr>
82
83 </table>
84 </fieldset>
85 </form>
86 </body>
87 </html>
1 <?php
2
3    // B.Tech Computer Science and Engineering
4    // Balkrishna Mehta
5    // 202103103510434
6
7    session_start();
8    $conn = mysqli_connect('localhost','root','','WD');
9    //Counting
10    $query1 = "SELECT * FROM counter";
11    $result = mysqli_query($conn,$query1);
12    $counter = mysqli_num_rows($result);
13  
14    $Name = $_COOKIE['Name'];
15    if(isset($_REQUEST['logout'])){
16        session_unset();
17        setcookie('data',"",time() - 3600);
18        $query = "DELETE FROM counter WHERE Name ='$Name'";
19 $result = mysqli_query($conn,$query);
20        header('Location: logout.php');
21   }
22    if(isset($_COOKIE['data'])){
23        $data  = json_decode($_COOKIE['data'],true);
24   }
25    elseif(isset($_SESSION['data'])){
26        $data = $_SESSION['data'];
27        setcookie('data', json_encode($data) , time() + (86400 * 30));
28   }
29    else{
30        header('Location: login.php');
31   }
32 ?>
33 <!DOCTYPE HTML>
34    <head>
35        <meta name="viewport" content="width=device-width, initial-scale=1">
36        <link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
37        <script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min
.js" integrity="sha384-
MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
38    </head>
39    <body style="background-color: #FFFFF0; margin-top:3em">
40    <div style="margin-left:auto; margin-top:1.1em !important; text-
align:center;">B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434</div>
41        <div style="display:grid; place-items:center; margin:auto;
width:18rem; border:2px solid; margin-top:2em !important; padding:1em;
background-color:white !important;">
42            <p><?php echo $data['Name']."  ";?></p>
43            <p><?php echo $data['Email']."  ";?></p>
44            <p><?php echo $data['Number']."  ";?></p>
45            <p><?php echo $data['DOB']."  ";?></p>
46            <p><?php echo $data['Gender']."  ";?></p>
47            <p><?php echo $data['Department']."  ";?></p>
48            <p><?php echo $data['Hobby']."  ";?></p>
49            <p><?php echo $data['Address']."  ";?></p>
50
51            <form method="post" action="">
52                <input type="submit" name="logout" value="Logout">
53            </form>
54        </div>
55        <p style="width:100%; text-align:center; margin-top:10em;"><?php echo
$counter;?> People Logged In to this website.</p>
56    </body>
57 </HTML>
Practical 8
Write a PHP script to create a file upload and download portal.
Practical 9
Write a PHP script to verify new user via email and mobile
number.
Practical 10
Write a PHP script to implement “Forget Password” functionality.
1 <?php
2
3 // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7 $Code = mt_rand(111111,999999);
8 $error="";
9 if (!empty($_REQUEST)){
10 if(empty($_REQUEST['pass1'])){
11 $error = ' Enter password';
12 }
13 elseif(!filter_var($_REQUEST['pass1'], FILTER_VALIDATE_REGEXP, array(
"options"=> array( "regexp" => "/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?
&])[a-zA-Z\d@$!%*?&]{8,20}$/"))) ){
14 $error = "  Invalid Password";
15 $_REQUEST['pass1'] = "";
16 }
17        elseif($_REQUEST['pass1'] != $_REQUEST['pass2']){
18 $error = "  Passwords does not match";
19 $_REQUEST['pass2'] = "";
20 }
21        elseif(!array_key_exists("vcode",$_REQUEST)){
22 $error = "Email Not Verified";
23 }
24 elseif(array_key_exists("vcode",$_REQUEST) && $_REQUEST['vcode'] !=
$_REQUEST['Vcode']){
25 $error = "Email Not Verified";
26 }
27 else{
28 $connect = new mysqli('localhost','root','','WD');
29 if($connect->connect_error){
30 die('Connection Failed: '.$connect->connect_error);
31 }
32 else{
33                $stmt = $connect->prepare("update practical9 set password = ?
where email = ?");
34                $stmt-
>bind_param("ss",$_REQUEST['pass1'],$_REQUEST['email']);
35                $stmt->execute();
36 }
37            header('Location: https://www.google.com');
38 }
39 }
40 ?>
41 <!DOCTYPE html>
42 <html lang="en">
43 <head>
44 <meta charset="UTF-8">
45 <meta http-equiv="X-UA-Compatible" content="IE=edge">
46 <meta name="viewport" content="width=device-width, initial-scale=1.0">
47 <title></title>
48 <link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css
" rel="stylesheet" integrity="sha384-
Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi"
crossorigin="anonymous">
49 <script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.mi
n.js" integrity="sha384-
OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3"
crossorigin="anonymous"></script>
50 <script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
51 <script
52 src="https://code.jquery.com/jquery-3.6.1.min.js"
53 integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ="
54 crossorigin="anonymous">
55 </script>
56 <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
57 <style>
58 form{
59 position:absolute;
60 left:35vw;
61 right:35vw;
62 top:12vw;
63 width:30vw;
64 height: fit-content;
65 padding:3em;
66 border: 2px solid #F2F2F2;
67 }
68 .error{
69 position:absolute;
70 left:35vw;
71 right:35vw;
72 top:7vw;
73 width:30vw;
74 height: fit-content;
75 padding:1em;
76 border: 2px solid #EB1D36;
77 }
78 </style>
79 </head>
80 <body>
81 <div style="margin: auto; margin-top:2em !important; width:30vw; text-
align:center;"><p>B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434</p></div>
82 <?php if(!empty($error)) { ?><div class="error"><span class="er">&#9888;
</span><?php echo $error; ?></div><?php ; }?>
83 <form action="" method="post">
84 <div class="form-group" id="verifyEmail">
85            <input type="hidden" name="Vcode" value="<?php echo $Code;?>">
86 <label for="mail">Email</label>
87 <input type="text" class="form-control" placeholder="Email ID"
id="mail" name="email" value="<?php  if(isset($_POST['email'])){echo
$_POST['email'];}?>">
88 <input type="submit" class="btn btn-outline-primary btn-sm" id="send"
value="Send Code" style="margin-left:24.5em; margin-top:0.8em; width:8em;">
89 </div>
90 <div class="form-group" id="verify">
91 </div><br>
92 <div class="form-group">
93 <label for="pass">Password</label>
94 <input type="password" class="form-control" placeholder="atleast 8
characters"  id="pass1" name="pass1"  value = "<?php
 if(isset($_POST['pass1'])){echo $_POST['pass1'];}?>">
95 </div><br>
96        <div class="form-group">
97 <label for="pass">Confirm Password</label>
98 <input type="password" class="form-control" placeholder="atleast 8
characters"  id="pass2" name="pass2" value = "<?php
 if(isset($_POST['pass2'])){echo $_POST['pass2'];}?>">
99 </div><br>
100 <br><button type="submit" class="btn btn-primary" id="btn" style="margin-
left:12em;">Submit</button>
101 </form>
102 </body>
103 <script>
104 $("#send").click(function(event){
105 event.preventDefault();
106 var a = document.getElementById('mail').value;
107 if(!a.includes("@") || !a.includes(".") || a.includes(" ")) {
108 return;
109 }  
110
111        $.ajax({
112            type: "POST",
113            url: 'validateEmail.php',
114            data: {email: a},
115            success: function (data) {
116                if(data == 0){
117                    $("#mail").addClass("is-invalid");
118                    add = '<div id="validationEmail" class="invalid-
feedback">Email does not exists. Please SignIn.</div>';
119                    if ($('#validationEmail').length === 0) {
120                        $( add ).insertAfter( "#mail" );
121                   }
122                    if ($('#vcode').length != 0) {
123                        $("#verify").remove();
124                   }
125               }
126                else{
127                    add = '<label for="vcode">Otp</label><input id="vcode"
name="vcode" class="form-control" type="tel" maxlength="6" size="6">';
128 $("#mail").removeClass("is-invalid");
129                    if ($('#vcode').length === 0) {
130                        $('#verify').append(add);
131                   }
132                    $.ajax({
133                    dataType: 'JSON',
134                    url: 'sendmail1.php',
135                    type: 'POST',
136                    data: 'userName='+$("#name").val()+'&Email='+
$("#mail").val()+'&mobileNo='+ $("#num").val()+'&Code='+ <?php echo $Code;?>,
137                    beforeSend: function(xhr){
138                        $('#send').val('SENDING...');
139                       },
140                        success: function(response){
141                       },
142                        error: function(){
143                       },
144                        complete: function(){
145                            $('#send').val('SENT');
146                       }
147               });
148               }
149           }
150       });
1 <?php
2
3    // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6    
7 use PHPMailer\PHPMailer\PHPMailer;
8 use PHPMailer\PHPMailer\Exception;
9
10
11 require '../PHPMailer/src/Exception.php';
12 require '../PHPMailer/src/PHPMailer.php';
13 require '../PHPMailer/src/SMTP.php';
14
15    $Email = $_POST["Email"];
16    $name = $_POST["userName"];
17    $mobileNo = $_POST["mobileNo"];
18    $Code = $_POST["Code"];
19    $msg = 'Hey '.$name.'. Your need to verify your Email. Your OTP is:
'.$Code;
20
21    $mail = new PHPMailer(true);
22
23    try {
24        $mail->isSMTP();                                            
25        $mail->Host       = 'smtp.gmail.com';                    
26        $mail->SMTPAuth   = true;                                  
27        $mail->Username   = 'krishmehta208@gmail.com';                    
28        $mail->Password   = 'wztxmjakhargkeil';                              
29        $mail->SMTPSecure = 'ssl';            
30        $mail->Port       = 465;                                  
31
32
33        $mail->setFrom('krishmehta208@gmail.com', 'Website_name');
34        $mail->addAddress($Email,$name);    
35        $mail->addReplyTo('no-reply@gmail.com', 'No-reply');
36
37
38
39        $mail->isHTML(true);    
40        $mail->Subject = 'Email Verification';
41        $mail->Body    = $msg;
42        $mail->send();
43
44   }
45    catch (Exception $e) {
46        echo "Message could not be sent.<br><span class='detail'> Invalid mail
ID or Mailer Error: " .$mail->ErrorInfo."</span>";
47   }
48 ?>
49
1 <?php
2
3    // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6
7    $email = $_REQUEST['email'];
8    $conn = new mysqli('localhost','root','','WD');
9    $query = "select * from practical9 where email = '$email'";
10    $result = mysqli_query($conn,$query);
11    $data = mysqli_num_rows($result);
12    echo $data;
13 ?>
Practical 12
Write a program using AJAX and PHP to demonstrate how a Web
page can communicate with the Web server while a user type
characters in input field.
1 <?php
2    // B.Tech Computer Science and Engineering
3 // Balkrishna Mehta
4 // 202103103510434
5 ?>
6 <!DOCTYPE html>
7 <html lang="en">
8 <head>
9    <meta charset="UTF-8">
10    <meta http-equiv="X-UA-Compatible" content="IE=edge">
11    <meta name="viewport" content="width=device-width, initial-scale=1.0">
12    <link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css
" rel="stylesheet" integrity="sha384-
Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi"
crossorigin="anonymous">
13    <script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.mi
n.js" integrity="sha384-
OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3"
crossorigin="anonymous"></script>
14    
15    <title></title>
16    <style>
17        input[type="text"],input[type="password"]{
18            padding:0.5em;
19            margin:0.5em;
20            box-sizing: border-box;
21            border: 3px solid #ccc;
22            -webkit-transition: 0.5s;
23            transition: 0.5s;
24            outline: none;
25       }
26        input[type="text"]:focus, input[type="password"]:focus{
27            border: 3px solid #47B5FF;
28       }
29
30
31    </style>
32 </head>
33 <body id="add_to_me">
34    <div style="position:absolute; left:35vw; top:8vw; text-align:center;
width:30vw;"><p>B.Tech Computer Science and Engineering<br>Balkrishna
Mehta<br>202103103510434</p></div>
35    <form action="" method="post" style="width:30vw; padding:1em; border:1px
solid black; position:absolute; left:35vw; top:16vw;">
36 <fieldset>
37 <legend><h1>Login</h1></legend>
38 <table>
39 <tr>
40 <th><label for="mail">Email</label></th>                          
     
41 <td>: <input type="text" id="mail" placeholder="Enter Email"
name="Email" value="<?php if(isset($_REQUEST['Email'])){echo
$_REQUEST['Email'];}?>" onkeyup="validateEmail(this.value)"/></td>
42 </tr>
43 <tr>
44 <th><label for="pass">Password</label></th>
45 <td>: <input type="password" id="pass" placeholder="Enter password"
value="<?php if(isset($_REQUEST['Password'])){echo $_REQUEST['Password'];}?>"
name="Password" onkeyup="validatePassword(this.value)"/></td>
46 </tr>
47                <tr>
48                    <td></td>
49 <td style="padding-left:4vw"><input type="submit" name="submitbtn"
value="submit" onclick='run(); return false;'></td>
50 </tr>
51
52 </table>
53 </fieldset>
54 </form>
55 </body>
56        <script>
57            function validateEmail(Email){
58                var xmlhttp = new XMLHttpRequest();
59                xmlhttp.onreadystatechange = function(){
60                    if(this.readyState == 4 && this.status == 200){
61                        if(this.responseText == 0){
62                          
 document.getElementById('mail').setAttribute("style","border: 3px solid
#EB1D36;");
63                       }
64                        if(this.responseText == 1){
65                          
 document.getElementById('mail').setAttribute("style","border: 3px solid
#47B5FF;");
66                       }
67                        if(this.responseText == 2){
68                          
 document.getElementById('mail').setAttribute("style","border: 3px solid
#38E54D;");
69                       }
70                   }
71               };
72                xmlhttp.open("GET","index2.php?Email="+Email,true);
73                xmlhttp.send();
74           }
75            function validatePassword(Password){
76                var xmlhttp = new XMLHttpRequest();
77                xmlhttp.onreadystatechange = function(){
78                    if(this.readyState == 4 && this.status == 200){
79                        if(this.responseText == 3){
80                          
 document.getElementById('pass').setAttribute("style","border: 3px solid
#EB1D36;");
81                       }
82                        if(this.responseText == 4){
83                          
 document.getElementById('mail').setAttribute("style","border: 3px solid
#47B5FF;");
84                       }
85                        if(this.responseText == 5){
86                          
 document.getElementById('pass').setAttribute("style","border: 3px solid
#38E54D;");
87                       }
88                   }
89               };
90                xmlhttp.open("GET","index2.php?Password="+Password,true);
91                xmlhttp.send();
92           }
93            function run(){
94                // #38E54D == rgb(56, 229, 77)
95                if(document.getElementById('mail').style.border ==  "3px
solid rgb(56, 229, 77)" && document.getElementById('pass').style.border ==
 "3px solid rgb(56, 229, 77)"){
96                  
 document.getElementById('mail').setAttribute("style","border: 3px solid
#ccc;");
97                  
 document.getElementById('pass').setAttribute("style","border: 3px solid
#ccc;");
98                    if( !( document.querySelectorAll('#alert1').length > 0) )
{
99                        document.getElementById("add_to_me").innerHTML +=
100                        "<div class='alert alert-warning alert-dismissible
fade show' role='alert' id='alert1'> <strong>Login Successful</strong><button
type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'>
</button></div>";
101                   }
102               }
103           }
104        </script>
105 </html>
1 <?php
2
3    // B.Tech Computer Science and Engineering
4 // Balkrishna Mehta
5 // 202103103510434
6        
7    if(isset($_REQUEST['Email'])){
8        if (!empty($_REQUEST['Email']) && !filter_var($_REQUEST['Email'],
FILTER_VALIDATE_EMAIL)) {
9            echo 0;
10       }
11        elseif(empty($_REQUEST['Email'])){
12            echo 1;
13       }
14        else{
15            echo 2;
16       }
17   }
18    if(isset($_REQUEST['Password'])){
19        if (!empty($_REQUEST['Password']) &&
!filter_var($_REQUEST['Password'], FILTER_VALIDATE_REGEXP, array( "options"=>
array( "regexp" => "/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[a-zA-
Z\d@$!%*?&]{8,20}$/"))) ){
20            echo 3;
21       }
22        elseif(empty($_REQUEST['Password'])){
23            echo 4;
24       }
25        else{
26            echo 5;
27       }
28        unset($_REQUEST['Password']);
29   }
30 ?>

You might also like