Internet Technology & its Applications
Prof. Ami Tusharkant ChoksiCKPCET, Surat.
What is Internet Technology?
Technology with internet can provide applications, information for internet users.
First thing come to our minds with internet is web. i.e. www (world wide web)
Applications integration of e-business models with front and
back office development of an intranet for your employees development of an extranet for your customers development of a web shop implementation of content management
systems e-mail marketing implementation of online payment systems
History of World Wide Web[1]
“A global hypertext space is created in which any network-accessible information could be referred to by a single Universal Document Identifier which was later called WorldWideWeb, a point and click hypertext editor which ran on the NeXT machine”. - Tim Berners-Lee
Requirements To run WWW Programs
HTML (HyperText Markup Language) URL (Universal Resource Locator) HTTP (Hyper Text Transfer Protocol) Web Server (Apache, Tomcat, GlassFish,
WebLogic, etc.) Web application programming languages (Pre
Hypertext Processor, Java Servlet, Java Server Pages, Common Gateway Interface/perl, Active Server Pages, JScipt/JavaScript, VBScript, eXtensible Markup Language)
What's server side and client side progg. Languages?
Programs which runs on server is called server side progg.
Programs which runs on client is called client side progg.
Server Side Progg. vs. Client Side Progg.
Server Side Progg. Programs which runs on
server Compiler/Interpreter for
programs needed at client
PHP, JSP, ASP, Java Servlet, CGI/perl etc.
Slower Applications:
Authentication, Authorization
Client Side Progg. Programs which runs on
client Compiler/Interpreter for
programs needed at client
JavaScript, Jscript, Vbscript, HTML, XML
Faster Applications: Validation
of forms done
Pre Hypertext Processor
Opensource product
Form handling, file processing, and database access
Server side scripting language
PHP processor has two modes: copy (XHTML)
interpret (PHP)
Purely Interpreted
PHP can be used as
Server-side scripting
Command line scripting
Writing desktop applications
Simple PHP Program (first.php)
<html>
<body>
<?php
echo “hi and welcome to the world of PHP”;
phpinfo();
?>
</body>
</html>
Configure Apache For PHP
/etc/httpd/conf/httpd.conf#Use for PHP 5.x:
LoadModule php5_module modules/libphp5.so
AddHandler php-script php
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Add input/output filters (older versions of Apache, in new versions following code will give error of “an unknown filter was not added: PHP” )
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 9524288</Files>
/etc/httpd/conf/httpd.conf If with user's home directory we want to
access
<IfModule mod_userdir.c>
#UserDir disabled
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disabled" line above, and uncomment the following line instead: UserDir public_html
</IfModule>
/etc/httpd/conf/httpd.conf<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
Deploy program on webserver Restart apache web server
/etc/rc.d/init.d/httpd restart
OR Service httpd restart
Login as ami(user)
mkdir public_html
Put first.php in /home/ami/public_html dir
chmod -R o+rx /home/ami/*
chmod o+rx /home/ami
chmod o+rx /home
Check in browser
http://localhost/~ami/first.php
If u have root previllages
• In /etc/httpd/conf/httpd.conf check for DocumentRoot
• Generally DocumentRoot is /var/www/html
• Put the first.php file in /var/www/html dir
• Set permission of first.php as o+rx
• Run in browser as http://localhost/first.php
Comments in PHP
// this is a comment # shell script like comment /* C and java-like comments */
Primitives, Operations, and Expressions
- No type declarations of variable
- Variable can be used as $var
- An unassigned (unbound) variable has the value, NULL
- The unset function sets a variable to NULL
- The IsSet function is used to determine whether a variable is NULL
- error_reporting(15); - prevents PHP from using unbound variables
- list predefined variables, including the environment variables of the host OS with phpinfo() in a script
There are eight primitive types:
- Four scalar types: Boolean, integer, double, and string
- Two compound types: array and object
- Two special types: resource and NULL
- Integer & double are like those of other languages
- Strings
- Characters are single bytes
- String literals use single or double quotes
- Single-quoted string literals (as in Perl)
- Embedded variables are NOT interpolated
- Embedded escape sequences are NOT recognized
- Double-quoted string literals (as in Perl)
- Embedded variables ARE interpolated
- Boolean - values are true and false (case insensitive)
- 0 and "" and "0" are false; others are true
Operators
As in 'C' language e.g.+, -, *, /, % String Functions strlen, strcmp, strpos, substr, as in C
chop – remove whitespace from the right end
trim – remove whitespace from both ends
ltrim – remove whitespace from the left end
strtolower, strtoupper
Type Conversion
$a = (int)$b; intval($total) settype($total, "integer") The type of a variable can be determined
with gettype or is_type
gettype($total) - it may return"unknown"
is_integer($total) – a predicate function
- echo/print/prinf used for print
Control StatementsControl Expressions
- Relational operators - same as JavaScript,
(including === and !==)
- Boolean operators - same as Perl (two sets, &&
and and, etc.)
- Selection statements
- if, if-else, elseif
- switch - as in C
- The switch expression type must be integer,
double, or string
- while - just like C
- do-while - just like C
- for - just like C
-foreach (array_expression as $value)
statement
foreach (array_expression as $key => $value)
statement
- break - in any for, foreach, while, do-while, or
switch
- continue - in any loop
- Alternative compound delimiters – more readability
if(...):
...
endif;
Arrays An array in PHP is an ordered map. A map is a type that associates values to keys. list (vector), hash table (an implementation of a
map), dictionary, collection, stack, queue,etc. $arr = array(1, 2, 3, 4, 5);//simple list Can be accessed with foreach foreach ($arr as $i){
echo $i; }
$arr = array(5 => 1, 12 => 2);//hash list
foreach ($arr as $key => $value) {
$colors[$key] = strtoupper($value);
} Sorting an array
sort($arr);
print_r($arr);
Sorting Arrays
rsort - To sort the values of an array into reverse order
- ksort - To sort the elements of an array by the keys, maintaining the key/value relationships
e.g.,
$list("Fred" => 17, "Mary" => 21, "Bob" => 49, "Jill" => 28);
ksort($list);
// $list is now ("Bob" => 49, "Fred" => 17, "Jill" => 28, "Mary" => 21)
- krsort
- To sort the elements of an array by the keys into reverse order
User Defined Functions
Syntactic form:
function function_name(formal_parameters) {
… }
- General Characteristics
- Functions need not be defined before they are called (in PHP 3, they must)
- Function overloading is not supported
- If you try to redefine a function, it is an error
- Functions can have a variable number of parameters
- Default parameter values are supported
- Function definitions can be nested
- Function names are NOT case sensitive
- The return function is used to return a value;
If there is no return, there is no returned value
Example
<?php
$sum=add(15,20);
echo "sum : $sum <br>\n";
function add($no1,$no2)
{
return ($no1+$no2);
}
?>
Form Handling
$_GET and $_POST variables $_GET[“varname”]; $_POST[“varname”];
References[1] Tim Berners-Lee, “The World Wide Web: A very
short personal history”, http://www.w3.org/People/Berners-Lee/ShortHistory.html
[2] PHP manual, http://php.net/manual/en/index.php
[3] http://tinman.cs.gsu.edu/~raj/4998/sp06/mysql-php/w3_c12.ppt
Top Related