Internet Technology & its Applications Prof. Ami Tusharkant Choksi CKPCET, 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 ( P re  H ypertext  P rocessor, Java Servlet,  J ava  S erver  P ages,  C ommon  G ateway  I nterface/perl,  A ctive  S erver   P ages, JScipt/JavaScript, VBScript, e X tensible  M arkup  L anguage )
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
P re  H ypertext  P rocessor 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 &quot;UserDir disabled&quot; 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  &quot;&quot;  and  &quot; 0 &quot;  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,  &quot; integer &quot; ) The type of a variable can be determined with gettype or is_type gettype($total)  - it may return &quot; unknown &quot; is_integer($total) – a predicate function - echo/print/prinf used for print
Control Statements Control 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(&quot;Fred&quot; => 17, &quot;Mary&quot; => 21, &quot;Bob&quot; => 49, &quot;Jill&quot; => 28); ksort($list); // $list is now (&quot;Bob&quot; => 49, &quot;Fred&quot; => 17, &quot;Jill&quot; => 28, &quot;Mary&quot; => 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 &quot;sum : $sum <br>\n&quot;; 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

Internet Technology and its Applications

  • 1.
    Internet Technology &its Applications Prof. Ami Tusharkant Choksi CKPCET, Surat.
  • 2.
    What is InternetTechnology? 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)
  • 3.
    Applications integration ofe-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
  • 4.
    History of WorldWide 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
  • 5.
    Requirements To runWWW 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 ( P re H ypertext P rocessor, Java Servlet, J ava S erver P ages, C ommon G ateway I nterface/perl, A ctive S erver P ages, JScipt/JavaScript, VBScript, e X tensible M arkup L anguage )
  • 6.
    What's server sideand client side progg. Languages? Programs which runs on server is called server side progg . Programs which runs on client is called client side progg .
  • 7.
    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
  • 8.
    P re H ypertext P rocessor 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
  • 9.
    Simple PHP Program(first.php) <html> <body> <?php echo “hi and welcome to the world of PHP”; phpinfo(); ?> </body> </html>
  • 10.
  • 11.
    /etc/httpd/conf/httpd.conf #Use forPHP 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>
  • 12.
    /etc/httpd/conf/httpd.conf If withuser'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 &quot;UserDir disabled&quot; line above, and uncomment the following line instead: UserDir public_html </IfModule>
  • 13.
    /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>
  • 14.
    Deploy program onwebserver 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
  • 15.
    If u haveroot 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
  • 16.
    Comments in PHP// this is a comment # shell script like comment /* C and java-like comments */
  • 17.
    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
  • 18.
    There are eightprimitive 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
  • 19.
    - Single-quotedstring 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 &quot;&quot; and &quot; 0 &quot; are false; others are true
  • 20.
    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
  • 21.
    Type Conversion $a= (int)$b; intval($total) settype($total, &quot; integer &quot; ) The type of a variable can be determined with gettype or is_type gettype($total) - it may return &quot; unknown &quot; is_integer($total) – a predicate function - echo/print/prinf used for print
  • 22.
    Control Statements ControlExpressions - 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
  • 23.
    -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;
  • 24.
    Arrays An arrayin 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; }
  • 25.
    $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);
  • 26.
    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(&quot;Fred&quot; => 17, &quot;Mary&quot; => 21, &quot;Bob&quot; => 49, &quot;Jill&quot; => 28); ksort($list); // $list is now (&quot;Bob&quot; => 49, &quot;Fred&quot; => 17, &quot;Jill&quot; => 28, &quot;Mary&quot; => 21) - krsort - To sort the elements of an array by the keys into reverse order
  • 27.
    User Defined FunctionsSyntactic 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
  • 28.
    Example <?php $sum=add(15,20);echo &quot;sum : $sum <br>\n&quot;; function add($no1,$no2) { return ($no1+$no2); } ?>
  • 29.
    Form Handling $_GETand $_POST variables $_GET[“varname”]; $_POST[“varname”];
  • 30.
    References [1] TimBerners-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