Server-Side Scripting with PHP and ASP.NET
Server-Side Scripting with PHP and ASP.NET
Unit- V
Server Side Scripting Languages
PHP, WAP & WML, [Link], NodeJS
Syllabus
PHP :
● Introduction to PHP, uses of
PHP,
● general syntactic [Link]
characteristics,
● Primitives, operations ● Overview of
and expressions, the .NET WAP & WML
output, Framework,
● Overview of Overview of Node
● control statements,
C#, JS.
● arrays,
● functions,
● Introduction
● pattern matching, to [Link],
● form handling,
● [Link]
● files, Controls,
● cookies, session ● Web Services
PH
P
Outline
Introduction to PHP,
Features,
sample code,
PHP syntax,
conditions &
Loops, Functions,
String manipulation,
Form handling,
Primitives
1 Integer Type
For displaying the integer value the Integer type is used.
It is similar to the long data type in C.
The size is 32 bit.
2 Double Type
For displaying the real values the double data type is used.
It includes the numbers with decimal point, exponentiation or both. The
exponent can be represented by E or e followed by integer literal.
It is not compulsory to have digits before and after the decimal point.
For instance .123 or 123. is allowed in PHP.
Data Types
3. String Type
There is no character data type in PHP. If the character has to be
represented then it is represented using the string type itself; but in this
case the string is considered to be of length 1.
The string literals can be defined using either single or double quotes.
In single quotes the escape sequence or the values of the literals can
not be
recognized by PHP but in double quotes the escape sequences can be
recognized.
4. Boolean Type
There are only two types of values that can be defined by the Boolean
type and
those are TRUE and FALSE.
sample code –
Example 1 to print Hello World using
PHP
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
sample code –
Example 2 variable declaration
Out Put
<?php
$txt = "Hello world!"; "Hello world!" 5
$x = 5; 10.5
$y = 10.5;
echo $txt;
echo "<br>";
echo $x;
echo "<br>";
echo $y;
?>
PHP
Variables
● Rules for PHP variables:
○ A variable starts with the $ sign, followed by the name of the
variable
○ A variable name must start with a letter or the underscore
character
○ A variable name cannot start with a number
○ A variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ )
○ Variable names are case-sensitive ($age and $AGE are two
sample code –
Example 3- To output text and a variable
<?php <?php
$txt = "[Link]"; $txt = "[Link]";
echo "I love $txt"; echo "I love " . $txt . ;
?> ?>
Program for addition of two numbers
<?php
$n1=5;
$n2=6;
$sum=$n1+$n2;
Echo “Summation is”.$sum;
?>
PHP Variables
Scope
myTest();
A variable declared outside a function has a GLOBAL SCOPE and can only be accessed
PHP Variables Scope-
Global and Local Scope
Example Out
<?php
function myTest() put
{
$x = 5; // local scope Variable x inside function is: 5
echo "Variable x inside function is: Variable x outside function is:
$x";
}
myTest();
echo "Variable x outside
function is: $x";
?>
A variable declared within a function has a LOCAL SCOPE and can only be accessed within
that function:
PHP Variables Scope-
The global Keyword
Example Outp
<?php
$x = 5; ut 15
$y = 10;
function myTest() {
global $x, $y;
$y = $x + $y;
}
Features,
sample code,
PHP syntax,
Functions,
String manipulation,
Form handling,
•If else
•Elseif
Conditional
ladder
Statements
•Switch
•case
While
•Do while
Loop •For
Statements •Foreach
If…else
Syntax Example
<?php
If(condition)
$n=5;
statements; If($n%2 == 0)
else Echo “Number is Even”;
statements; Else
Echo “Number is Odd”;
?>
Elsei
f
Syntax Example
<?php
If(condition) $day=date(“l”);
statements; If($day == “Saturday”))
Elseif(condition) echo “Happy Weekend”;
Elseif($day == “Sunday”))
statements; echo “Happy Sunday”;
Else Else
echo “Nice Working day”;
statements; ?>
Switch case
Example
<?php
$favcolor = “red";
Syntax switch ($favcolor) {
case "red":
Switch(expression) echo "Your favorite color is
{ red!"; break;
Case
case "blue":
constant_expressi
echo "Your favorite color is
on: statements;
break; blue!"; break;
Default:
statement default:
s; echo "Your favorite color is
} neither red, blue!";
} ?>
While Loop
Syntax Example
<?php
while (condition is true)
$x = 1;
{
code to be executed; while($x <= 5) {
} echo "The number is: $x <br>";
$x++;
}
?>
Do-While Loop
Syntax Example
<?php
do { $x = 1;
code to be do {
executed; echo
"The
} while (condition is
number
true); is: $x
<br>";
$x++;
For
Loop
Syntax Example
<?php
for (init counter; test counter;
increment counter) for ($x = 0; $x <= 10;
$x++)
{
{
code to be executed;
echo "The number is:
}
$x <br>";
}
Foreach Loop
Syntax Example
<?php
foreach ($array as
$colors = array("red", green", "blue");
$value) { code
foreach ($colors as $value)
to be executed; {
} echo "$value <br>";
}
?>
Outline
Introduction to PHP,
Features,
sample code,
PHP syntax,
Functions,
String manipulation,
Form handling,
function <?php
function
functionName() { writeMsg() {
code to be echo "Hello
executed; world!";
} }
writeMsg();
?>
Parameterized Functions
Example Output
<?php
Sum is
function Add($a,$b) { 30
$sum=$a+$b;
echo “Sum is
$sum";
} Add(10,20);
?>
Returning value through function
Example Output
<?php
function Add($a,$b) { Sum is
$sum=$a+$b; 30
return $sum;
}
$Result=Add(10,20);
echo “Sum is $Result";
?>
Setting default values for function parameter
Example Output
<?php
function Add($a,
$b=300)
Sum is 130
{
$sum=$a+$b;
Sum is 30
echo “Sum is $sum";
}
Add(10);
Add(10,20);
Dynamic Function Calls
Example Output
<?php
Hello How
function Hello() { R U?
echo "Hello How R
U?";
}
$fh = "Hello";
$fh();
?>
Outline
Introduction to PHP,
Features,
sample code,
PHP syntax,
Functions,
String manipulation,
Form handling,
Features,
sample code,
PHP syntax,
Functions,
String manipulation,
Form handling,
Example
<?php
$age = array("Peter"=>"35", "Ben"=>"37",
"Joe"=>"43"); echo "Peter is " . $age['Peter'] . "
years old.";
?>
Loop Through an Associative Array
Example
<?php
$age = array("Peter"=>"35", "Ben"=>"37",
"Joe"=>"43"); foreach($age as $x => $x_value) {
echo "Key=" . $x . "Value=" . $x_value;
Arrays- Multidimensional Arrays
PHP understands multidimensional arrays that are two, three, four, five,
or more levels deep.
PHP - Two-dimensional Arrays: A two-dimensional array is an
array of arrays First, take a look at the following table:
Name Stock Sold
Volvo 22 18
BMW 15 13
Example
$cars = array
( array("Volvo",22,18
),
Functions on Array
Example Output
Array
<?php (
$a = [a] => apple
array ('a' => 'apple', 'b' => [b] => banana
'banana‘) print_r ($a); )
?>
●Functions on Array: extract()
Converts array into variables
Example Output
<?php
$my_array = array(“Rno" =>
1
“1",
Anna
“ Name" => “Anna", TE Comp
“Class" => “TE Comp");
extract($my_array); echo
$Rno;
echo $Name; echo
$Class;
Functions on Array: compact()
Converts group of variables into array
Example Output
<?php
$firstname = "Peter";
Array
$lastname = "Griffin";
(
$age = "41";
[firstname] => Peter
[lastname] =>
$result = compact("firstname",
Griffin [age] => 41
)
"lastname", "age");
Functions on Array: sort()
<?php
$numbers = array(4, 6, 2, 22, 11);
Features,
sample code,
PHP syntax,
Functions,
String manipulation,
Form handling,
[Link] [Link]
<form action="[Link]"
method="post"> Name: Welcome
<input type="text" <?php
name="t1"> echo $_POST["t1"];
<br> ?>
<input type="submit">
</form>
Form Handling- using Get Method
[Link] [Link]
<form action="[Link]"
method=“get"> Name: Welcome
<input type="text" <?php
name="t1"> echo $_GET[“t1"];
<input type="submit"> ?>
</form>
Form Handling-
Difference between get and post method
$_GET is an array of variables passed to the current script via the URL
parameters.
$_POST is an array of variables passed to the current script via the HTTP POST
method.
Features,
sample code,
PHP syntax,
Functions,
String manipulation,
Form handling,
● What is a Cookie?
● A cookie is often used to identify a user. A cookie is a small file that the
server embeds on the user's computer. Each time the same computer
requests a page with a browser, it will send the cookie too. With PHP, you
can both create and retrieve cookie values.
● Create Cookies With PHP- is created with the setcookie() function.
● Syntax
● setcookie(name, value, expire, path, domain, secure, httponly);
● Only the name parameter is required. All other parameters are optional.
Cookie-Create/Retrieve a Cookie
<?php
setcookie(“name”, “Amit”, time() + (86400 * 30), "/"); // 86400
= 1 day
?>
<?php if(isset($_COOKIE[“name”]))
{
$nm=$_COOKIE[“name”];
echo “Hello”,$nm;
}
else { echo “Coocke is not set”; } ?
>
Cookie-Modifying a Cookie
<?php
// set the expiration date to one hour ago
setcookie("user", "", time() - 3600);
?>
<html>
<body>
<?php
echo "Cookie 'user' is deleted.";
?>
</body>
</html>
Session
s
● A session is a way to store information (in variables) to be used across multiple
pages.
● Unlike a cookie, the information is not stored on the users computer.
● What is a PHP Session?
● When you work with an application, you open it, do some changes, and then
you close it. This is much like a Session. The computer knows who you are. It
knows when you start the application and when you end. But on the internet
there is one problem: the web server does not know who you are or what you
do, because the HTTP address doesn't maintain state.
● Session variables solve this problem by storing user information to be used
across multiple pages (e.g. username, favorite color, etc). By default,
session variables last until the user closes the browser.
● So; Session variables hold information about one single user, and are
available to all pages in one application.
Sessions- Start a
Session
● A session is started with the session_start() function.
● Session variables are set with the PHP global variable:
$_SESSION.
● Example - demo_session1.php
<?php
session_start(); // Start the session ?>
<html>
<body>
<?php
$_SESSION["favcolor"] = "green"; // Set session variable
echo "Session variables are set."; ?>
</body>
</html>
Sessions: Get Session Variable Values
<?php
session_start(); ?>
<html>
<body>
<?php
// to change a session variable, just overwrite it
$_SESSION["favcolor"] = "yellow";
print_r($_SESSION);
?>
</body>
</html>
Sessions: Destroy a Session
To remove all global session variables and destroy the session, use
session_unset() and session_destroy():
Example-
<?php
session_start(); ?>
<html>
<body>
<?php
session_unset(); // remove all session
session_destroy(); variables
?> // destroy the session
</body>
Outline
Introduction to PHP,
Features,
sample code,
PHP syntax,
Functions,
String manipulation,
Form handling,
<?php
// Create connection
//$conn = new mysqli($servername, $username, $password,
$dbname);
$conn = new mysqli(“localhost”, “root”, “”);
//MySǪLi extension (the "i" stands for improved)
<?php
$conn = mysqli_connect(‘localhost’, ‘root’, ‘root’,
‘db1’); if(!$conn){
die(mysqli_connect_error());
}
echo 'Connected successfully<br>';
if($nrows > 0) {
while($row =
mysqli_fetch_assoc($rs)){
echo "ID :{$row['id']}
<br>"; echo"FNAME : {$row['firstname']} <br>";
echo"LNAME : {$row['lastname']} <br>";
echo "--------------------------------<br>";
}
}
else { echo “ No result"; }
mysqli_close($conn);
?>
Refer pdf shared for more operations on Mysql connectivity
WAP &
WML
WAP(Wireless Application
Protocol) -Introduction
The basic aim of WAP is to provide a web-like experience on
small portable devices - like mobile phones and PDAs
WAP -Introduction
● Purpose of WAP
To enable easy, fast delivery of relevant information and services to
mobile users.
● Type of devices that use WAP
Handheld digital wireless devices such as mobile phones, pagers, two-
way radios, smart phones and communicators -- from low-end to high-
end.
● Type of OS that use WAP
It can be built on any operating system including Palm OS, EPOC
32,Windows CE, FLEXOSs
Refer for WAP architecture in details-
Components of WAP Architecture
Bearers :
CDM IS-1 CDP PDC- Etc
GSM PHS FLEX
A 36 D P …
In detail component of WAP
Wireless Application Environment (WAE): This layer is responsible for defining the
application environment and user interface for WAP. It includes:
Wireless Markup Language (WML): A language similar to HTML but designed for mobile devices. It allows the
creation of pages that can be easily viewed on small screens.
WMLScript: A scripting language used to create dynamic content and interactive applications within WML pages.
Wireless Session Protocol (WSP): Manages the session between the mobile device and the
WAP Gateway. It ensures that data is transmitted correctly and efficiently.
Wireless Transaction Protocol (WTP): Provides transaction support for WAP. It handles the
reliability and ordering of messages between the mobile device and the WAP server.
Wireless Transport Layer Security (WTLS): Ensures secure communication between the
mobile device and the WAP server by providing encryption and authentication.
Wireless Datagram Protocol (WDP): Handles the transport of data over the wireless network.
It is similar to the Internet Protocol (IP) used in traditional web communications
Wireless Application Environment
(WAE) - components
● WML is the markup language defined in the WAP specification. WAP sites
are written in WML, while web sites are written in HTML. WML is very
similar to HTML. Both of them use tags and are written in plain text format.
<?xml version="1.0"?>
<wml>
<card id="one" title="First Card">
<p>
This is the first card in the deck
</p>
</card>
<card id="two" title="Second Card">
<p>
Ths is the second card in the deck
</p>
</card>
</wml>
WML
Scripts
● WMLScript (Wireless Markup Language Script) is the client-side
scripting language of WML
(Wireless Markup Language).
● A scripting language is similar to a programming language, but is
of lighter weight.
● Banking:
● Finance:
● Shopping:
● Ticketing:
● Entertainment:
● Weather:
● E- Messaging:
[Link]
ASP.N
ET
● Overview of the .NET Framework,
● Overview of C#,
● Introduction to [Link],
● [Link] Controls,
● Web Services
.NET
history
● .NET Framework supports more than 60 programming languages in
which 11 programming languages are designed and developed by
Microsoft. The remaining Non-Microsoft Languages are
supported by .NET Framework but not designed and developed
by Microsoft.
● There are three significant phases of the development of .NET
technology.
○ OLE Technology
○ COM Technology
.NET
history
.NET
history
● The .Net framework was meant to create applications, which
would run on the Windows Platform.
● The first version of the .Net framework was released in the year
2002.
● The version was called .Net framework 1.0. The Microsoft .Net
framework has come a long way since then, and the current
version is .Net Framework 4.7.2.
● The Microsoft .Net framework can be used to create both –
Form-based and Web-based applications.
● Web services can also be developed using the .Net
.NET history
11 Programming Languages which are designed and
developed by Microsoft are:
C#.NET
[Link]
C++.NET
J#.NET
F#.NET
[Link]
T
WINDOWS
POWERSHELL IRON
RUBY
IRON
PYTHON C
OMEGA
ASML(Abstra
How does [Link] Works ?
Step 1 : When user demands for the [Link] file, the web
browser of the client’s PC
sends this request to IIS server.
Step 2 : The IIS server passes this request to .NET Engine.
Step 3 : The .NET engine reads the file line by line and generates
the script in a file.
Step 4 : The requested .NET file is returned to the web browser.
.NET Framework
Architecture
2. Class Library
● The .NET Framework includes a set of standard class libraries.
● A class library is a collection of methods and functions that can
be used for the core purpose.
What is C#?
C# is pronounced "C-Sharp".
that runs on the .NET Framework. C# has roots from the C family, and
the language is close to other popular languages like C++ and Java.
C# is used for:
● Mobile applications
● Desktop applications
● Web applications
● Web services
● Web sites
● Games
● VR
● Database applications
● And much, much
more!
C# -Example
[Link]
using System;
namespace
HelloWorld
{
class Program
{
static void
Main(string[]
args)
{
[Link]
teLine("Hell
C#- Example Explained
Example explained
● Using System means that we can use classes from the System namespace.
● namespace is used to organize your code, and it is a container for classes
and other namespaces.
● class is a container for data and methods, which brings functionality to your
program.
● Another thing that always appear in a C# program, is the Main method.
● Console is a class of the System namespace, which has a WriteLine() method
that is used to output/print text.
● If you omit the using System line, you would have to write
[Link]() to print/output text.
C# Variables
int - stores integers (whole numbers), without decimals, such as 123 or -123
(int myNum = 5; )
double - stores floating point numbers, with decimals, such as 19.99 or -19.99
(double myDoubleNum = 5.99D;)
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by
single quotes (char myLetter = 'D'; )
string - stores text, such as "Hello World". String values are surrounded by double
quotes (string myText = "Hello"; )
bool - stores values with two states: true or false (bool myBool = true; )
C# Variables
Syntax
type variableName = value;
Example
string name = "John"; Display
Variables Example string name =
"John";
[Link]("Hello " + name);
Declare Many Variables
int x = 5, y = 6, z = 50;
c#- Get User Input
Example
[Link]("Enter username:");
[Link]();
C# Assignment Operators
C# Conditional Statements
C# has the following conditional statements:
[Link]
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
[Link](“welcome User!!!!");
}
}
}
Refer following link to create first C# program
using Visual studio or VS code IDE
[Link]
[Link]
[Link] introduction
AS
P
Acti Serv Pag
ve er es
[Link] introduction
● [Link] is a web application framework developed and marketed by Microsoft
to allow programmers to
build dynamic web sites.
[Link] is a platform for developing web applications. It works on HTTP protocol
and makes use of HTTP commands.
● ASP is a development framework for building web pages.
● ASP supports many different development models:
○ Classic ASP
○ [Link] Web Forms
○ [Link] MVC
○ [Link] Web Pages
○ [Link] API
[Link] introduction
1. Button Controls
2. Text Boxes and Labels
3. Check Boxes and Radio Buttons
4. List Controls
5. The ListItemCollection
6. HyperLink Control
7. Image Control
How to Create Web Form Application ?
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<b> User Name:</b>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
Step 4 : The above web from can be executed on IIS Express
server. Click on the IIS Express option present below the menu
bar.
Output-
• we can select the controls from the ToolBox under the Standard option.
Click and drag the desired controls on the form.
https
://[Link]/UploadFile/29d7e0/steps-to-create-a-si
mple-web-service-and-use-it-in-Asp-Net
/
NodeJS
[Link] :
Overview
How PHP or ASP handles a file request: How [Link] handles a file request:
[Link] the task to the computer's file [Link] the task to the computer's file
system. system.
[Link] while the file system opens [Link] to handle the next request.
and reads the file. [Link] the [Link] the file system has opened and read
content to the client. the file, the server returns the content
[Link] to handle the next request.
•[Link] eliminates the waiting, and simply to the client.
continues with the next request.
•[Link] runs single-threaded, non-blocking, asynchronous programming, which is
very memory efficient.