SlideShare a Scribd company logo
1 of 39
CHAPTER 1.
INTRODUCTION TO
WEB TECHNIQUES
Prepared By- Mrs. Shital V. Ghotekar
Asst. Prof.
Computer Science Department
MAEER’S MIT Art's, Commerce & Science College, Alandi(D), Pune
Contents
 HTTP Basics
 Variables
 Server Information
 Processing Forms
 Setting Response Header
 Maintaining State
 PHP Error Handling
HTTP Basics
 This protocol governs how web browsers request files from web servers and how the servers
send the files back.
 When a web browser requests a web page, it sends an HTTP request message to a web server.
 The request message always includes some header information, and it sometimes also includes
a body.
 The first line of an HTTP request looks like this:
 GET /index.html HTTP/1.1
 This line specifies an HTTP command, called a method , followed by the address of a
document and the version of the HTTP protocol being used.
 In this case, the request is using the GET method to ask for the index.html document using
HTTP 1.1
HTTP Basics
 After this initial line, the request can contain optional header information that gives the server
additional data about the request.
 For example:
 User-Agent: Mozilla/5.0 (Windows 2000; U) Opera 6.0 [en]
 Accept: image/gif, image/jpeg, text/*, */*
 The User-Agent header provides information about the web browser, while the Accept header
specifies the MIME types that the browser accepts.
HTTP Basics
 The web server responds with a reply message, which always includes header information and
usually contains a body.
 The web server receives the request, processes it, and sends a response.
 The first line of an HTTP response looks like this:
 HTTP/1.1 200 OK
 This line specifies the protocol version, a status code, and a description of that code.
 In this case, the status code is "200", meaning that the request was successful (hence the
description "OK").
HTTP Basics
 There are three basic features that make HTTP a simple but powerful protocol:
• HTTP is connectionless: The HTTP client, i.e., a browser initiates an HTTP request and after a
request is made, the client waits for the response. The server processes the request and sends a
response back after which client disconnect the connection. So client and server knows about
each other during current request and response only. Further requests are made on new
connection like client and server are new to each other.
• HTTP is media independent: It means, any type of data can be sent by HTTP as long as both
the client and the server know how to handle the data content. It is required for the client as
well as the server to specify the content type using appropriate MIME-type.
• HTTP is stateless: As mentioned above, HTTP is connectionless and it is a direct result of
HTTP being a stateless protocol. The server and client are aware of each other only during a
current request. Afterwards, both of them forget about each other. Due to this nature of the
protocol, neither the client nor the browser can retain information between different requests
across the web pages.
HTTP Methods
 The two most common HTTP methods are GET and POST.
 The GET method is designed for retrieving information, such as a document, an image, or the
results of a database query, from the server.
 The POST method is meant for posting information, such as a credit-card number or
information that is to be stored in a database, to the server.
 The GET method is what a web browser uses when the user types in a URL or clicks on a link.
 When the user submits a form, either the GET or POST method can be used, as specified by the
method attribute of the form tag.
Variables
 Server configuration and request information—including form parameters and cookies—are
accessible in three different ways from your PHP scripts.
 Collectively, this information is referred to as EGPCS (environment, GET, POST, cookies, and
server).
 If the register_globals option in php.ini is enabled, PHP creates a separate global variable for every
form parameter, every piece of request information, and every server configuration value.
 PHP creates six global arrays that contain the EGPCS information.
 The global arrays are:
 $HTTP_COOKIE_VARS ($_COOKIE) Contains any cookie values passed as part of the request,
where the keys of the array are the names of the cookies.
 $HTTP_GET_VARS ($_GET)Contains any parameters that are part of a GET request, where the
keys of the array are the names of the form parameters.
 $HTTP_POST_VARS ($_POST) Contains any parameters that are part of a POST request, where
the keys of the array are the names of the form parameters.
Variables
 $HTTP_POST_FILES ($_FILES ) Contains information about any uploaded files.
 $HTTP_SERVER_VARS ($_SERVER) Contains useful information about the web server.
 $HTTP_ENV_VARS ($_ENV) Contains the values of any environment variables, where the
keys of the array are the names of the environment variables.
 PHP provides shorter aliases: $_COOKIE, $_GET, $_POST, $_FILES, $_SERVER, and
$_ENV.
 These short variables are the recommended way to access EGPCS values.
 The $_REQUEST array is also created by PHP if the register_globals option is on; however,
there is no corresponding $HTTP_REQUEST_VARS array. The $_REQUEST array contains
the elements of the $_GET, $_POST, and $_COOKIE arrays.
 PHP also creates a variable called $PHP_SELF, which holds the name of the current script,
