PHP 3.

Slides:



Advertisements
Similar presentations
CHAPTER 3 MORE ON FORM HANDLING INCLUDING MULTIPLE FILES WRITING FUNCTIONS.
Advertisements

MMDE5011 – INTERACTIVE MEDIA PRACTICE 1 WEEK 1: INTRODUCTION TO HTML5
Python and Web Programming
1 HTML’s Transition to XHTML. 2 XHTML is the next evolution of HTML Extensible HTML eXtensible based on XML (extensible markup language) XML like HTML.
Understanding HTML Style Sheets. What is a style?  A style is a rule that defines the appearance and position of text and graphics. It may define the.
Basics of Administration & Theming - Smarajit Dasgupta.
#psuweb13 WORDPRESS THEMES 101 A WORDPRESS THEME INTRO WORKSHOP.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
Lab Assignment 7 | Web Forms and Manipulating Strings Interactive Features Added In this assignment you will continue the design and implementation of.
Web Design Using HTML Codes. WHAT DO I NEED TO BEGIN DESIGNING A HOME PAGE? 1.YOU NEED A FOLDER (also called a DIRECTORY) You should set up a folder or.
CS117 Introduction to Computer Science II Lecture 2 Creating an HTML Document Instructor: Li Ma Office: NBC 126 Phone: (713)
SIMPLE ROUTER The slide made by Salim Malakouti. Next we will create the Router  What do I we mean by a router?  Routers work similar to a map. It receives.
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.
WordPress Architecture ► Core files – PHP ► MySQL database  Configured by the installation script ► wp-content directory  themes subdirectory: layout.
CPSC 203 Introduction to Computers Lab 33 By Jie Gao.
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
>> 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.
Chapter 3 Creating Dynamic Web Sites Part 1. Large Sites ”complex sites demand compartmentalization of some HTML or PHP code”.
PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Advanced Web 2012 Lecture 11 Sean Costain 2012.
#eduguruSummit WORDPRESS THEMES 101 SOME SIMPLE STARTER TIPS FOR WORDPRESS THEMES dotEduGuru Summit 2013.
PHP-5- Working with Files and Directories. Reading Files PHP’s file manipulation API is extremely flexible: it lets you read files into a string or into.
Unit 1 – Web Concepts Instructor: Brent Presley.
 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.
PHP Form Processing * referenced from
Company LOGO In the Name of Allah,The Most Gracious, The Most Merciful King Khalid University College of Computer and Information System Web pages Development.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 2 Key Concepts 1 Copyright © Terry Felke-Morris.
Workshop Partner:. Saad Amin Cofounder and CTO Inspire Chittagong Cofounder & Managing Director Codework Builders and Assets Ltd.
HTML Structure & syntax
Getting Started – Basic Page Structure
De-Blackboxing WordPress Communication, Culture and Technology (CCT)
Working with HTML5 & DIV Structures, CSS, Webfonts and Templates
Web Systems & Technologies
PHP (Session 1) INFO 257 Supplement.
Introduction to Dynamic Web Programming
Site Organization.
HTM: Section 2 Hypertext Links Different section of same page
A Method To Minimize HTML Code Duplication
Web Development & Design Foundations with HTML5 8th Edition
>> PHP: HTML Integration
Simple PHP An Introduction.
Arrays and files BIS1523 – Lecture 15.
Relative Paths.
BASIC PHP and MYSQL Edward S. Flores.
>> PHP: Form Processing
PHP Introduction.
Intro to PHP & Variables
Views Views is where we store HTML and lots of contents, we are going to display our user. So, we have models that interact with database. We have controllers,
Simple PHP application
CISC103 Web Development Basics: Web site:
HTML A brief introduction HTML.
Site Organization.
Customizing Editable Regions and Building Templates
Title: Tech Training Certificate: Ace of Initiative Program
Building Web Applications
Introduction to HTML5.
Bare bones notes.
Developing a Model-View-Controller Component for Joomla
Enabling CGI & PHP With Apache
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Server Side Includes Server Side Includes (SSI) are simply this:

