PHP Week 8 INFM 603. Agenda Questions PHP Drupal Project Plan.

Slides:



Advertisements
Similar presentations
Web Database Programming Connecting Database to Web.
Advertisements

PHP Week 11 INFM 603. Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging –But not.
PHP (2) – Functions, Arrays, Databases, and sessions.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
Debugging and Ajax Session 7 INFM 718N Web-Enabled Databases.
MySQL and PHP Integration Session 6 INFM 718N Web-Enabled Databases.
JavaScript and PHP Week 10 LBSC 690 Information Technology.
PHP Programming Session 2 INFM 718N Web-Enabled Databases.
MySQL and Requirements Session 4 INFM 718N Web-Enabled Databases.
Week 1 INFM 718N Web-Enabled Databases The Big Picture.
Web-Database Integration
PHP and MySQL Web Development tMyn1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
PHP Programming Part II and Database Design Session 3 INFM 718N Web-Enabled Databases.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Dataface API Essentials Steve Hannah Web Lite Solutions Corp.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
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.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Content Management Systems Week 9 INFM 603. Muddiest Points How JSON differs from XML –And how JSONP differs from JSON How Ajax works Examples of JavaScript.
Ajax and Ruby on Rails Session 9 INFM 603.
Drupal Week 10 INFM 603. Agenda Questions Drupal Project Plan.
Content Management Systems Week 14 LBSC 671 Creating Information Infrastructures.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Programming Week 11 LBSC 690 Information Technology.
Website Development with PHP and MySQL Saving Data.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
 2008 Pearson Education, Inc. All rights reserved PHP.
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.
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
CSC 2720 Building Web Applications Accessing MySQL from PHP.
CSC 2720 Building Web Applications Basic Frameworks for Building Dynamic Web Sites / Web Applications.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
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.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
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.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
Radoslav Georgiev Telerik Corporation
PHP using MySQL Database for Web Development (part II)
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Content Management Systems
Software Engineering for Internet Applications
PHP.
Presentation transcript:

PHP Week 8 INFM 603

Agenda Questions PHP Drupal Project Plan

Database Server-side Programming Interchange Language Client-side Programming Web Browser Client Hardware Server Hardware (PC, Unix) (MySQL) (PHP) (HTML, XML) (JavaScript) (IE, Firefox) (PC) Business rules Interaction Design Interface Design Relational normalization Structured programming Software patterns Object-oriented design Functional decomposition

Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging Procedural perspective (vs. object-oriented)

Making PHP HTML stuff <?php PHP stuff ?> HTML stuff stuff---/xxxxx.php

Programming Skills Hierarchy Reusing code [run the book’s programs] Understanding patterns [read the book] Applying patterns [modify programs] Coding without patterns [programming] Recognizing new patterns

Some Things to Pay Attention To Syntax How layout helps reading How variables are named How strings are used How input is obtained How output is created Structured Programming How things are nested How arrays are used Modular Programming Functional decomposition How functions are invoked How arguments work How scope is managed How errors are handled How results are passed

Variables All variable names starts with a $ –Case sensitive (assume everything could be!) Variables can hold any scalar value –Number (integer, float) –String (double quotes, \ escape character) –TRUE, FLASE –NULL Need not be declared, automatically cast

Operators in PHP Arithmetic operators + - * / Logical operators = > && || ! String concanetation operator. Different from JavaScript!

Statements in PHP Sequential {…; …;…;} Semicolons are required at the end of every statement Conditional if (3==i) {…} else {…} Loop foreach ($array as $key => $value) {…} while ($row=mysql_fetch_array(…)) {…} For ($i=0; $i<10; $i++) {…} Braces are optional around a single statement

Arrays in PHP A set of key-element pairs $days = array(“Jan”->31, “Feb”=>28, …); $months = explode(“/”, “Jan/Feb/Mar/…/Dec”); $_POST Each element is accessed by the key –$months[0]; –{$days[“Jan”]} PHP unifies arrays and hashtables –Elements may be different types

Functions in PHP Declaration function multiply($a, $b=3){return $a*$b;} Invoking a method $b = multiply($b, 7); All variables in a function have only local scope Unless declared as global in the function

Using PHP with (X)HTML Forms ”, size=30 /> Yes No if (isset($_POST[“submitted”])) { echo “Your address is $ .”; } else { echo “Error: page reached without proper form submission!”; }

Connecting PHP to MySQL On XAMPP: $dbc=mysql_connect (‘localhost’, ‘userid’, ‘password’); On unix: $dbc=mysql_connect(‘:/export/software/otal/mysql/run/mysqld.sock’, ‘userid’, ‘password’);

