Adv Web Tech
Adv Web Tech
UNIT ONE
◦ By ROBIN NIXON
◦ Publishers- Oreilly
UNIT FOUR
PHP FUNCTIONS AND OBJECTS
* FUNCTIONS
* INCLUDING AND REQUIRING FILES
* PHP OBJECTS (OBJECT ORIENTED PROGRAMMING)
UNIT SIX
FORM HANDLING
* BUILDING FORMS
UNIT SEVEN
• COOKIES, SESSION AND AUTHENTICATION
UNIT EIGHT
PROJECT
WEB SERVERS
Apache
IIS
Novell's Web Server (Novel OS)
Lotus Domino servers (IBM)
JBoss(Mostly used in Eclipse)
GlassFish (For Java EEE using netbeans)
operating system
PHP
ASP.NET
RUGBY RAIL
JAVA
PHTHON
etc
UNIT TWO
PHP is a recursive acronym for Hypertext
Preprocessor
Developed by…Rasmus Lerdorf
Year :1994
Website: http://www.php.net
LANGUAGE SYNTAX
Basic Syntax
Semicolons
String variables
$username = "Kojo Mensah";
The quotation marks indicate that “Fred Smith” is a string of
characters. You must enclose each string in quotation marks
Numeric variables
$count = 17;
You could also use a floating-point number (containing
a decimal point);
• Variable names can contain only the characters: a-z, A-Z, 0-9, and _
(underscore).
<?php
function longdate($timestamp)
{
$temp = date("l F jS Y", $timestamp);
return "The date is $temp";
}
Global variables
Also, some data may be large and complex, and you don’t
want to keep passing it as arguments to functions.
<?php
function test()
{
static $count = 0;
echo $count;
$count++;
}
?>
$var1=‘PHP’; Assign a value of ‘PHP’ to $var1
$var2=5;
$var3=$var2 +1;
$var2= $var1;
echo $var1; // out PHP
echo $var2; //
echo $var3 //
echo $var2. ‘rule’; // Outputs ‘PHP rule’
Superglobal variables
global scope of the script. The variable names are the keys of the
array.
locations. The entries in this array are created by the web server
and there is no guarantee that every web server will provide any
or all of these.
$_POST Variables passed to the current script via the HTTP POST
method.
$_FILES Items uploaded to the current script via the HTTP POST
method.
method.
$_GET Variables passed to the current script via the
HTTP GET method
ARITHMETIC OPERATORS:
and $k == 2
|| Or $j < 5 || $j > 10
or $j < 5 or $j > 10
Eg
mysql_select_db($database) or die("Unable to select
database");
Multiple-Line Commands
There are times when you need to output quite a lot of text from
PHP and using several echo (or print) statements would be time-
consuming and messy.
<?php
$lecturer = “Emmanuel ";
echo “This a Advance Web Class
offered by the second year class.
Regular/Evening and Weekend
Taught by $lecturer .";
?>
here-document or heredoc
<?php
$author = "Alfred E Newman";
echo <<<_END
This is a Headline
This is the first line.
This is the second.
- Written by $author.
_END;
?>
What this code does is to tell PHP to output everything
between the two _END tags as if it were a double-quoted
string.
UNIT THREE
An expression is a combination of values,
variables, operators, and functions that results
in a value.
y = 3(abs(2x) + 4)
which in PHP would be:
$y = 3 * (abs(2*$x) + 4);
The if Statement
<?php
if ($bank_balance < 100)
{
$money += 1000;
$bank_balance += $money;
}
?>
The else Statement
<?php
if ($bank_balance < 100)
{
$money += 1000;
$bank_balance += $money;
}
else
{
$savings += 50;
$bank_balance -= 50;
}
?>
The elseif Statement
There are also times when you want a number of different possibilities to
occur, based upon a sequence of conditions.
<?php
if ($bank_balance < 100)
{
$money += 1000;
$bank_balance += $money;
}
elseif ($bank_balance > 200)
{
$savings += 100;
$bank_balance -= 100;
}
else
{
$savings += 50;
$bank_balance -= 50;
}
?>
A multiple-line if...elseif... statement
<?php
if ($page == "Home") echo "You selected
Home";
elseif ($page == "About") echo "You selected
About";
elseif ($page == "News") echo "You selected
News";
elseif ($page == "Login") echo "You selected
Login";
elseif ($page == "Links") echo "You selected
Links";
switch statement
<?php
switch ($page)
{
case "Home": echo "You selected Home";
break;
case "About": echo "You selected About";
break;
case "News": echo "You selected News";
break;
case "Login": echo "You selected Login";
break;
case "Links": echo "You selected Links";
break;
}
?>
Breaking out
.
The ? Operator
One way of avoiding the verbosity of if and else statements
is to use the more compact ternary operator, ?, which is
unusual in that it takes three operands rather than the
more usual two.
<?php
echo $fuel <= 1 ? "Fill tank now" : "There's enough fuel";
?>
LOOPING
A while loop
<?php
$fuel = 10;
while ($fuel > 1)
{
// Keep driving ...
echo "There's enough fuel";
}
?>
$count = 0;
while (++$count <= 12)
echo "$count times 12 is " . $count * 12 .
"<br />";
?>
<?php
$count = 1;
do
echo "$count times 12 is " . $count * 12 .
"<br />";
while (++$count <= 12);
?>
For Loops
<?php
for ($count = 1 ; $count <= 12 ; ++$count)
echo "$count times 12 is " . $count * 12 .
"<br />";
?>
Each for statement takes three parameters:
An initialization expression
A condition expression
A modification expression
The for loop from with added curly braces
<?php
for ($count = 1 ; $count <= 12 ; ++$count)
{
echo "$count times 12 is " . $count * 12;
echo "<br />";
}
?>