Digging in a little deeper
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
Monday, Sept. 24 Today we are going to update the html code to html5. It has some new features that we have not covered yet.
Presentation transcript:

PHP 3

Previous lesson http://enos.itcollege.ee/~ematsak/rakendused/12_04/

Ternary operator if( $valid ) { $x = 'yes'; } else { $x = 'no'; } $x = $valid ? 'yes' : 'no'; If x is valid set it to yes; otherwise set it to no. $valid = true; $lang = 'french'; $x = $valid ? ($lang === 'french' ? 'oui' : 'yes') : ($lang === 'french' ? 'non' : 'no'); echo $x; // outputs 'oui'

Introduction eCommerce UX Design http://ecommerceuxdesi gn.com/collection/websit e-header/

Structure

Index.php

First steps <?php get_header(); ?> <?php get_sidebar(); ?> <?php get_footer(); ?> These functions inject the contents of header.php, sidebar.php and footer.php  WordPress The get_ functions are actually custom variants of the generic include function found in PHP. You could rewrite them as <?php include('header.php'); ?> <?php include('sidebar.php'); ?> <?php include('footer.php'); ? >

Begining <header> <?php include "header.php"; ?> </header> <article><?php include "content.php"; ?></article> <aside> <?php include "sidebar.php"; ?> </aside> <footer><?php include "footer.php"; ?></footer>

Next example header.htm, index.htm footer.htm. <html> <title>My cool website</title> </head> <body> <div id="header"> <img src="logo.png" alt="Cool Website Logo" /> </div> <div id="content"> <p>Awesome content goes here</p> <div id="footer"> <p>Copyright 2011 Cool Site.</p> </body> </html> header.htm,  index.htm footer.htm. <?php include("templates/header.htm"); include("templates/index.htm"); include("templates/footer.htm"); ?>

$action Change index in your code (from templates/index.htm) to be $action <?php include("templates/header.htm"); if (!empty($_GET['action'])) { $action = $_GET['action']; $action = basename($action); include("templates/$action.htm"); } include("templates/footer.htm"); So now that we're only running our code when there is a parameter present, we need to write some code that's going to be ran when it's not present.

