Building Web Applications

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

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.
PHP Reusing Code and Writing Functions.
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
Newsletter Plugin The newsletter plugin allows you to create and send newsletters to a managed list or multiple lists of users. Your users can subscribe.
PHP (2) – Functions, Arrays, Databases, and sessions.
Python and Web Programming
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 21: Publishing Your Pages on the Web.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advanced Web 2012 Lecture 4 Sean Costain PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
PHP Tutorial - Anas Jaghoub Chapter 2 Control Structures.
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT.
SHOPPING CARTS CHAPTER 19. E-COMMERCE Typically, an e-commerce site will have public pages and admin pages.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
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.
® IBM Software Group © 2006 IBM Corporation JSF Progress Bar This Learning Module shows how to integrate EGL/JSF functionality into a run-time progress.
Publishing Your Web Pages Ann Emmanuel SIUE Web Administrator
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
audio video object Options: controls autoplay Need to define height and width Options: controls autoplay.
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.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Chapter 3 Creating Dynamic Web Sites Part 1. Large Sites ”complex sites demand compartmentalization of some HTML or PHP code”.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
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.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
HTML5 and CSS3 Illustrated Unit E: Inserting and Working with Links.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Advanced HTML Tags:.
June 17, 2009 Office 2007 Tips & Tricks.
Brad N Greenwood, PhD MBA
Sessions and cookies MIS 3501 Jeremy Shafer Department of MIS
User-Written Functions
Introduction to Python
Loops BIS1523 – Lecture 10.
Arrays: Checkboxes and Textareas
Single Sample Registration
ITM 352 Cookies.
PHP & MySQL Introduction.
>> PHP: HTML Integration
Web Programming Language
Core LIMS Training: Advanced Administration
Arrays and files BIS1523 – Lecture 15.
Error Handling Summary of the next few pages: Error Handling Cursors.
Unit 4 – Functions and Include Files
Open Source Programming
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
While Loops BIS1523 – Lecture 12.
HTML Forms and User Input
MVC Framework, in general.
ISC440: Web Programming 2 Server-side Scripting PHP 3
More Selections BIS1523 – Lecture 9.
Functions BIS1523 – Lecture 17.
Conditions and Ifs BIS1523 – Lecture 8.
Number and String Operations
In-Class Program: Sales System
Configuring Internet-related services
In Class Programming BIS1523 – Lecture 11.
In Class Programming: Credit card payment
Video list editor BIS1523 – Lecture 24.
Coding Concepts (Basics)
Sessions and cookies MIS 3501 Jeremy Shafer Department of MIS
Web Programming Language
Mr. Justin “JET” Turner CSCI 3000 – Fall 2016 Section DA MW 4:05-5:20
Presentation transcript:

Building Web Applications BIS1523 – Lecture 18

Web Applications Often, a web site isn’t a single page, or even just 2 pages. A lot of our applications or web sites are made up of numerous pages. For example: http://www.visit.msstate.edu/ Notice this web site has a number of different links, all with a similar look. They have the same header, and navigation options at the top. When we select an option, the URL changes. These are all different html (or php) files.

Web Applications When we have sections of web pages that are all repeated, it is often times better to have that HTML or PHP code in a single location. Imagine if each of those 5 pages had their own copy of the header and nav options. If you wanted to change the look of those, you’d have to edit them in 5 locations. Now imagine how that scales, if you have 20 different pages, or 50. Any time you have to do multiple edits, the chance for errors goes up, and the time to make the change goes up drastically. A better system is to create something called a “template”, store the HTML in one file, and then reference that file.

Templates We can use the “include” PHP command to reference other files in our pages. In each of these three pages, we can put the command: This will add the contents of header.html into the web page as it is loading. Each time the page loads, it goes back and gets header.html

Templates This means changes header.html can be done in a single location, and those changes will be updated when the other pages load. Included files may contain HTML and/or PHP. Notice that the include command is PHP, so the including file needs to have a .PHP extension

Example Index.php: Results: Example.html:

Functions in Includes Another useful use for inclusion is code you want to re-use on multiple projects. For example, you write a complex function to format some output, or do a calculation, and it can be used in several different pages. You could put it in its own file, and then just use include commands in the pages that need to access the function. Much like HTML updates this makes updates to the functions easier to accomplish as well.

Sessions Sessions allow you to store data between several web pages. Normal variables only exist while the PHP script is running, they don’t exist out of their local area. With a Session variable, you could have values stored that would be accessible from all of your web pages. Session variables are stored on the server.

Session Start In order to use session variables, you have to perform the command session_start() This command must be the very first thing in every PHP file that wants to use these variables.

Session Variables Once you have started a session, you have access to the $_SESSION array. You can set variables using the command: You can access those variables just as you would any other variable:

Ending a Session You can end a session with the command session_destroy(); This stops the session, removing all the data stored on the server. Most servers are configured to automatically do this after a certain period of time. Note: The course web site uses sessions in several ways, so executing this command inside one of your PHP pages will effectively log you out of the course web site.

Example Let’s assume we have a web site with a few pages, and we’d like to track how often people visit the page, and what pages they visit. If a user visits several pages in a row, we’d like to know which pages she visits. If they leave and come back later, we’ll start a different log. We will use 2 different pieces of data to tell when a user visits our page: A file that stores a single number. That is the number of the “last user who visited the page” A session variable, that will remember what visitor number is currently assigned to this session.

Example So, when a user visits our page, we will: Check to see if they are already assigned a visitor number by reading in the session variable. If it is blank, then we Read the file to assign them a number. Increment the number in the file for the next person Set the session variable for other pages Set a normal variable for this page.

Example If a user has visited this page recently, the session variable $_SESSION[‘visitor’] will have already been set, so we just read it in. If they haven’t, we get the next number from the file

Example Once the PHP variable $visitor is set, it can be accessed in HTML anywhere on the page

Example If we include that same script to read the session variable on other pages, they will all track that visitor number. So user goes to session1.php and the session variable gets set. Then, when they visit session2.php, that variable is still set, and we can use it. We could also then use that variable to track page visits. Lets say we’d like to create a unique log file for each user. We’ll name it “log”, and then add their visitor number. So visitor 18 will have a file “log.18”.

Example To create the filename, we make use of PHP’s ability to do variable substitution, and put the value of $visitor into the name: So if $visitor has the value “18”, the variable $filename will have the value “log.18”. Then, we write information to that file:

Example We use FILE_APPEND so the new information is just added to the end of the file. We concatenate the name of the page with PHP_EOL, so when we look at the file each name is on its own line. The resulting log file might contain information like:

Example We could include this header on all of our web pages. The only thing different on each page would be the name that we are logging. If this is going to be repeated, we should instead, use an include.

Example To use an include, first, we create a new file, with just the header information we want in it. File: visit.include.php: Then, in each of our web pages, we include it with the command:

Example So now, each of our web pages looks like: