PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.

Slides:



Advertisements
Similar presentations
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Advertisements

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.
CIS101 Introduction to Computing Week 08. Agenda Your questions JavaScript text Resume project HTML Project Six This week online Next class.
PHP and the Web: Session : 4. Predefined variables PHP provides a large number of predefined global variables to any script which it runs also called.
SWU, Computer systems and technologies. The Objective of This Lecture To give you a very high-level overview of some of the tools for Web Programming.
Page 1 PHP, HTML, STATE Achmad Arwan, S.Kom. Page 2 PHP ( PHP: Hypertext Preprocessor) A programming language devised by Rasmus Lerdorf in 1994 for building.
CSE 154 LECTURE 13: SESSIONS. Expiration / persistent cookies setcookie("name", "value", expiration); PHP $expireTime = time() + 60*60*24*7; # 1 week.
Php cookies & sessions.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Uploading Files. Why? By giving a user the option to upload a file you are creating an interactive page You can enable users have a greater web experience.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
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.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
INTERNET APPLICATION DEVELOPMENT For More visit:
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
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.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
PHP Tutorial - Anas Jaghoub Chapter 2 Control Structures.
Week 9 PHP Cookies and Session Introduction to JavaScript.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Nic Shulver, Introduction to Sessions in PHP Sessions What is a session? Example Software Software Organisation The login HTML.
Slide 7-1 CHAPTER 7 Managing Multiple-Form Applications: Writing scripts with multiple screens.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
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.
Cookies & Session Web Technology
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
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.
COOKIES and SESSIONS. COOKIES 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.
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.
Sessions in PHP – Page 1 of 13CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Sessions in PHP Reading: Williams.
Web Database Programming Week 7 Session Management & Authentication.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizard’s Guide to PHP by David Lash.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
The Module Road Map Assignment 1 Road Map We will look at… Internet / World Wide Web Aspects of their operation The role of clients and servers ASPX.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
PHP Session ISYS 475. Session The web server starts a session when a visitor visiting your web site and assigns a unique id, the session id for the session.
Sessions Brendan Knight A visitor accessing your web site is assigned a unique id. This id links to specific data that remains on the server. Sessions.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
Cookies / Sessions Week 10 TCNJ Web 2 Jean Chu. Webpages have no memories.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
1 DIG 3134 Lecture 6: Maintaining State Michael Moshell University of Central Florida Media Software Design.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 3: Working with PHP Rob Gleasure
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
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.
PHP Form Processing * referenced from
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.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizard’s Guide to PHP by David Lash.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
PHP – Hypertext Preprocessor.
Sessions and cookies MIS 3501, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 4/12/2016.
CHAPTER 5 SERVER SIDE SCRIPTING
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
ITM 352 Cookies.
Open Source Programming
Cookies BIS1523 – Lecture 23.
Web Systems Development (CSC-215)
<?php require("header.htm"); ?>
Web Programming Language
PHP-II.
Presentation transcript:

PHP

$_GET / $_POST / $_SESSION

PHP uses predefined variables to provide access to important information about the server and requests from a browser. PHP provides a large number of predefined variables to any script which it runs. PHP provides an additional set of predefined arrays containing variables from the web server the environment, and user input. We can access predefined variables in any scope - any if block, any for block. It means every where in PHP block. There are many predefined variables provided by PHP but this week you will learn just $_GET, $_POST, $_SESSION because there are common things you need to know.

HANDLING USER INPUT WITH $_GET / $_POST

Before knowing $_GET and $_POST You have to know ‘HTTP data sending method’ first. HTTP is how webpage runs. it is agreement between web server and web browser. That is how server and browser communicate to each other. HTTP sending method is about how much secure browser send data to server. (data which comes from user input). - GET method is less secure but easier. With this method we can send data by submitting form or put it directly in address bar but web user can see datas in address bar. ( ) - POST method is better secure but more difficult. With this method we can send data by only submitting form and web user cannot see datas in address bar. ( )

THE WAY OF $_GET We have 2 ways to send data from one php page to another one php page (or itself). – First is using form submission. Important to set method=“get” – Second is specifying data as key-value pair directly after URL.

When datas are sent to destination page you will see the URL in address bar In destination page you can use $_GET[‘key or name of data’]; in PHP block to access datas sent from source page.

THE WAY OF $_POST We have 1 way to send data from one php page to another one php page (or itself). – It is using form submission. Important to set method=“post”

When datas are sent to destination page you will see the URL in address bar In destination page you can use $_POST[‘key or name of data’]; in PHP block to access datas sent from source page.

STORING USER’S STATE OR TEMPORARY INFO WITH $_SESSION

Before knowing $_SESSION Session provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. Session is like transaction, at 7-11 cashier you buy 3 things - Lays, Coke, Mama. Cashier staff calculates the price one by one by scanning your things’ barcode. She does three times then press ‘Enter’ to finish to process. The whole process just now is 1 transaction. The same way when you go to facebook.com website. You may first go to your profile first then you go to your friends’ profile, leave some comments. You found your friend of friend looks nice, you go to his/ her profile and try to see information, photos, marriage status. You may go 5-6 pages already but that is 1 session.

Session may start when you first come to web site at any page or logged in success. After session started, web server can store your state (your information, your input, your IP address, Item you want to buy etc). Web server can destroy your session - by program (such as when you click logout) or - by timing which is when you are inactive (sleep in front your computer or you did not go any page within the same web site) within defined interval (such as 30 minutes). We call this ‘Session timeout’.

Starting a session. Before you can begin storing user information in your PHP session, you must first start the session. When you start a session, it must be at the very beginning of your code, before any HTML or text is sent. Below is a simple script that you should place at the beginning of your PHP code to start up a PHP session.

<?php session_start(); // start up your PHP session! ?>.

Storing / Getting data. When you want to store user data in a session use the $_SESSION associative array. This is where you both store and retrieve session data.

<?php session_start(); // start up your PHP session! ?> <?php $_SESSION[‘views’])=1; // store session data print “view is =“.$_SESSION[‘views’]; // retrieve data ?>

Check if particular session data exists. isset() function comes in handy. isset is a function that takes any variable you want to use and checks to see if it has been set. That is, it has already been assigned a value. With our previous example, we can create a very simple pageview counter by using isset to check if the pageview variable has already been created. If it has we can increment our counter. If it doesn't exist we can create a pageview counter and set it to one. Here is the code to get this job done:

<?php session_start(); // start up your PHP session! ?> <?php if(isset($_SESSION[‘views’])) $_SESSION[‘views’])= $_SESSION[‘views’]+1; else $_SESSION[‘views’])=1; print “view is =“.$_SESSION[‘views’]; ?>

Destroying session You may remove some datas in someone’s session such as session data named ‘cart’ when shopping cart is checked out.

<?php session_start(); // start up your PHP session! ?> <?php // Remove only session data name ‘cart’ if(isset($_SESSION[‘cart’])) unset($_SESSION[‘cart’]) ; ?>

You can also destroy someone’s whole session when he clicked log out button.

<?php session_start(); // start up your PHP session! ?> … <?php session_destroy(); // destroy your PHP session! ?>

Setting up session timeout interval. If you want your session of visitor to be destroy if your visitor are inactive (did not open any page for a while) for an interval you desire, you can easily set it as below: Note that number is second. So 1800 is 30 minutes.

<?php ini_set(‘session.gc_maxlifetime’,’1800’); session_start(); // start up your PHP session! ?> …