CS Learning Centre PHP Tutorial. Introduction ⇨ Based on PHP and MySQL Web Development, Third Edition (Available as CS eBook from Dal Library) ⇨ Other.

Slides:



Advertisements
Similar presentations
Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
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.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
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.
PHP (2) – Functions, Arrays, Databases, and sessions.
Introduction to php Chapter 1 ACSG 550. What we will be doing… Developing full-service websites with – dynamic content – support for user interaction.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
Using Session Control in PHP tMyn1 Using Session Control in PHP HTTP is a stateless protocol, which means that the protocol has no built-in way of maintaining.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
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.
PHP - Hypertext Preprocessor Yaron Benita De Paul University.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
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.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Introduction to Applets CS 3505 Client Side Scripting with applets.
Computing & Information Sciences Kansas State University Lecture 17 of 42 Friday, 10 October 2008 William H. Hsu Department of Computing and Information.
Web Programming Language Week 7 Dr. Ken Cosh Security, Sessions & Cookies.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
12/3/2012ISC329 Isabelle Bichindaritz1 PHP and MySQL Advanced Features.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Introduction to PHP “PHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
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.
1 PHP Introduction Chapter 1. Syntax and language constructs.
PHP Teresa Worner. What is it? PHP: Hypertext Preprocessor server-side scripting language open source cross-platform compatible with almost all servers.php.php3.phtml.
CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Introduction to PHP Advanced Database System Lab no.1.
Introduction to Web Programming. Introduction to PHP What is PHP? What is a PHP File? What is MySQL? Why PHP? Where to Start?
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.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
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)
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
 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.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Creating PHP Pages Chapter 5 PHP Structure and Syntax.
Chapter 1 Introduction to PHP Part 1. Textbook’s Code DOWNLOADS PHP and MySQL for Dynamic Web Sites Complete Set of Scripts.
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 Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
1 CS428 Web Engineering Lecture 22 Building Dynamic Web pages (PHP - V)
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Cookies and Sessions in PHP. Arguments for the setcookie() Function There are several arguments you can use i.e. setcookie(‘name’, ‘value’, expiration,
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.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
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.
By bscshelp.com 1.  It is a group assignment.  Complete Website design Using Html and Css.  Due date: 10 th December, 2014 (Hard Deadline) 2.
Introduction to Dynamic Web Programming
Introduction to PHP Part 1
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
PHP Introduction.
<?php require("header.htm"); ?>
PHP.
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
Tutorial 10: Programming with javascript
PHP an introduction.
Advanced Concepts and AJAX
Presentation transcript:

CS Learning Centre PHP Tutorial

Introduction ⇨ Based on PHP and MySQL Web Development, Third Edition (Available as CS eBook from Dal Library) ⇨ Other eBooks from Dal Library ⇨ Learning PHP 5 ⇨ PHP Cookbook ⇨ For Online resources, google “PHP”

Table of Contents ⇨ Embedding PHP ⇨ Variables ⇨ Operators and Control Structures ⇨ Array ⇨ Function ⇨ Session Control (Using Cookie)

Embedding PHP in HTML ⇨ Insert PHP tag inside HTML file (with.php extension ⇨ XML Style ⇨ Short Style (Need to be enabled) ⇨ Script Style PHP statement; ⇨ ASP Style (Need to be enabled) ⇨ Dynamic Content function('argument'); ⇨ Note: argument is in string

Variables ⇨ Do not require to declare variable type ⇨ Variable variables $varname = 'tireqty'; $$varname = 5; ⇨ Constants define('TIREPRICE', 100); ⇨ Accessing form variables (field=tireqty) ⇨ Short style (requires register_globals) $tieryqty ⇨ Medium style $_POST['tireqty'] or $_GET['tireqty'] ⇨ Long style $HTTP_POST_VARS['tireqty']

Operators and Control Structures ⇨ Pretty much same as in other programming languages (C, Java, etc.) ⇨ Break statements are also same (continue, break), except it provides exit statement to break out of the script ⇨ Alternative control structure syntex if( $totalqty == 0): echo 'You did not order anything on the previous page! '; exit; endif;

Array ⇨ Create an array $products = array ('Tires', 'Oil', 'Engine'); ⇨ Automatically generate sequnces of number, character $numbers = range (1,10,2); //last parameter optional(Indicate step) ⇨ Accessing element $products[0] ⇨ Array with different indices $prices = array( 'Tires'=>100, 'Oil'=>10, 'Spark Plugs'=>4 ); ⇨ Assign key and value to variables list( $product, $price ) = each( $prices );

Array (Cont'd) ⇨ Multidimensional Array ($products[row][column] $products = array( array( 'Code' => 'TIR', 'Description' => 'Tires', 'Price' => 100 ), array( 'Code' => 'OIL', 'Description' => 'Oil', 'Price' => 10 ), array( 'Code' => 'SPK', 'Description' => 'Spark Plugs', 'Price' =>4 ) );

Function ⇨ New function function my_function() { echo 'My function was called'; } ⇨ Calling function my_function();

Function (Cont'd) ⇨ Using argument ⇨ Should reset the argument if it is an array ⇨ The next command gets next element of arg ⇨ The current command gets current element ⇨ Ex. function create_table2( $data, $border = 1, $cellpadding = 4, $cellspacing = 4 ) { echo "<table border = $border cellpadding = $cellpadding"." cellspacing = $cellspacing>"; reset($data); $value = current($data); while ($value) { echo " $value \n"; $value = next($data); } echo ' '; }

Session Control (Using Cookie) ⇨ Manually setting Cookie in PHP bool setcookie (string name [, string value [, int expire [, string path [, string domain [, int secure]]]]]) Ex. setcookie ('mycookie', 'value'); ⇨ Using Cookie with Sessions ⇨ Get session cookie parameters session_get_cookie_params() ⇨ Set session cookie parameters session_set_cookie_params($lifetime, $path, $domain [, $secure]);

Session Control (Cont'd) ⇨ Starting Session (Must be declared at the beginning of the file) session_start(); ⇨ Registering Session variables $_SESSION['myvar'] = 5; ⇨ Unsetting variables ⇨ Single variable unset($_SESSION['myvar']); ⇨ All variables $_SESSION=array(); ⇨ Destroying session session_destroy();

Session Control (Example) ⇨ Begin session <?php session_start(); $_SESSION['sess_var'] = "Hello world!"; echo 'The content of $_SESSION[\'sess_var\'] is '.$_SESSION['sess_var'].' '; ?> Next page

Session Control (Example) ⇨ Get the variable and unset it <?php session_start(); echo 'The content of $_SESSION[\'sess_var\'] is '.$_SESSION['sess_var'].' '; unset($_SESSION['sess_var']); ?> Next page

Session Control (Example ⇨ End session <?php session_start(); echo 'The content of $_SESSION[\'sess_var\'] is '.$_SESSION['sess_var'].' '; session_destroy(); ?>