$action. Continue <?php include("templates/header.htm"); if (!empty($_GET['action'])) { $action = $_GET['action']; $action = basename($action); if (!file_exists("templates/$action.htm") $action = "index"; include("templates/$action.htm"); } else { include("templates/index.htm"); } include("templates/footer.htm"); ?> <?php include("templates/header.htm"); if (!empty($_GET['action'])) { $action = $_GET['action']; $action = basename($action); include("templates/$action.htm"); } else { include("templates/index.htm"); } include("templates/footer.htm"); ?>

<. php include("templates/header. htm"); if ( <?php include("templates/header.htm"); if (!empty($_GET['action'])) { $action = $_GET['action']; $action = basename($action); if (!file_exists("templates/$action.htm")) $action = "index"; if ($action == 'header' || $action == 'footer') include("templates/$action.htm"); } else { include("templates/index.htm"); } include("templates/footer.htm");

<. php include("templates/header <?php include("templates/header.htm"); // Set the default name $action = 'index'; // Specify some disallowed paths $disallowed_paths = array('header', 'footer'); if (!empty($_GET['action'])) { $tmp_action = basename($_GET['action']); // If it's not a disallowed path, and if the file exists, update $action if (!in_array($tmp_action, $disallowed_paths) && file_exists("templates/{$tmp_action}.htm")) $action = $tmp_action; } // Include $action include("templates/$action.htm"); include("templates/footer.htm");

//specify disallow paths $disallow_paths = array('header', 'footer'); <!DOCTYPE html> <?php //set default name $action = 'index'; //specify disallow paths $disallow_paths = array('header', 'footer'); if (!empty($_GET['action'])){ $tmp_action = basename($_GET['action']); //if it's not a diallowed path, and if the file exists, make $action if (!in_array($tmp_action, $disallow_paths) && file_exists("templates/{$tmp_action}.htm")) $action = $tmp_action; } echo "<html> <head> <link type='text/css' rel='stylesheet' href='stylesheet.css' /> <title>Title - " . $action . "</title> </head> <body>"; include("templates/header.htm"); include("templates/$action.htm"); include("templates/footer.htm"); echo "</body> </html>";

Creating a Website Design Templating System Using PHP Step 1 Create a folder on your server and name it "design". Step 2 Create the following files in the design folder: 'header.html', 'footer.html', 'right_column.html', 'left_column.html' Step 3 Create another folder and name it "pages" Step 4 In the "pages" directory, create a page and give it the name: 'main.html' Step 5 Now in the root directory create a file and give it the 'index.php' Step 6 Add the following code to your 'index.php' file

<. php if (isset($_REQUEST['page'])) { if($_REQUEST['page'] <?php if (isset($_REQUEST['page'])) { if($_REQUEST['page'] !="") if(file_exists("pages/".$_REQUEST['page'].".html")) $page_content = file_get_contents("pages/".$_REQUEST['page'].".html"); else if (file_exists($_REQUEST['page'].".html")) $page_content = file_get_contents($_REQUEST['page'].".html"); echo "<center>Page:".$_REQUEST['page']." does not exist! Please check the url and try again!</center>"; } $page_content = file_get_contents("pages/main.html"); $page_content = str_replace("!!HEADER!!", file_get_contents("design/header.html"),$page_content); $page_content = str_replace("!!LEFT_COLUMN!!", file_get_contents("design/left_column.html"),$page_content); $page_content = str_replace("!!RIGHT_COLUMN!!", file_get_contents("design/right_column.html"),$page_content); $page_content = str_replace("!!FOOTER!!", file_get_contents("design/footer.html"),$page_content); $page_content = str_replace("!!COMMON_TAGS!!", file_get_contents("design/common_tags.html"),$page_content); echo $page_content; ?> index.php

Code Explanation & How it Works. (1) if (isset($_REQUEST['page'])) This php code will check to see if a page is requested. if($_REQUEST['page'] !="") Of course, to eliminate errors, make sure a page is entered and it is not a blank argument. if(file_exists("pages/".$_REQUEST['page'].".html")) Now we check to see if it exists in the default folder; in our case it is the pages folder. Note that we have included the '.html' extension here so we do not need to enter it when we request the page. By using this method, we also benefit from using standard html designs for the pages. 

Code Explanation & How it Works. (2) $page_content = file_get_contents($_REQUEST['page'].".html"); If every thing is alright, assign the contents of that page to a variable: $page_content. Note that the file_get_content function will not execute any code. That is: putting php code in your pages will not work. If you need to use any php code, either add it to your 'index.php' or to separate files and then include it in the 'index.php'.  else if (file_exists($_REQUEST['page'].".html")) $page_content = file_get_contents($_REQUEST['page'].".html"); These lines will extend and go further than the default folder.  You can use it to request pages in deeper folders in your website. For example, you can design pages in a sub-directory and request it in a similar way to requesting pages in the default folder using the following command in your browser:  main_folder_of_files/index.php?page=sub-directory/page.html

Code Explanation & How it Works. (3) else echo "<center>Page:".$_REQUEST['page']." does not exist! Please check the url and try again!</center>";  We looked for the requested page in the default folder, in the sub- directory requested but we did not find it....then it does not exist. Print an error statement!!! else $page_content = file_get_contents("pages/main.html"); If no page is requested at all, go to a default page. 

Code Explanation & How it Works. (4) $page_content = str_replace("!!HEADER!!", file_get_contents("design/header.html"),$page_content); $page_content = str_replace("!!LEFT_COLUMN!!", file_get_contents("design/left_column.html"),$page_content); $page_content = str_replace("!!RIGHT_COLUMN!!", file_get_contents("design/right_column.html"),$page_content); $page_content = str_replace("!!FOOTER!!", file_get_contents("design/footer.html"),$page_content);  This is the fun part! Our $page_content variable now holds the design and the content of the page requested. We simply use the str_replace function to replace our tag holders with our predesigned pages.