relative to the document root (e.g., /store/cart.php). This value is also accessible as
$_SERVER['PHP_SELF']. This variable is useful when creating self-referencing scripts.
Server Information
 The $_SERVER array contains a lot of useful information from the web server.
 SERVER_SOFTWARE A string that identifies the server (e.g., "Apache/1.3.22 (Unix)
mod_perl/1.26 PHP/4.1.0").
 SERVER_NAME The hostname, DNS alias, or IP address for self-referencing URLs (e.g.,
"www.example.com").
 GATEWAY_INTERFACE The version of the CGI standard being followed (e.g., "CGI/1.1").
 SERVER_PROTOCOL The name and revision of the request protocol (e.g., "HTTP/1.1").
 SERVER_PORT The server port number to which the request was sent (e.g., "80").
 REQUEST_METHOD The method the client used to fetch the document (e.g., "GET").
 PATH_INFO Extra path elements given by the client (e.g., "/list/users").
 PATH_TRANSLATED The value of PATH_INFO, translated by the server into a filename
(e.g., "/home/httpd/htdocs/list/users").
Server Information
 SCRIPT_NAME The URL path to the current page, which is useful for self-referencing scripts
(e.g., "/~me/menu.php").
 QUERY_STRING Everything after the ? in the URL (e.g., "name=Fred+age=35").
 REMOTE_HOST The hostname of the machine that requested this page (e.g., "dialup-192-
168-0-1.example.com"). If there's no DNS for the machine, this is blank and REMOTE_ADDR
is the only information given.
 REMOTE_ADDR A string containing the IP address of the machine that requested this page
(e.g., "192.168.0.250").
 AUTH_TYPE If the page is password-protected, this is the authentication method used to
protect the page (e.g., "basic").
 REMOTE_USER If the page is password-protected, this is the username with which the client
authenticated (e.g., "fred"). Note that there's no way to find out what password was used.
Server Information
 The two most common and useful headers are: HTTP_USER_AGENT The string the browser
used to identify itself (e.g., "Mozilla/5.0 (Windows 2000; U) Opera 6.0 [en]")
 HTTP_REFERER The page the browser said it came from to get to the current page (e.g.,
"http://www.example.com/last_page.html")
Processing Forms
 There are two HTTP methods that a client can use to pass form data to the server: GET and
POST.
 Parameters-
 Use the $_POST , $_GET, and $_FILES arrays to access form parameters from your PHP
code.
 Example-
 Design HTML Page to accept username & password.
 Write PHP script to display it in as an output.
Processing Forms
 The $ _FILES array contains following properties −
 $_FILES['file']['name'] - The original name of the file to be uploaded.
 $_FILES['file']['type'] - The mime type of the file.
 $_FILES['file']['size'] - The size, in bytes, of the uploaded file.
 $_FILES['file']['tmp_name'] - The temporary filename of the file in which the uploaded
file was stored on the server.
 $_FILES['file']['error'] - The error code associated with this file upload.
The enctype attribute specifies how the form-data should be encoded when submitting it to the server.
Note: The enctype attribute can be used only if method="post"
Setting Response Header
PHP Error Handling
 An error is a unwanted result of program.
 Error is a type of mistake.
 An error can also be defined as generate wrong output of program caused by a fault.
 An error message display with error message, filename and line number.
 An error can be categorized in :
• Syntax Error
• Logical Error
• Run-time Error
PHP Error Handling
 In PHP there are four types of errors.
• Notice Error
• Fatal Error
• Waring Error
• Parse Error
 PHP – Notice Error
 Notice error occurs when we use a variable in program which is not defined then it produce
notice error.
 Notice error code execution of script does not stop.
PHP – Notice Error
 <?php
 for($i=1;$i<=10;$i++)
 {
 $series=$series. " ".$i;
 }
 echo "The No = ".$series;
 ?>
 Output-
 Notice: Undefined variable: series in
/var/www/html/Sem-2/isset.php on line 29
The No = 1 2 3 4 5 6 7 8 9 10
 In the given example we use $series variable
but it is not defined, so it will produce notice
error but the execution of script does not stop.
PHP – Notice Error
 <?php
 $a=5;
 echo “The result = ” . $b;
 ?>
 Output-
 In this example we declare a variable $a, but
we use another variable $b in program which
is not defined, so it will also generate notice
error like below.
 Notice: Undefined variable: b in
/var/www/html/Sem-2/isset.php on line 3
 Fatal error is critical error and it is stop the
execution of script immediately.
Fatal error occurs when we call undefined
functions or class.
 Ex-
 <?php
 function sum()
 { $sum=5+6;
 echo "The sum= ".$sum; }
 mul();
 ?>
 Output-
 In the given example we declined “sum()”
function but in program we call “mul()”
function which is not defined in program, so
it will produce fatal error and stop the
execution of script.so it will also generate
notice error like below.
 Fatal Error: Call to undefined function mul( )
in /var/www/html/Sem-2/isset.php on line 7
PHP – Fatal Error
 A warning error does not stop the execution
of script. warning error not a critical error.
 A warning error occurs when we pass wrong
parameter in function or we include external
file using include() function but the file
doesn’t exist then display warning error.
 Warning Error Example-
 <?php
 include("wrongfile.php");
 $sum=5+6;
 echo "".$sum;
 ?>
 Output-
 Warning:include(wrongfilr.php):failed to
open stream:No such file or directory in
/var/www/html/Sem-2/isset.php on line 3
 The sum=11
PHP – Warning Error
 A Parse error occurs if there is a mistake in a
syntax.
 When parse error occurs the execution of
script will be terminated.
 Parse Error Example
 <?php
 $a=10
 echo "The A = ".$a;
 ?>
 Output-
 Parse error : syntax error , unexpected
‘echo’(T_ECHO) in /var/www/html/Sem-
2/isset.php on line 5
PHP – Parse Error
Error Handling
 Error handling is the process of catching errors raised by your program and then taking
appropriate action.
 Ways to handle PHP Errors:
• Using die() method
• Custom Error Handling and error triggers
• Error reporting
Error Handling
 <?php
 // Php code showing default error handling
 $file = fopen(“demo.txt", "w");
 ?>
 Runtime Error: (demo.txt file not present)
 PHP Warning: fopen(demo.txt): failed to open stream: Permission denied in /var/www/html/isset.php on line 2
 To prevent /avoid this error use die() function.
 The die() function print a message and exit from current script.
 It is equivalent to exit() function in PHP.
 Syntax:
 die( $message )
Error Handling
 Example-
 <?php
 if( !file_exists(“demo.txt") ) {
 die("File is not present");
 }
 else {
 $file = fopen(“demo.txt", "w");
 }
 ?>
 Note: If demo.txt file not present then it will display output.
 Output : File is not present
Error Handling
 Custom Error handling:
 Creating a custom error handler is quite simple.
 Create a special function that can be called when an error occurs in PHP.
 This function must be able to handle a minimum of two parameters (error level and error message) but
 can accept up to five parameters
 Syntax:
 error_function( $error_level, $error_message, $error_file, $error_line, $error_context)
 $error_level: It is required parameter and it must be an integer. There are predefined error levels.
 $error_message: It is required parameter and it is the message which user want to print.
 $error_file: It is optional parameter and used to specify the file in which error has been occurred.
 $error_line: It is optional parameter and used to specify the line number in which error has been occurred.
 $error_context: It is optional parameter and used to specify an array containing every variable and their value
when error has been occurred.
Error Handling
 error_level: These are the possible error level which are listed below:
• 1 : .E_ERROR :fatal runtime error execution of script has been halted
• 2 : E_WARNING :non fatal runtime error execution of script has been halted
• 4 : E_PARSE :compile time error it is generated by the parser
• 8 :E_NOTICE :The script found something that might be an error
• 16 :E_CORE_ERROR :Fatal errors that occurred during initial startup of script
• 32 :E_CORE_WARNING :Non fatal errors that occurred during initial startup of script
• 8191 :E_ALL :All errors and warning
Error Handling
 CUSTOM FUNCTION
 function customError($errno, $errstr)
 {
 echo "<b>Error:</b> [$errno] $errstr<br>";
 echo "Ending Script";
 die();
 }
 The code above is a simple error handling function.
 When it is triggered, it gets the error level and an error
 message. It then outputs the error level and message
 and terminates the script.
Error Handling
 SET ERROR HANDLER
 Since we want our custom function to handle all errors, the set_error_handler() only
needed one
 parameter, a second parameter could be added to specify an error level.
 set_error_handler("customError");
EXAMPLE
<?php
//error handler function
function customError($errno, $errstr)
{
echo "<b>Error:</b> [$errno] $errstr";
}
//set error handler
set_error_handler("customError");
//trigger error
echo($test);
?>
 OUTPUT - Error: [8] Undefined variable: test
Error Handling
<?php
function myerror($error_no, $error_msg) {
echo "Error: [$error_no] $error_msg ";
echo "n Now Script will end"; // When error occurred script has to be stopped
die();
}
set_error_handler("myerror");
$a = 10;
$b = 0;
// This will generate error
echo($a / $b);
?> Output : Error: [2] Division by zero
Now Script will end
Trigger An Error
 In a script where users can input data it is useful to trigger errors when an illegal input occurs.
 In PHP, this is done by the trigger_error() function.
<?php
$test=2;
if ($test>=1)
{
trigger_error("Value must be 1 or below");
}
?>
OUTPUT
Notice: Value must be 1 or below in /var/www/html/Sem-2/error.php on line 6
ERROR TYPES
 E_USER_ERROR - Fatal user-generated run-time error. Errors that can not be recovered from.
 Execution of the script is halted
 E_USER_WARNING - Non-fatal user-generated run-time warning. Execution of the script is
not Halted.
 E_USER_NOTICE - Default. User-generated run- time notice. The script found something that
might be an error, but could also happen when running a script normally
EXAMPLE
 <?php
 //error handler function
 function customError($errno, $errstr)
 {
 echo "<b>Error:</b> [$errno] $errstr<br>";
 echo "Ending Script";
 die();
 }
 //set error handler
 set_error_handler("customError",E_USER_WARNIN
G);
 //trigger error
 $test=2;
 if ($test>=1)
 {
 trigger_error("Value must be 1 or
below",E_USER_WARNING);
 }
 ?>
 EXPLANATION
 E_USER_WARNING occurs if the "test" variable is bigger than "1".
 If an E_USER_WARNING occurs we will use our custom error handler and
end the script:
 OUTPUT-
 Error: [512] Value must be 1 or below
 Ending Script
ERROR LOG
 By default, PHP sends an error log to the server’s logging system or a file, depending
on how the error_log configuration is set in the php.ini file.
 By using the error_log() function you can send error logs to a specified file or a remote
destination.
 Sending error messages to yourself by e-mail can be a good way of getting notified of
specific errors.
EXAMPLE
 <?php
 //error handler function
 function customError($errno, $errstr)
 {
 echo "<b>Error:</b> [$errno] $errstr<br>";
 echo "Webmaster has been notified";
 error_log("Error: [$errno] $errstr",1,
 "svghotekar@gamil.com","From:
vaibhavghotekar@gmail.com");
 }
 //set error handler
 set_error_handler("customError",E_USER_
WARNING);
 //trigger error
 $test=2;
 if ($test>=1)
 {
 trigger_error("Value must be 1 or
below",E_USER_WARNING);
 }
 ?>
 OUTPUT
 Error: [512] Value must be 1 or below Vaibhavghotekar has been notified
 And the mail received from the code above looks like this:
 Error: [512] Value must be 1 or below

More Related Content

Similar to Chapter 1.Web Techniques_Notes.pptx

Http request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.NHttp request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.N
Navaneethan Naveen
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
Cathie101
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
Cathie101
 
Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014
Navaneethan Naveen
 

Similar to Chapter 1.Web Techniques_Notes.pptx (20)

Http request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.NHttp request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.N
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 
Spider Course Day 1
Spider Course Day 1Spider Course Day 1
Spider Course Day 1
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
HTTPProtocol HTTPProtocol.pptHTTPProtocol.ppt
HTTPProtocol HTTPProtocol.pptHTTPProtocol.pptHTTPProtocol HTTPProtocol.pptHTTPProtocol.ppt
HTTPProtocol HTTPProtocol.pptHTTPProtocol.ppt
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
PHP Training: Module 1
PHP Training: Module 1PHP Training: Module 1
PHP Training: Module 1
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
HTTP Basics Demo
HTTP Basics DemoHTTP Basics Demo
HTTP Basics Demo
 
Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014
 
API Basics
API BasicsAPI Basics
API Basics
 
introduction_php.ppt
introduction_php.pptintroduction_php.ppt
introduction_php.ppt
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
 
www and http services
www and http serviceswww and http services
www and http services
 
Ch2 the application layer protocols_http_3
Ch2 the application layer protocols_http_3Ch2 the application layer protocols_http_3
Ch2 the application layer protocols_http_3
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 

Recently uploaded

Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
levieagacer
 
PODOCARPUS...........................pptx
PODOCARPUS...........................pptxPODOCARPUS...........................pptx
PODOCARPUS...........................pptx
Cherry
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Sérgio Sacani
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
seri bangash
 
Human genetics..........................pptx
Human genetics..........................pptxHuman genetics..........................pptx
Human genetics..........................pptx
Cherry
 
LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.
Cherry
 
POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.
Cherry
 

Recently uploaded (20)

Call Girls Ahmedabad +917728919243 call me Independent Escort Service
Call Girls Ahmedabad +917728919243 call me Independent Escort ServiceCall Girls Ahmedabad +917728919243 call me Independent Escort Service
Call Girls Ahmedabad +917728919243 call me Independent Escort Service
 
Dr. E. Muralinath_ Blood indices_clinical aspects
Dr. E. Muralinath_ Blood indices_clinical  aspectsDr. E. Muralinath_ Blood indices_clinical  aspects
Dr. E. Muralinath_ Blood indices_clinical aspects
 
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIACURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
 
Use of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxUse of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptx
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptx
 
Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
 
PODOCARPUS...........................pptx
PODOCARPUS...........................pptxPODOCARPUS...........................pptx
PODOCARPUS...........................pptx
 
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRLGwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
Gwalior ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Gwalior ESCORT SERVICE❤CALL GIRL
 
Cot curve, melting temperature, unique and repetitive DNA
Cot curve, melting temperature, unique and repetitive DNACot curve, melting temperature, unique and repetitive DNA
Cot curve, melting temperature, unique and repetitive DNA
 
Site Acceptance Test .
Site Acceptance Test                    .Site Acceptance Test                    .
Site Acceptance Test .
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
 
Concept of gene and Complementation test.pdf
Concept of gene and Complementation test.pdfConcept of gene and Complementation test.pdf
Concept of gene and Complementation test.pdf
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
 
Human genetics..........................pptx
Human genetics..........................pptxHuman genetics..........................pptx
Human genetics..........................pptx
 
LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.LUNULARIA -features, morphology, anatomy ,reproduction etc.
LUNULARIA -features, morphology, anatomy ,reproduction etc.
 
POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.
 
Genome organization in virus,bacteria and eukaryotes.pptx
Genome organization in virus,bacteria and eukaryotes.pptxGenome organization in virus,bacteria and eukaryotes.pptx
Genome organization in virus,bacteria and eukaryotes.pptx
 
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICEPATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
 
Selaginella: features, morphology ,anatomy and reproduction.
Selaginella: features, morphology ,anatomy and reproduction.Selaginella: features, morphology ,anatomy and reproduction.
Selaginella: features, morphology ,anatomy and reproduction.
 

Chapter 1.Web Techniques_Notes.pptx

  • 1. CHAPTER 1. INTRODUCTION TO WEB TECHNIQUES Prepared By- Mrs. Shital V. Ghotekar Asst. Prof. Computer Science Department MAEER’S MIT Art's, Commerce & Science College, Alandi(D), Pune
  • 2. Contents  HTTP Basics  Variables  Server Information  Processing Forms  Setting Response Header  Maintaining State  PHP Error Handling
  • 3. HTTP Basics  This protocol governs how web browsers request files from web servers and how the servers send the files back.  When a web browser requests a web page, it sends an HTTP request message to a web server.  The request message always includes some header information, and it sometimes also includes a body.  The first line of an HTTP request looks like this:  GET /index.html HTTP/1.1  This line specifies an HTTP command, called a method , followed by the address of a document and the version of the HTTP protocol being used.  In this case, the request is using the GET method to ask for the index.html document using HTTP 1.1
  • 4. HTTP Basics  After this initial line, the request can contain optional header information that gives the server additional data about the request.  For example:  User-Agent: Mozilla/5.0 (Windows 2000; U) Opera 6.0 [en]  Accept: image/gif, image/jpeg, text/*, */*  The User-Agent header provides information about the web browser, while the Accept header specifies the MIME types that the browser accepts.
  • 5. HTTP Basics  The web server responds with a reply message, which always includes header information and usually contains a body.  The web server receives the request, processes it, and sends a response.  The first line of an HTTP response looks like this:  HTTP/1.1 200 OK  This line specifies the protocol version, a status code, and a description of that code.  In this case, the status code is "200", meaning that the request was successful (hence the description "OK").
  • 6. HTTP Basics  There are three basic features that make HTTP a simple but powerful protocol: • HTTP is connectionless: The HTTP client, i.e., a browser initiates an HTTP request and after a request is made, the client waits for the response. The server processes the request and sends a response back after which client disconnect the connection. So client and server knows about each other during current request and response only. Further requests are made on new connection like client and server are new to each other. • HTTP is media independent: It means, any type of data can be sent by HTTP as long as both the client and the server know how to handle the data content. It is required for the client as well as the server to specify the content type using appropriate MIME-type. • HTTP is stateless: As mentioned above, HTTP is connectionless and it is a direct result of HTTP being a stateless protocol. The server and client are aware of each other only during a current request. Afterwards, both of them forget about each other. Due to this nature of the protocol, neither the client nor the browser can retain information between different requests across the web pages.
  • 7. HTTP Methods  The two most common HTTP methods are GET and POST.  The GET method is designed for retrieving information, such as a document, an image, or the results of a database query, from the server.  The POST method is meant for posting information, such as a credit-card number or information that is to be stored in a database, to the server.  The GET method is what a web browser uses when the user types in a URL or clicks on a link.  When the user submits a form, either the GET or POST method can be used, as specified by the method attribute of the form tag.
  • 8. Variables  Server configuration and request information—including form parameters and cookies—are accessible in three different ways from your PHP scripts.  Collectively, this information is referred to as EGPCS (environment, GET, POST, cookies, and server).  If the register_globals option in php.ini is enabled, PHP creates a separate global variable for every form parameter, every piece of request information, and every server configuration value.  PHP creates six global arrays that contain the EGPCS information.  The global arrays are:  $HTTP_COOKIE_VARS ($_COOKIE) Contains any cookie values passed as part of the request, where the keys of the array are the names of the cookies.  $HTTP_GET_VARS ($_GET)Contains any parameters that are part of a GET request, where the keys of the array are the names of the form parameters.  $HTTP_POST_VARS ($_POST) Contains any parameters that are part of a POST request, where the keys of the array are the names of the form parameters.
  • 9. Variables  $HTTP_POST_FILES ($_FILES ) Contains information about any uploaded files.  $HTTP_SERVER_VARS ($_SERVER) Contains useful information about the web server.  $HTTP_ENV_VARS ($_ENV) Contains the values of any environment variables, where the keys of the array are the names of the environment variables.  PHP provides shorter aliases: $_COOKIE, $_GET, $_POST, $_FILES, $_SERVER, and $_ENV.  These short variables are the recommended way to access EGPCS values.  The $_REQUEST array is also created by PHP if the register_globals option is on; however, there is no corresponding $HTTP_REQUEST_VARS array. The $_REQUEST array contains the elements of the $_GET, $_POST, and $_COOKIE arrays.  PHP also creates a variable called $PHP_SELF, which holds the name of the current script, relative to the document root (e.g., /store/cart.php). This value is also accessible as $_SERVER['PHP_SELF']. This variable is useful when creating self-referencing scripts.
  • 10. Server Information  The $_SERVER array contains a lot of useful information from the web server.  SERVER_SOFTWARE A string that identifies the server (e.g., "Apache/1.3.22 (Unix) mod_perl/1.26 PHP/4.1.0").  SERVER_NAME The hostname, DNS alias, or IP address for self-referencing URLs (e.g., "www.example.com").  GATEWAY_INTERFACE The version of the CGI standard being followed (e.g., "CGI/1.1").  SERVER_PROTOCOL The name and revision of the request protocol (e.g., "HTTP/1.1").  SERVER_PORT The server port number to which the request was sent (e.g., "80").  REQUEST_METHOD The method the client used to fetch the document (e.g., "GET").  PATH_INFO Extra path elements given by the client (e.g., "/list/users").  PATH_TRANSLATED The value of PATH_INFO, translated by the server into a filename (e.g., "/home/httpd/htdocs/list/users").
  • 11. Server Information  SCRIPT_NAME The URL path to the current page, which is useful for self-referencing scripts (e.g., "/~me/menu.php").  QUERY_STRING Everything after the ? in the URL (e.g., "name=Fred+age=35").  REMOTE_HOST The hostname of the machine that requested this page (e.g., "dialup-192- 168-0-1.example.com"). If there's no DNS for the machine, this is blank and REMOTE_ADDR is the only information given.  REMOTE_ADDR A string containing the IP address of the machine that requested this page (e.g., "192.168.0.250").  AUTH_TYPE If the page is password-protected, this is the authentication method used to protect the page (e.g., "basic").  REMOTE_USER If the page is password-protected, this is the username with which the client authenticated (e.g., "fred"). Note that there's no way to find out what password was used.
  • 12. Server Information  The two most common and useful headers are: HTTP_USER_AGENT The string the browser used to identify itself (e.g., "Mozilla/5.0 (Windows 2000; U) Opera 6.0 [en]")  HTTP_REFERER The page the browser said it came from to get to the current page (e.g., "http://www.example.com/last_page.html")
  • 13. Processing Forms  There are two HTTP methods that a client can use to pass form data to the server: GET and POST.  Parameters-  Use the $_POST , $_GET, and $_FILES arrays to access form parameters from your PHP code.  Example-  Design HTML Page to accept username & password.  Write PHP script to display it in as an output.
  • 14. Processing Forms  The $ _FILES array contains following properties −  $_FILES['file']['name'] - The original name of the file to be uploaded.  $_FILES['file']['type'] - The mime type of the file.  $_FILES['file']['size'] - The size, in bytes, of the uploaded file.  $_FILES['file']['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.  $_FILES['file']['error'] - The error code associated with this file upload.
  • 15. The enctype attribute specifies how the form-data should be encoded when submitting it to the server. Note: The enctype attribute can be used only if method="post"
  • 17. PHP Error Handling  An error is a unwanted result of program.  Error is a type of mistake.  An error can also be defined as generate wrong output of program caused by a fault.  An error message display with error message, filename and line number.  An error can be categorized in : • Syntax Error • Logical Error • Run-time Error
  • 18. PHP Error Handling  In PHP there are four types of errors. • Notice Error • Fatal Error • Waring Error • Parse Error  PHP – Notice Error  Notice error occurs when we use a variable in program which is not defined then it produce notice error.  Notice error code execution of script does not stop.
  • 19. PHP – Notice Error  <?php  for($i=1;$i<=10;$i++)  {  $series=$series. " ".$i;  }  echo "The No = ".$series;  ?>  Output-  Notice: Undefined variable: series in /var/www/html/Sem-2/isset.php on line 29 The No = 1 2 3 4 5 6 7 8 9 10  In the given example we use $series variable but it is not defined, so it will produce notice error but the execution of script does not stop.
  • 20. PHP – Notice Error  <?php  $a=5;  echo “The result = ” . $b;  ?>  Output-  In this example we declare a variable $a, but we use another variable $b in program which is not defined, so it will also generate notice error like below.  Notice: Undefined variable: b in /var/www/html/Sem-2/isset.php on line 3
  • 21.  Fatal error is critical error and it is stop the execution of script immediately. Fatal error occurs when we call undefined functions or class.  Ex-  <?php  function sum()  { $sum=5+6;  echo "The sum= ".$sum; }  mul();  ?>  Output-  In the given example we declined “sum()” function but in program we call “mul()” function which is not defined in program, so it will produce fatal error and stop the execution of script.so it will also generate notice error like below.  Fatal Error: Call to undefined function mul( ) in /var/www/html/Sem-2/isset.php on line 7 PHP – Fatal Error
  • 22.  A warning error does not stop the execution of script. warning error not a critical error.  A warning error occurs when we pass wrong parameter in function or we include external file using include() function but the file doesn’t exist then display warning error.  Warning Error Example-  <?php  include("wrongfile.php");  $sum=5+6;  echo "".$sum;  ?>  Output-  Warning:include(wrongfilr.php):failed to open stream:No such file or directory in /var/www/html/Sem-2/isset.php on line 3  The sum=11 PHP – Warning Error
  • 23.  A Parse error occurs if there is a mistake in a syntax.  When parse error occurs the execution of script will be terminated.  Parse Error Example  <?php  $a=10  echo "The A = ".$a;  ?>  Output-  Parse error : syntax error , unexpected ‘echo’(T_ECHO) in /var/www/html/Sem- 2/isset.php on line 5 PHP – Parse Error
  • 24. Error Handling  Error handling is the process of catching errors raised by your program and then taking appropriate action.  Ways to handle PHP Errors: • Using die() method • Custom Error Handling and error triggers • Error reporting
  • 25. Error Handling  <?php  // Php code showing default error handling  $file = fopen(“demo.txt", "w");  ?>  Runtime Error: (demo.txt file not present)  PHP Warning: fopen(demo.txt): failed to open stream: Permission denied in /var/www/html/isset.php on line 2  To prevent /avoid this error use die() function.  The die() function print a message and exit from current script.  It is equivalent to exit() function in PHP.  Syntax:  die( $message )
  • 26. Error Handling  Example-  <?php  if( !file_exists(“demo.txt") ) {  die("File is not present");  }  else {  $file = fopen(“demo.txt", "w");  }  ?>  Note: If demo.txt file not present then it will display output.  Output : File is not present
  • 27. Error Handling  Custom Error handling:  Creating a custom error handler is quite simple.  Create a special function that can be called when an error occurs in PHP.  This function must be able to handle a minimum of two parameters (error level and error message) but  can accept up to five parameters  Syntax:  error_function( $error_level, $error_message, $error_file, $error_line, $error_context)  $error_level: It is required parameter and it must be an integer. There are predefined error levels.  $error_message: It is required parameter and it is the message which user want to print.  $error_file: It is optional parameter and used to specify the file in which error has been occurred.  $error_line: It is optional parameter and used to specify the line number in which error has been occurred.  $error_context: It is optional parameter and used to specify an array containing every variable and their value when error has been occurred.
  • 28. Error Handling  error_level: These are the possible error level which are listed below: • 1 : .E_ERROR :fatal runtime error execution of script has been halted • 2 : E_WARNING :non fatal runtime error execution of script has been halted • 4 : E_PARSE :compile time error it is generated by the parser • 8 :E_NOTICE :The script found something that might be an error • 16 :E_CORE_ERROR :Fatal errors that occurred during initial startup of script • 32 :E_CORE_WARNING :Non fatal errors that occurred during initial startup of script • 8191 :E_ALL :All errors and warning
  • 29. Error Handling  CUSTOM FUNCTION  function customError($errno, $errstr)  {  echo "<b>Error:</b> [$errno] $errstr<br>";  echo "Ending Script";  die();  }  The code above is a simple error handling function.  When it is triggered, it gets the error level and an error  message. It then outputs the error level and message  and terminates the script.
  • 30. Error Handling  SET ERROR HANDLER  Since we want our custom function to handle all errors, the set_error_handler() only needed one  parameter, a second parameter could be added to specify an error level.  set_error_handler("customError");
  • 31. EXAMPLE <?php //error handler function function customError($errno, $errstr) { echo "<b>Error:</b> [$errno] $errstr"; } //set error handler set_error_handler("customError"); //trigger error echo($test); ?>  OUTPUT - Error: [8] Undefined variable: test
  • 32. Error Handling <?php function myerror($error_no, $error_msg) { echo "Error: [$error_no] $error_msg "; echo "n Now Script will end"; // When error occurred script has to be stopped die(); } set_error_handler("myerror"); $a = 10; $b = 0; // This will generate error echo($a / $b); ?> Output : Error: [2] Division by zero Now Script will end
  • 33. Trigger An Error  In a script where users can input data it is useful to trigger errors when an illegal input occurs.  In PHP, this is done by the trigger_error() function. <?php $test=2; if ($test>=1) { trigger_error("Value must be 1 or below"); } ?> OUTPUT Notice: Value must be 1 or below in /var/www/html/Sem-2/error.php on line 6
  • 34. ERROR TYPES  E_USER_ERROR - Fatal user-generated run-time error. Errors that can not be recovered from.  Execution of the script is halted  E_USER_WARNING - Non-fatal user-generated run-time warning. Execution of the script is not Halted.  E_USER_NOTICE - Default. User-generated run- time notice. The script found something that might be an error, but could also happen when running a script normally
  • 35. EXAMPLE  <?php  //error handler function  function customError($errno, $errstr)  {  echo "<b>Error:</b> [$errno] $errstr<br>";  echo "Ending Script";  die();  }  //set error handler  set_error_handler("customError",E_USER_WARNIN G);  //trigger error  $test=2;  if ($test>=1)  {  trigger_error("Value must be 1 or below",E_USER_WARNING);  }  ?>
  • 36.  EXPLANATION  E_USER_WARNING occurs if the "test" variable is bigger than "1".  If an E_USER_WARNING occurs we will use our custom error handler and end the script:  OUTPUT-  Error: [512] Value must be 1 or below  Ending Script
  • 37. ERROR LOG  By default, PHP sends an error log to the server’s logging system or a file, depending on how the error_log configuration is set in the php.ini file.  By using the error_log() function you can send error logs to a specified file or a remote destination.  Sending error messages to yourself by e-mail can be a good way of getting notified of specific errors.
  • 38. EXAMPLE  <?php  //error handler function  function customError($errno, $errstr)  {  echo "<b>Error:</b> [$errno] $errstr<br>";  echo "Webmaster has been notified";  error_log("Error: [$errno] $errstr",1,  "svghotekar@gamil.com","From: vaibhavghotekar@gmail.com");  }  //set error handler  set_error_handler("customError",E_USER_ WARNING);  //trigger error  $test=2;  if ($test>=1)  {  trigger_error("Value must be 1 or below",E_USER_WARNING);  }  ?>
  • 39.  OUTPUT  Error: [512] Value must be 1 or below Vaibhavghotekar has been notified  And the mail received from the code above looks like this:  Error: [512] Value must be 1 or below

Editor's Notes

  1. NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.