Why The Lucky Stif
Why The Lucky Stif
LANGUAGE
MODULE
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
when you don't create things, you become defined by your tastes rather than ability. your tastes only
narrow
&
exclude
people.
so
create.
Why The Lucky Stif
Bill said that he thought that the esteemed leader of the house had it in mind to
tell the unfortunate vice president that the calls that he made from the office in the
White House that he thought was private..
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
Scripting Languages
Scripting is about producing simple very-high-level-languages that are friendly to the
programmer who has a life.
Modern sophisticated HLLS
Java, C++, C#, etc. are extremely complex
(they have a nasty tendency to get bigger and bigger as designers add more and more useful
facilities, and interface components, and bells and whistles, )
Take a long time to learn to use (but are wonderful when you really understand them).
Modern sophisticated HLLS Java, C++, C#, etc. are extremely complex
(they have a nasty tendency to get bigger and bigger as designers add more and more useful
facilities, and interface components, and bells and whistles, )
Take a long time to learn to use (but are wonderful when you really understand them).
In this example below there are four type of programming one is the c++
programming language, java programming, HTML and the other one is PHP programming,
As we can see the syntax and approach to display the output
Source Code
Filename extencion
Automatically
save
as
Filename.cpp
Programming Type
C++ PROGRAMMING
JAVA PROGRAMMING
HYPERTEXT
PROCESSOR
PRE
C# PROGRAMMIN
save as
Filename.java
save as
Filename.php
save as
Filename.html
Save as
Filename
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello
World!");
// Keep the console
window open in debug mode.
Console.WriteLine("Press
any
key to exit.");
Console.ReadKey();
}
}
}
All program output the same word which is HELLO WORLD.
Web Scripting
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
Web sites and the web pages that they are composed of must be written using one or more
computer languages that web browsers can understand. Let's take a brief introduction to the
concept of web languages by looking at some of the most common ones.
HTML, XHTML, and CSS
The most commonly used and broadly applicable web language is HTML, which stands
forHyperText Markup Language. In this course we'll actually be learning HTML's smarter
descendant, XHTML (the X is for eXtensible).
As its title reveals, XHTML is a markup language, not a programming language. While
programming languages logically process data or information for various dynamic results, a
markup language simply "marks" bits and pieces of information as a means of identifying that
information. XHTML is what we use to prepare our content for the user. Rest assured that before
we're halfway through this course you will know XHTML inside and out.
While most web browsers perform some basic visual formatting of HTML de facto, we will need to
rely upon CSS, or Cascading Style Sheets to make our pages look awesome. CSS is the
formatting language that controls how the content that we identified with XHTML looks in a web
browser.
Client-Side Languages
Javascript is the ubiquitous web scripting language that runs on the client-side. This means
that everything Javascript does, it does using the user's web browser. Javascript is used to
enhance user interactivity within web pages, and can change the way a web page looks and acts
at any time, based on user input.
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
-If we do the validation on the client, this reduces the work that the server has to do and reduces
the time taken to respond to the user.
HTML5 essentially includes Javascript elements to enhance its power.
Ouput
</body>
</html>
Both XHTML and CSS are delivered from the host web server to the client web browser once:
when the page loads. Unless acted upon by another web language, once XHTML and CSS for a
given page is loaded, it will remain static.
Server-Side Languages
While Javascript is a client-side web language, there are a number of powerful server-side web
languages, such as PHP, ASP, PERL, etc. Server-side languages allow the client web browser to
receive custom information and interactions on the fly through dynamic communication with the
web server. Server-side languages often "talk" to databases in order to store and retrieve user
information (e.g. shopping carts, searchable databases, etc).
PHP
<?php
$servername
Output
Connect Successfully
= "localhost";
ADRIAN D. EVANCULLA, MIT
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
$username
$password
//
$conn
$username,
= "username";
= "password";
Create
connection
= new mysqli($servername,
$password);
//
Check
if ($conn->connect_error) {
die("Connection
failed:
>connect_error);
}
echo "Connected
?>
connection
".
$conn-
successfully";
Note: This sample will just work considering you have the localhost which is xampp and
username of your xampp and password you use to connect to xampp server follow instruction in
xampp in module 1.
You (the client) send a request to the server for a web page. The server looks up the web page
using part of the URL you have sent it, then returns the HTML page which your browser
subsequently displays on your machine.
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
You (the client) send a request to the server and it dynamically determines the HTML that is to
be returned.
The dynamics of the reply is achieved through extending the web server with a program (script)
that does some data processing and creates HTML output based on the data you sent (e.g.
contents of a form).
The process of generating the HTML response is performed server-side.
Dynamic Web Model
One approach is the Common Gateway Interface (CGI) where we have a separate program that
can be executed
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
Laboratory
The if, elseif ...else and switch statements are used to take decision based on the
different condition.
You can use conditional statements in your code to make your decisions. PHP supports
following three decision making statements
if...else statement use this statement if you want to execute a set of code when a
condition is true and another if the condition is not true
elseif statement is used with the if...else statement to execute a set of code if one of the
several condition is true
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
switch statement is used if you want to select one of many blocks of code to be executed,
use the Switch statement. The switch statement is used to avoid long blocks of if..elseif..else
code.
Syntax
if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
Example
The following example will output "Have a nice weekend!" if the current day is Friday,
Otherwise, it will output "Have a nice day!":
<html>
<body>
<?php
$d =date("D");
if($d =="Fri")
echo"Have a nice weekend!";
else
echo"Have a nice day!";
?>
</body>
10
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
</html>
Syntax
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
Example
The following example will output "Have a nice weekend!" if the current day is Friday,
and "Have a nice Sunday!" if the current day is Sunday. Otherwise, it will output "Have a
nice day!"
<html>
<body>
<?php
$d =date("D");
if($d =="Fri")
echo"Have a nice weekend!";
elseif($d =="Sun")
echo"Have a nice Sunday!";
else
echo"Have a nice day!";
?>
</body>
11
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
</html>
Syntax
switch (expression){
caselabel1:
code to be executed if expression = label1;
break;
caselabel2:
code to be executed if expression = label2;
break;
default:
code to be executed
if expression is different
from both label1 and label2;
}
Example
The switch statement works in an unusual way. First it evaluates given expression then
seeks a lable to match the resulting value. If a matching value is found then the code
associated with the matching label will be executed or if none of the lable matches then
statement will execute any specified default code.
<html>
<body>
12
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
<?php
$d =date("D");
switch($d){
case"Mon":
echo"Today is Monday";
break;
case"Tue":
echo"Today is Tuesday";
break;
case"Wed":
echo"Today is Wednesday";
break;
case"Thu":
echo"Today is Thursday";
break;
case"Fri":
echo"Today is Friday";
break;
case"Sat":
echo"Today is Saturday";
break;
case"Sun":
echo"Today is Sunday";
13
WEEK # 3
Introduction to Web
scripting languages
2 Hours Lecture 1 hour lab
break;
default:
echo"Wonder which day is this ?";
}
?>
</body>
</html>
Laboratory
Activity # 1
14