<?php # Script mysql_connect.php // Set the database access information as constants. DEFINE ('DB_USER', 'tester'); DEFINE ('DB_PASSWORD', 'tester'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); // Make the connection. $dbc (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: '. mysql_error() ); // Select the (DB_NAME) OR die ('Could not select the database: '. mysql_error() ); // Create a function for escaping the data. function escape_data ($data) { // Address Magic Quotes. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } // Check for mysql_real_escape_string() support. if (function_exists('mysql_real_escape_string')) { global $dbc; // Need the connection. $data = mysql_real_escape_string (trim($data), $dbc); } else { $data = mysql_escape_string (trim($data)); } // Return the escaped value. return $data; } // End of function. ?>

<?php # Script login.php (7th version after Scripts 9.1, 9.3, 9.6, & 9.14) // Send NOTHING to the Web browser prior to the session_start() line! // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('../mysql_connect.php'); // Connect to the db. $errors = array(); // Initialize error array. // Check for an address. if (empty($_POST[' '])) { $errors[] = 'You forgot to enter your address.'; } else { $e = escape_data($_POST[' ']); } // Check for a password. if (empty($_POST['password'])) { $errors[] = 'You forgot to enter your password.'; } else { $p = escape_data($_POST['password']); }

if (empty($errors)) { // If everything's OK. /* Retrieve the user_id and first_name for that /password combination. */ $query = "SELECT user_id, first_name FROM users WHERE ='$e' AND password=SHA('$p')"; $result ($query); // Run the query. $row = mysql_fetch_array ($result, MYSQL_NUM); // Return a record, if applicable. if ($row) { // A record was pulled from the database. // Set the session data & redirect. session_name ('YourVisitID'); session_start(); $_SESSION['user_id'] = $row[0]; $_SESSION['first_name'] = $row[1]; $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); // Redirect the user to the loggedin.php page. // Start defining the URL. $url = ' $_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url.= '/loggedin.php'; header("Location: $url"); exit(); // Quit the script. } else { // No record matched the query. $errors[] = 'The address and password entered do not match those on file.'; // Public message. $errors[] = mysql_error(). ' Query: '. $query; // Debugging message. } } // End of if (empty($errors)) IF. mysql_close(); // Close the database connection. } else { // Form has not been submitted. $errors = NULL; } // End of the main Submit conditional.

// Begin the page now. $page_title = 'Login'; include ('./includes/header.html'); if (!empty($errors)) { // Print any error messages. echo ' Error! The following error(s) occurred: '; foreach ($errors as $msg) { // Print each error. echo " - $msg \n"; } echo ' Please try again. '; } // Create the form. ?> Login Address: Password: <?php include ('./includes/footer.html'); ?>

Agenda Questions PHP  Drupal Project Plan

Content Management Systems Database to store content –Also stores access control data and parameters PHP to control user experience –Reads database, generates HTML –“Canned” settings provide standard behaviors XHTML to convey user experience Allows limited interactivity –Most user actions require a server response –JavaScript may be used for form validation

Installing Drupal Download and install XAMPP –Add c:\xampp\mysql\bin to your path Download and install Drupal version 6.x –Configure for local use (“first time user guide”) –Ignore SMTP error messages Configure your site –Add some “splash page” content –Set user permissions

Drupal’s Use of MySQL USE drupal; SHOW TABLES; SELECT * FROM users; SELECT * FROM nodes; SELECT * FROM node_revisions;

Modifying Drupal Work with what’s there –Content –Configuration Download a distribution profile Edit the CSS files Edit the PHP code Edit the database contents

Agenda Questions PHP Drupal  Project Plan

What are Requirements? Attributes –Appearance –Concepts (represented by data) Behavior –What it does –How you control it –How you observe the results

Who Sets the Requirements? People who need the task done (customers) People that will operate the system (users) People who use the system’s outputs People who provide the system’s inputs Whoever pays for it (requirements commissioner)

The Requirements Interview Focus the discussion on the task –Look for entities that are mentioned Discuss the system’s most important effects –Displays, reports, data storage –Learn where the system’s inputs come from –People, stored data, devices, … Note any data that is mentioned –Try to understand the structure of the data Shoot for the big picture, not every detail

The Project Plan One-page contract –Between developer and requirements commissioner Goal The problem to be solved ProductWhat you plan to deliver ScopeAvailable time and personnel RolesWhat you expect each other to do