More on Variables Some related techniques. Header() function void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) header()

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
PHP Form Processing. Using Forms in PHP  Two steps to process  Display the form  Process the submitted data.
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
1 Static Web Pages Websites on Servers (The Big Picture) –Apache Tomcat can support static web pages –Primarily intended to support servlets and JSP –Some.
PHP Form Processing. Using Forms in PHP  Two steps to process  Display the form  Process the submitted data.
PHP Forms. I. Using PHP with HTML Forms A very common application of PHP is to have an HTML form gather information from a website's visitor and then.
FILE UPLOADS CHAPTER 11. THE BASIC PROCESS 1.The HTML form displays the control to locate and upload a file 2.Upon form submission, the server first stores.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
CSCI 323 – Web Development Chapter 1 - Setting the Scene We’re going to move through the first few chapters pretty quick since they are a review for most.
MIT AITI 2004 JSP – Lecture 2 Get and Post Requests.
Web Forms with PHP COEN 351. Displaying and processing a simple form if( array_key_exists(‘my name’,$_POST)){ print “Hello, “.$_POST[‘my_name’]; } else.
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
PHP : Hypertext Preprocessor
1 Chapter 6 – Creating Web Forms and Validating User Input spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
HOW WEB SERVER WORKS? By- PUSHPENDU MONDAL RAJAT CHAUHAN RAHUL YADAV RANJIT MEENA RAHUL TYAGI.
Week Three CIT 354 Internet II. 2 Objectives Displaying Dynamic Content Sending Using Your File System Common Programming Errors Summary Quiz,
Creating Databases for Web Applications cookie examples lab time: favorites cookies & Sessions class time for group work/questions on projects Next class:
MySQL and PHP Internet and WWW. Computer Basics A Single Computer.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input.
CGI programming Peter Verhás January What this tutorial is about Introduction to CGI programming Using ScriptBasic –Simple to program –Simple to.
1 Welcome to CSC 301 Web Programming Charles Frank.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Global Variables - Superglobals Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
PHP-based Authentication
Part 2 Lecture 9 PHP Superglobals and Form Handling.
Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending working: both html and Flash!
Various Notes on PHP Several useful tidbits not discussed in class.
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
JavaScript and Ajax (Internet Background) Week 1 Web site:
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
1 CS428 Web Engineering Lecture 22 Building Dynamic Web pages (PHP - V)
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Radoslav Georgiev Telerik Corporation
PHP – Hypertext Preprocessor.
National College of Science & Information Technology.
JavaScript and Ajax (Ajax Tutorial)
PHP on the Command Line Often convenient to experiment with PHP in the command window, without involving the server Add the location of php.exe to your.
Networks Problem Set 1 Due Oct 3 Bonus Date Oct 2
MapServer In its most basic form, MapServer is a CGI program that sits inactive on your Web server. When a request is sent to MapServer, it uses.
PHP Introduction.
Intro to PHP & Variables
14-мавзу. Cookie, сеанс, FTP и технологиялари
Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314
PHP.
Hypertext Transfer Protocol
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
The HTTP Protocol COSC 2206 Internet Tools The HTTP Protocol
PHP: Hypertext Preprocessor
Introduction to PHP.
Presentation transcript:

More on Variables Some related techniques

Header() function void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) header() is used to send a raw HTTP header. Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.include()require()

Error in using header() /* Discuss the above URL */

Application Example Calculator example: need to provide 2 operands and select an operator What if one field is blank or no operator is selected?

<?php /* Note: 1. For security reasons, do not use implicit variables in forms passed directly to the server. Use $_POST[xxx] instead. 2. All variables passed via $_POST should be in quotes, double or single 3. IF the textfields are empty, the server will reload the form */ if (($_POST["val1"] == "") || ($_POST["val2"] == "") || ($_POST["calc"] == "")) { header("Location: exit; } 6-1 Use header() to reload a file

6-2 HTTP Environment Variables Look for Apache Environment REMOTE_ADDR HTTP_USER_AGENT Use getnev() function

<?php /* getenv() function * To get the REMOTE_ADDR value * REMOTE_ADDR environment variable contains the IP address * of the machine making the request. */ $address = getenv("REMOTE_ADDR"); echo "Your IP address is $address."; ?> getenv() in 6-3remoteaddress.php

<?php $agent = getenv("HTTP_USER_AGENT"); echo " You are using $agent."; /* HTTP_USER_AGENT variable contains * the browser type *the browser version *language encoding *platform */ ?>

7-1 Detecting User’s Browser M07/7-1browsermatch.php <?php $agent = getenv("HTTP_USER_AGENT"); if (preg_match("/MSIE/i", "$agent")) { $result = "You are using Microsoft Internet Explorer."; } else if (preg_match("/Firefox/i", "$agent")) { $result = "You are using Firefox."; } else if (preg_match("/Mozilla/i", "$agent")) { $result = "You are using Netscape."; } else { $result = "You are using $agent"; } ?>

7-2 Displaying Platform-Specific HTML <?php $agent = getenv("HTTP_USER_AGENT"); if (preg_match("/Win/i", "$agent")) { $style = "win"; } else if (preg_match("/Linux/i", "$agent")) { $style = "linux"; } ?> <?php if ($style == "win") { echo "$win_style"; } else if ($style == "linux") { echo "$linux_style"; } ?>

7-3 generic form + string functions header() md5(text1) strlen(text1) strrev(text1) strtoupper(text1) strtolower(text1) ucwords(text1)

7-4 Redirecting to a New Location Sending an HTTP header to the browser – Authentication, redirection, cookies etc. must be sent to the browser before anything else (including white space, line breaks, and any characters) 7-4do_redirect.php

Code <?php if ($_POST['location'] == ""){ /* works with or without double quotes around location */ header("Location: 7-4redirect_form.html"); exit; } else { header("Location: $_POST[location]"); /* Here quotes are not allowed!! */ exit; } ?>