Engineering Notes
This blog contains Information Security, Cryptography and Network Security, Network Security, Web and Internet Technologies, Campus Placement questions and Python Notes.
Wednesday, 5 March 2025
Saturday, 6 April 2024
The anatomy of a PHP Page(or) Embedding PHP Code in Your Web Pages
A PHP script is a file (ending with a .php extension) consisting of text, HTML, and PHP instructions interspersed throughout the file.
The PHP instructions are contained within two HTML style tags; is the closing tag. Everything between these two tags is interpreted by the PHP module (also called interpreter) and converted to regular text and HTML before being sent back to the requesting browser.
There are four delimitation variants:
- Default Syntax
- Short-Tags
- Script
- ASP Style
- Short-circuit syntax
Embedding Multiple Code Blocks :
Commenting Your Code:
- Single-Line C++ Syntax
- Shell Syntax
- Multiple-Line C Syntax (/*………*/)
HTML5 Input Types
HTML5 added several new input types:
<input type="color"/>
<input type="date"/>
<input type="datetime-local"/>
<input type="email"/>
<input type="month"/>
<input type="number"/>
<input type="range"/>
<input type="search"/>
<input type="tel"/>
<input type="time"/>
<input type="url"/>
<input type="week"/>
New Tags in HTML5
<audio>
<bdi> Bi-Directional Isolation
<canvas>
<datalist>
<details>
<dialog>
<embed>
<figcaption> tag defines a caption for a <figure> element
<figure>
<footer>
<header>
<mark>
<meter>
<nav> tag defines a set of navigation links
<output>
<progress>
<source>
<video>
<wbr> (Word Break Opportunity)
<article>
<aside>
<main>
<menuitem>
<picture>
<ruby> tag specifies a ruby annotation.
<rp>
<rt>
<section>
<summary>
<time>
<track> tag specifies text tracks for media elements <audio> and <video>
Multi page form in PHP with Example
A multi page form in PHP are used to retain values of a form and can transfer them from one page to another .
multipage.php
<html>
<body>
<div style="width: 500px; text-align: left;">
<form action="multipage2.php" method="post">
<p>Page 1 Data Collection:</p>
<input type="hidden" name="submitted" value="yes" />
Your Name: <input type="text" name="yourname" maxlength="150" />
<br /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />
</form>
</div>
</body>
</html>
OUTPUT
multipage2.php
<html><body>
<div style="width: 500px; text-align: left;">
<form action="multipage3.php" method="post">
<p>Page 2 Data Collection:</p>
Selection:
<select name="yourselection">
<option value="nogo">make a selection...</option>
<option value="Choice1">Choice1</option>
<option value="Choice2">Choice2</option>
<option value="Choice3">Choice3</option>
</select><br /><br />
<input type="hidden" name="yourname" value="<?php echo $_POST['yourname']; ?>" />
<input type="submit" value="Submit" style="margin-top: 10px;" />
</form>
</div>
</body></html>
OUTPUT
multipage3.php
<html>
<body>
<div style="width: 500px; text-align: left;">
<form action="multipage4.php" method="post">
<p>Page 3 Data Collection:</p>
Your Email: <input type="text" name="youremail" maxlength="150" /><br />
<input type="hidden" name="yourname" value="<?php echo $_POST['yourname']; ?>" />
<input type="hidden" name="yourselection" value="<?php echo $_POST['yourselection']; ?>" />
<input type="submit" value="Submit" style="margin-top: 10px;" />
</form>
</div>
</body>
</html>
OUTPUT
multipage4.php
<html>
<head><title>Page 4</title></head>
<body><div style="width: 500px; text-align: left;">
<?php
//Display the results.
echo "Your Name: " . $_POST['yourname'] . "<br />";
echo "Your Selection: " . $_POST['yourselection'] . "<br />";
echo "Your Email: " . $_POST['youremail'] . "<br />";
?>
<a href="multipage.php">Try Again</a>
</div></body></html>
OUTPUT
Sunday, 1 November 2020
What is Information Security?
Information Security is not only about securing information from unauthorized access. Information Security is basically the practice of preventing unauthorized access, use, disclosure, disruption, modification, inspection, recording or destruction of information. Information can be physical or electronic one.
Saturday, 31 October 2020
Monday, 26 October 2020
Write a PHP program to store user registration information (like user name, address, DOB, age, Aadhar card number, gender) with data base and display that details on view screen in tabular manner
user.html
<html>
<head>
<title> user registration information</title>
</head>
<body>
<h3 align="center">user registration information</h3>
<form name="registration" method="post" action="storeuser.php">
<table align="center" height="450">
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td>Address:</td>
<td><textarea rows="4" cols="30" name="address" id="address"></textarea> </td>
</tr>
<tr>
<td>Date of Birth:</td><td><input type="date" name="dob" id="dob"/></td>
</tr>
<tr>
<td>Age:</td>
<td><input type="number" name="age" id="age" /></td>
</tr>
<tr>
<td>Aadhar Number:</td>
<td><input type="text" name="aadhar" id="aadhar" /></td>
</tr>
<tr>
<td>Gender:</td>
<td><input type="radio" name="gender" value="male" /> Male
<input type="radio" name="gender" value="female" /> Female</td>
</tr>
<tr>
<td colspan="2" align="center">
<input value="Submit" type="submit"/>
<input value="reset" type="reset" />
</td>
</tr>
</table>
</body>
</html>
storeuser.php
<?php
$link = mysqli_connect("localhost", "root", "", "wit");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$user = mysqli_real_escape_string($link, $_POST['name']);
$address = mysqli_real_escape_string($link, $_POST['address']);
$dob = mysqli_real_escape_string($link, $_POST['dob']);
$age = mysqli_real_escape_string($link, $_POST['age']);
$aadhar = mysqli_real_escape_string($link, $_POST['aadhar']);
$gender = mysqli_real_escape_string($link, $_POST['gender']);
// attempt insert query execution
$sql = "INSERT INTO storeuser (name, address,dob,age,aadhar,gender) VALUES ('$user', '$address',
'$dob','$age','$aadhar','$gender')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
$link_address="store.html";
echo "<a href='".$link_address."'>Go to Register Page</a>";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
<a href="display.php">|Display|</a>
display.php
<html>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("wit");
$r=mysql_query("select * from storeuser");
echo"<table border=1>";
echo"<tr><th>User Name</th><th>Address</th><th>Date of Birth</th><th>Age</th><th>Aadhar Number</th><th>Gender</th></tr>";
while ($row=mysql_fetch_array($r))
{ echo"<tr>";
echo "<td>".$row['0']."</td>"."<td>".$row['1']."</td>"."<td>".$row['2']."</td>"."<td>".$row['3']."</td>"."<td>".$row['4']."</td>"."<td>".$row['5']."</td>";
echo "</tr>";
}
echo"</table>";
?>
<a href="store.html">|Home|</a>
</body>
</html>
Monday, 19 October 2020
Write a script that asks the user to enter two numbers and outputs text that displays the sum, product, difference and quotient of the two numbers.
<html>
<head>
<title>javascript using sum, product, difference and quotient</title>
<script>
var number1;
var number2;
var sum;
var product;
var difference;
var quotient;
number1 = parseInt(window.prompt( "Enter first number" ));
number2 = parseInt(window.prompt( "Enter second number" ));
sum = number1 + number2;
product = number1 * number2;
difference = number1 - number2;
quotient = number1 / number2;
document.writeln( "<h3>The sum is " + sum + "</h3>" );
document.writeln( "<h3>The product is " + product + "<h3>");
document.writeln( "<h3>The difference is " + difference + "<h3>");
document.writeln( "<h3>The quotient is " + quotient + "<h3>");
</script></head>
</html>
Output:
Sunday, 18 October 2020
Design a form using HTML and java script to collect the details from the user such as name, gender (radio button), address, state & city. Create a dynamic drop down list for state and based on state, create another drop down list containing list of cities for that state.
<html>
<head><title>dynamic drop down list</title>
<script>
function dropdownlist()
{
var state=document.getElementById('input').value;
if(state==="AP")
{
var array=["Tirupati","vizag","kadapa","Amaravathi","kurnool"];
}
else if(state==="KA")
{
var array=["Bangalore","Mysore","Mangalore","Hubli"];
}
else if(state==="TN")
{
var array=["vellore","chennai","Coimbatore","Madurai"];
}
else if(state==="TG")
{
var array=["Hyderabad","Warangal","Nizamabad","Karimnagar"];
}
else
{
var array=[];
}
var string='';
for(i=0;i<array.length;i++)
{
string=string+"<option>"+array[i]+"</option>";
}
string="<select name='loc'>"+string+"</select>";
document.getElementById('output').innerHTML=string;
}
</script></head>
<body>
<form name="collectdetails">
<p>Name:<input type="text" name="uname" id="uname" /></p>
<p>Gender:<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="female">Female</p>
<p>Address:<textarea rows="4" cols="10" placeholder="please enter the proper address"></textarea></p>
<p>
State:
<select id="input" onChange='dropdownlist()'>
<option>select</option>
<option>AP</option>
<option>TG</option>
<option>TN</option>
<option>KA</option>
</select>
</p>
City:
<div id="output">
<select>
<option>select</option>
</select>
</div></form></body>
</html>
Output:
Write a script that reads an integer and determines whether it is arm strong number or not.
<html><head><title>Armstrong number or not</title>
<script>
function Armstrong()
{
var flag,number,remainder,addition = 0;
number = Number(document.getElementById("num").value);
flag = number;
while(number > 0)
{
remainder = number%10;
addition = addition + remainder*remainder*remainder;
number = parseInt(number/10);
}
if(addition == flag)
{
window.alert("The input number is Armstrong");
}
else
{
window.alert("The input number is not Armstrong");
}
}
</script></head>
<body>
<h1>Whether a number is Armstrong or not</h1>
Enter the number :<input type="text" name="n" id = "num"/><br/>
<input type="submit" value="CHECK" onClick="Armstrong()" />
</body>
</html>
For example Armstrong numbers are : 153 370 371 407
Output:
Write a PHP script to sort the elements in descending order of an array.
Example 1
<?php
$numbers = array(20, 91, 4, 39, 23);
rsort($numbers);
$arraylength = count($numbers);
for($x = 0; $x < $arraylength; $x++) {
echo $numbers[$x];
echo "<br>";
}
?>
Output:
91
39
23
20
4
Example 2
<?php
$cars = array("Maruthi", "TATA", "KIA");
rsort($cars);
$carslength = count($cars);
for($i = 0; $i < $carslength; $i++) {
echo $cars[$i];
echo "<br>";
}
?>
Output:
TATA
Maruthi
KIA
Example 3
<?php
// Define array
$numbers = array(1,2,3,4,5,6,7,8,9,10);
// Sorting and printing array
rsort($numbers); // rsort- sort arrays in descending order
print_r($numbers);
?>
Output:
Array ( [0] => 10 [1] => 9 [2] => 8 [3] => 7 [4] => 6 [5] => 5 [6] => 4 [7] => 3 [8] => 2 [9] => 1 )
Example 4
<?php
$colors = array("Red", "Blue", "Green","Yellow");
rsort($colors);
print_r($colors);
?>
Output: Array ( [0] => Yellow [1] => Red [2] => Green [3] => Blue )