PHP Hypertext Preprocessor

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
XAMPP: Cross – Apache, MySQL, Php, Perl + FileZilla, Tomcat NetBeans: IDE PHP Installation.
WEB SECURITY WORKSHOP TEXSAW 2013 Presented by Joshua Hammond Prepared by Scott Hand.
PHP: Hypertext Processor Fred Durao
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Mandakini Ayushi Infotech Mandakini Kumari 22 nd July PHP Basic.
PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP is a powerful.
SCV1223 PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
Content Types and Views Information Systems 337 Prof. Harry Plantinga.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
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.
INTERNET APPLICATION DEVELOPMENT Practical on Sessions.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
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
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
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)
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Introduction to PHP Brendan Knight. What is PHP PHP is a general-purpose scripting language originally designed for web development to produce dynamic.
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.
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.
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.
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
Mini – Workshop on PHP Faculty of Engineering in Foreign Languages 1.
Tried my best to simplify it for you!
PHP (Session 2) INFO 257 Supplement.
Remote hosts and web servers
CHAPTER 5 SERVER SIDE SCRIPTING
Introduction to Dynamic Web Programming
DBW - PHP DBW2017.
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.
ITM 352 Cookies.
Web Programming Language
Content Types and Views
Cookies and Sessions in PHP
PHP / MySQL Introduction
BASIC PHP and MYSQL Edward S. Flores.
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
Introduction to Web programming
Web Systems Development (CSC-215)
<?php require("header.htm"); ?>
CIS 388 Internet Programming
Software Engineering for Internet Applications
Web DB Programming: PHP
PHP: Database Basic Selection FdSc Module 109
PHP: Combo box FdSc Module 109 Server side scripting and
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Web Programming Language
محمد احمدی نیا PHP محمد احمدی نیا
Web Programming Language
PHP an introduction.
PHP PROF. S. LAKSHMANAN, DEPT. OF B. VOC. (SD & SA),
Hypertext Preprocessor
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga PHP Hypertext Preprocessor

Getting Nice Output How do Drupal and other content management systems work? How can you customize the look or functionality of your site? To understand the theme system and to make your own modules requires PHP Youtube and Flickr are pretty similar, apart from looks… All html, css, javascript, images, etc. can be overridden by the theme

PHP Overview What is it? PHP files contain PHP Hypertext Preprocessor Server-side scripting language Widely used, cross-platform, free PHP files contain HTML PHP code Poorly designed langauge?

PHP Example <h2>MSPSP U14 Boys Classic 3</h2> <table style='width:100%' id="standings"> <?php $result = db_query("select name, abbrev, wins, losses, ties, points, goalsFor, goalsAgainst, power from stats.team order by points desc, power desc"); while ($row = db_fetch_array($result)) { echo("<tr><td><a href=\”schedule?team=$row[abbrev]\”>$row[name]</a></td>"); echo("<td>$row[wins]</td>"); echo("<td>$row[losses]</td>"); echo("<td>$row[ties]</td>"); echo("<td>$row[points]</td>"); echo("<td>$row[goalsFor]</td>"); echo("<td>$row[goalsAgainst]</td>"); $power=round($row[power],2); echo("<td style='text-align:right'>$power</td></tr>"); } ?> </table>

PHP Basics /* comments */ Variables: loosely typed $var1 = "hello world"; $var2 = 7; C/Java/JavaScript-like syntax for expressions, arrays, if, for, while, switch, etc Associative arrays, concatenation like perl: $mascot('calvin')='knight'; $mascot('hope') = 'flying' . ' dutchman'; functions: function add($a, $b) { return $a + $b; } demo for loop, (10, 9, 8… boom!) demo associative array: $mascot(‘fred’) = ‘ralph’; echo $mascot(‘fred’’);

Question How would I write PHP to Display "Hello world!" <?php echo("<h1>Hello world!</h1>"); ?> Display 1 2 3 4 5 … 100 <?php for ($i=1; $i<=100; $i++) echo("$i "); ?> Display the current date <?php echo date("Y-m-d"); ?> Load in a server side include file <?php include("header.php"); ?> demo for loop, (10, 9, 8… boom!) demo associative array: $mascot(‘fred’) = ‘ralph’; echo $mascot(‘fred’’);

Question How can you read and use data entered into a form?

PHP Forms Handling Forms handling, GET and POST hello.html hello.php <form action="hello.php" method="post"> Name: <input type="text" name="name" /> <input type="submit"/> </form> hello.php <html> <h3>Welcome, <?php echo $_POST["fname"]; ?>!</h3> </html> Also, $_GET["attname"] (example) demo forms processin: <?php if (strlen($_GET["name"])>0) echo "<h1>Hello, " . $_GET["name"] . "</h1>"; else echo "<h3>What's your name?</h3>"; ?>

Question How can you keep track of a user's preferences for your website, say preferred font size?

Cookies Built-in cookie handling: setcookie(name, value, expire, path, domain); $expire = time() + 60*60*24*365; setcookie("fontsize","120%",$expire); Retrieve a cookie: echo $_COOKIE["fontsize"]; Example

Sessions Session variables are a convenient way to keep track of users over different pageviews Kept as a cookie or propagated in the URL Starting a session: <?php session_start(); ?> <html>… Storing a session variable: <?php session_start(); $_SESSION['fontSizePref']=14; ?> Demo (also view cookies with firebug!): <?php session_start(); $_SESSION['count']++; echo "<h3>You've visited this page " . $_SESSION["count"] . " times.</h3>” ?>

Email "We've received your email; someone will get back to you soon…" <?php $to = "hplantin@calvin.edu"; $from = "leroy@calvin.edu"; $subject = "Good job!"; $message = "Just wanted to say…"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> demo

Database access Example <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con)   die('Could not connect: ' . mysql_error()); mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); while($row = mysql_fetch_array($result)) {   echo $row["FirstName"] ." ". $row["LastName"];   echo "<br />"; } mysql_close($con); ?>

What if… Web page: Server code: <form method=“GET” action=“process.php”> <input type=“text” name=“username”> Server code: $query = “SELECT * FROM users WHERE name=‘“ . $_GET[‘username’] . “’”; Select * from person where lastname="$webinput"

More trouble Select * from person where lastname="$webinput"

More trouble Select * from person where lastname="$webinput"

A Test… What happens if I log in to a server with the username hi' or 1=1— How about something like this? http://duck/index.asp?id=10 UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='admin_login'— How to prevent? Select * from person where lastname="$webinput"

SQL Injection Called an SQL Injection attack How to prevent? Filter inputs Parameterized queries

Parameterized input PHP example. Something similar can be done in all languages.

Input filtering Make sure input values are valid and safe ALWAYS FILTER ALL INPUT DATA! Example <?php $int = "I23"; if(!filter_var($int, FILTER_VALIDATE_INT))   echo("Integer is not valid"); else   echo("Integer is valid"); ?>

Sanitizing filters Sanitizing filters: remove harmful content FILTER_SANITIZE_STRING, …ENCODED, …SPECIAL_CHARS, …EMAL, …URL, …NUMBER_INT, …MAGIC_QUOTES [apply addslashes()] Validation filters FILTER_VALIDATE_INT, BOOLEAN, FLOAT, REGEXP, URL, EMAIL, IP

Ethical responsibility… How common are these attacks? Do you have any ethical responsibilities here?