Lecture 6 Session Control and User Authentication. INLS 760 Web Databases Spring 2013 Rob Capra

Size: px
Start display at page:

Download "Lecture 6 Session Control and User Authentication. INLS 760 Web Databases Spring 2013 Rob Capra"

Transcription

1 Lecture 6 Session Control and User Authentication INLS 760 Web Databases Spring 2013 Rob Capra

2 HTML Forms and PHP PHP: lect2/form1.php echo "Hello, ". htmlspecialchars(strip_tags($_get['name'])); echo "<br>"; echo "You are in the course: ". htmlspecialchars(strip_tags($_get['course'])); 2

3 Simple PHP page protection Simple page protection lect6/onepage.php (based on Ch.16, p ) $user = $_POST['user']; $pass = $_POST['pass']; if (empty($user) empty($pass)) { You must log in to see this page.<p> <form method="post" action="onepage.php"> Username: <input type="text" name="user"><p> Password: <input type="password" name="pass"><p> <input type="submit" value="login"> </form> else if ($user=='inls760' && $pass=='foo') { echo "Here is the hidden page.<p>"; else { echo "Incorrect username / password."; Note 1: This is all done in one file. Note 2: What if $user='inls760' Instead of == Note suppresses any errors 3

4 User input Do NOT trust ANY user input How we handle user input depends on what we wish to do with it. Common things: Store in a database (e.g. name, address) Display in HTML (back to the user, or to other users) Compare against a stored value (e.g. logging in) 4

5 Sanitizing User Input if ($_GET['sortby']) { $sortby = $_GET['sortby']; else { $sortby = "itemnum"; echo "sortby = $sortby"; 5

6 Sanitizing User Input $sortby = "itemnum"; switch ($_GET['sortby']) { case "author": $sortby = "author"; break; default: $sortby = "itemnum"; echo "sortby = $sortby"; Four points: 1. Clear initialization of $sortby variable at the top of the code segment 2. switch statement avoids = versus == mistakes 3. Assigns $sortby a known value in each case 4. Includes a default in the switch QTP: Which assignment statement is last when there is no sortby passed through the GET? 6

7 myaddslashes() lect6/myaddslashes.php function myaddslashes($s,$db) { $retval = $s; if (get_magic_quotes_gpc()) { $retval = stripslashes($retval); $retval=mysql_real_escape_string($retval,$db); return $retval; See Best Practices: 7

8 When do we use...? mysql_real_escape_string() addslashes htmlentities html_specialchars() strip_tags()

9 Future Assignments Future Assignments starting with Project 3 Initialize ALL variables clearly at the top of code segments Appropriate use of addslashes, striptags, htmlentities Conditional code for magicquotes_gpc ON or OFF\ Should each have their own version of the records database (e.g. p4records, p5records, etc.) 9

10 Avoid using eval() PHP eval() evaluates its argument as PHP code and returns the result. X eval("\$foo = 1+1;"); echo $foo; As a general rule, NEVER use eval() Especially not with user input!!! 10

11 What is session control? HTTP is stateless So Session Control How do we keep track of users across multiple pages? Answer: Session control / management 11

12 Session control How? Session ID Unique key to identify each session (e.g. 8c6ea32b1) Web site example, visit sites, look at cookies/sids Cookies Small name-value pair of information stored at the client, placed by the server Can be used to store a session id Pass-along in URLs (get method) Alternate to storing SID in a cookie Pass SID in each URLs: foo.php?8c6ea32b1 Examples: Amazon includes the sessionid in the URL 12

13 Session control in practice Look at session and cookie information from several commercial web sites PHPSESSID 13

14 Session variables and PHP First, read (especially sessions and security): Look at session settings on ruby Start a session in PHP session_start(); Session variables In addition to the session id, you may want to store other information for use during a session PHP superglobal $_SESSION Stores variables across an entire session $_SESSION['foo'] = 760; 14

15 Session variables and PHP session_start(); $sid = session_id(); echo "The SID for this session is ". $sid. "<br>"; $_SESSION['itemsincart'] = 5; echo "itemsincart = ". $_SESSION['itemsincart']. "<br>"; <a href="session2.php">go to next session example page</a> lect6/session1.php lect6/session2.php session_start(); $sid = session_id(); echo "The SID for this session is ". $sid. "<br>"; echo "itemsincart = ". $_SESSION['itemsincart']. "<br>"; unset($_session['itemsincart']); $_SESSION = array(); session_destroy(); <a href="session3.php">go to next session example page</a> 15

16 Session variables and PHP lect6/session3.php session_start(); $sid = session_id(); echo "The SID for this session is ". $sid. "<br>"; echo "itemsincart = ". $_SESSION['itemsincart']. "<br>"; Problem: Session id is still stored QTP: Look at browser cookies should be able to see PHPSESSID, but why is that all that is stored? What about itemsincart? 16

17 Session variables and PHP Completely destroying sessions can get tricky Recall that session ids can be Stored in a cookie Passed along in the URLs To get rid of a session id when passing along can stop passing along To get rid of a session id when using cookies session_destroy() does not delete the session id cookie Must remove session id cookie manually Several approaches Cookies aren t really removed, but rather, they expire See: 17

18 Session variables and PHP session_start(); $sid = session_id(); echo "The SID for this session is ". $sid. "<br>"; $_SESSION['itemsincart'] = 5; echo "itemsincart = ". $_SESSION['itemsincart']. "<br>"; <a href="session2b.php">go to next session example page</a> lect6/session1b.php lect6/session2b.php session_start(); $sid = session_id(); unset($_session['itemsincart']); $_SESSION = array(); if (isset($_cookie[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); session_destroy(); echo "The SID for this session is ". $sid. "<br>"; echo "itemsincart = ". $_SESSION['itemsincart']. "<br>"; <a href="session3b.php">go to next session example page</a> Note that setcookie must happen *before* other output since it is part of the headers: 18

19 Session variables and PHP lect6/session3b.php session_start(); $sid = session_id(); echo "The SID for this session is ". $sid. "<br>"; echo "itemsincart = ". $_SESSION['itemsincart']. "<br>"; There are other approaches to handle the session id cookie See: 19

20 Sessions for User Accounts Sessions are a convenient way to handle user accounts for a web site Idea: Store account information in MySQL User logs in using a form Verify username and password Set session variables to indicate logged in 20

21 Encryption in PHP Safer alternative to storing account passwords in plain text Use a one-way hashing algorithm md5, sha1 Instead of if ($enteredpass == $plaintextstoredpass) Use this if (sha1($enteredpass) == $sha1storedpass) 21

22 Encryption in PHP PHP sha1() function lect6/sha1.php echo sha1('mypassword'); Output is: 91dfd9ddb4198affc5c194cd8ce6d338fde470e2 22

23 Using sha1 in PHP & MySQL lect6/sha1.php $plaintext = $argv[1]; $ciphertext = sha1($plaintext); echo "plaintext = ###". $plaintext. "###\n"; echo "ciphertext = ###". $ciphertext. "###\n"; echo "sha1('password') = ###". sha1('password'). "###\n"; // check in mysql with // select sha1('password'); In MySQL: select sha1('password'); 23

24 Set up user accounts in DB mysql> create table swusers -> (uid int unsigned not null auto_increment primary key, -> uname varchar(20), upass varchar(50), utype varchar(20)); mysql> insert into swusers values (NULL, 'luke', sha1('ekul'), 'jedi'); mysql> insert into swusers values (NULL, 'ben', sha1('neb'), 'jedi'); mysql> insert into swusers values (NULL, 'yoda', sha1('adoy'), 'jedimaster'); mysql> select * from swusers; uid uname upass utype luke cf3bda53706bd12c766d2e00c0f823d698101ca3 jedi 3 ben 33ec049c8ac6227a8869e91c3cdbbec90bbac265 jedi 4 yoda e12c0bef5a1409e7843fbab98fe4b176aee8441a jedimaster rows in set (0.00 sec) 24

25 Authentication + Session Control lect6/swcantina-home.php <h1>sw Cantina</h1> <form method="post" action="swcantina-login.php"> Username: <input type="text" name="fuser"><p> Password: <input type="password" name="fpass"><p> <input type="submit" value="login"> </form> 25

26 Login lect6/swcantina-login.php (part 1 of the file) if (isset($_post['fuser']) && isset($_post['fpass'])) { // user has provided a username & password, so try to log them in $fuser = $_POST['fuser']; $fpass = $_POST['fpass']; require "/export/home/r/rcapra/dbconnect.php"; //echo mysql_error($db); $query = 'select utype from swusers '. "where uname = '$fuser' ". "and upass = sha1('$fpass')"; //echo "query = $query". "<br>"; $result = mysql_query($query); //echo mysql_error($db); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { session_start(); $row = mysql_fetch_row($result); echo "###$row[0]###<br>"; $_SESSION['valid_user'] = $fuser; $_SESSION['user_type'] = $row[0]; mysql_close($db); 26

27 Login lect6/swcantina-login.php (part 2 of the file) <h1>login Page</h1> if (isset($_session['valid_user'])) { // user is logged in echo 'Welcome, '. $_SESSION['valid_user']. '<br>'; echo '<a href="swcantina-logout.php">logout</a><br>'; if ($_SESSION['user_type'] == 'jedi') { echo '<a href="swcantina-jedi.php">jedi only</a><br>'; echo '<a href="swcantina-jedimaster.php">jedi master only</a><br>'; if ($_SESSION['user_type'] == 'jedimaster') { echo '<a href="swcantina-jedi.php">jedi only</a><br>'; echo '<a href="swcantina-jedimaster.php">jedi master only</a><br>'; else { // user is not logged in if (isset($fuser)) { // tried to login, but failed echo "Problem logging in.<br>"; else { // not logged in echo "You are not logged in.<br>"; <h1>sw Cantina</h1>Please log in. <form method="post" action="swcantina-login.php"> Username: <input type="text" name="fuser"><p> Password: <input type="password" name="fpass"><p> <input type="submit" value="login"> </form> 27

28 if (isset($_post['fuser']) && isset($_post['fpass'])) { // user has provided a username and password, // so try to log them in $fuser = $_POST['fuser']; $fpass = $_POST['fpass']; require "/export/home/r/rcapra/dbconnect.php"; //echo mysql_error($db); $query = 'select utype from swusers. "where uname = '$fuser' ". "and upass = sha1('$fpass')"; //echo "query = $query". "<br>"; $result = mysql_query($query); //echo mysql_error($db); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { session_start(); $row = mysql_fetch_row($result); echo "###$row[0]###<br>"; $_SESSION['valid_user'] = $fuser; $_SESSION['user_type'] = $row[0]; mysql_close($db); <h1>login Page</h1> Login lect6/swcantina-login.php (whole file) if (isset($_session['valid_user'])) { // user is logged in echo 'Welcome, '. $_SESSION['valid_user']. '<br>'; echo '<a href="swcantina-logout.php">logout</a><br>'; if ($_SESSION['user_type'] == 'jedi') { echo '<a href="swcantina-jedi.php">jedi only</a><br>'; echo '<a href="swcantina-jedimaster.php">'; echo 'Jedi master only</a><br>'; if ($_SESSION['user_type'] == 'jedimaster') { echo '<a href="swcantina-jedi.php">jedi only</a><br>'; echo '<a href="swcantina-jedimaster.php">'; echo 'Jedi master only</a><br>'; else { // user is not logged in if (isset($fuser)) { // tried to login, but failed echo "Problem logging in.<br>"; else { // not logged in echo "You are not logged in.<br>"; <h1>sw Cantina</h1> Please log in. <form method="post" action="swcantina-login.php"> Username: <input type="text" name="fuser"><p> Password: <input type="password" name="fpass"><p> <input type="submit" value="login"> </form> 28

29 Standard dbconnection /export/home/r/rcapra/dbconnect.php -rw-r r-- $h = 'pearl.ils.unc.edu'; $u = 'webdb_1'; $p = 'yourpassword'; $dbname = 'webdb_1'; $db = mysql_connect($h,$u,$p) or die('could not connect'); mysql_select_db($dbname) or die ('Could not select db'); lect3/showdb2.php -rw-r r-- echo "SW Cantina Products<p>"; require "/export/home/r/rcapra/dbconnect.php"; $query = "select * from swcantina"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo $row['pname']. " ($". $row['price']. ") -- ". $row['pdesc']; echo "<p>"; 29

30 Debugging PHP Illustrate debugging swcantina-login.php session_start() warning about already output headers Why? extra line at end of dbconnect.php 30

31 lect6/swcantina-logout.php Logout session_start(); $old_user = $_SESSION['valid_user']; $_SESSION = array(); if (isset($_cookie[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); session_destroy(); <h1>logout</h1> if (!empty($old_user)) { echo "You are now logged out.<br>"; else { echo "You were not logged in.<br>"; <a href="swcantina-home.php>home page</a> 31

32 lect6/swcantina-jedi.php Protected Pages session_start(); if (isset($_session['valid_user']) && ($_SESSION['user_type'] == 'jedi')) { echo "Jedi can see this.<br>"; else { echo "You must log in as a Jedi to see this page.<br>"; lect6/swcantina-jedimaster.php session_start(); if (isset($_session['valid_user']) && ($_SESSION['user_type'] == 'jedimaster')) { echo "Jedi Masters can see this.<br>"; else { echo "You must log in as a Jedi Master to see this page.<br>"; 32

33 Mid-term exam Mid-term is Feb. 26, Man 208, from 6:00-7:30pm 15% of overall course grade Closed book, close note, closed computer May bring one 8.5 x11 sheet of paper with notes Format Warm-up questions (multiple choice, definitions) Short answer questions Thinking questions Write / complete / correct code Understand and apply a concept Material covered All lectures, readings, assignments, and exercises up to and including Feb

Lecture 5 Security and User Input. INLS 760 Web Databases Spring 2013 Rob Capra

Lecture 5 Security and User Input. INLS 760 Web Databases Spring 2013 Rob Capra Lecture 5 Security and User Input INLS 760 Web Databases Spring 2013 Rob Capra Security What data should be stored on a web server? HTTP logs? Users account information? Passwords? Possible harms Exposure

More information

home.php 1/1 lectures/6/src/ include.php 1/1 lectures/6/src/

home.php 1/1 lectures/6/src/ include.php 1/1 lectures/6/src/ home.php 1/1 3: * home.php 5: * A simple home page for these login demos. 6: * David J. Malan 8: * Computer Science E-75 9: * Harvard Extension School 10: */ 11: // enable sessions 13: session_start();

More information

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008.

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008. PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008. Outline. How cookies work. Cookies in PHP. Sessions. Databases. Cookies. Sometimes it is useful to remember a client when it comes

More information

ITS331 IT Laboratory I: (Laboratory #11) Session Handling

ITS331 IT Laboratory I: (Laboratory #11) Session Handling School of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University ITS331 Information Technology Laboratory I Laboratory #11: Session Handling Creating

More information

By the end of this section of the practical, the students should be able to:

By the end of this section of the practical, the students should be able to: By the end of this section of the practical, the students should be able to: Connecting to a MySQL database in PHP with the mysql_connect() and mysql_select_db() functions Trapping and displaying database

More information

WEB APPLICATION ENGINEERING II

WEB APPLICATION ENGINEERING II WEB APPLICATION ENGINEERING II Lecture #5 Umar Ibrahim Enesi Objectives Gain understanding of how Cookies and Sessions Work Understand the limitations of Sessions and Cookies Understand how to handle Session

More information

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Minor Subject

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Minor Subject Multimedia im Netz Online Multimedia Winter semester 2015/16 Tutorial 03 Minor Subject Ludwig- Maximilians- Universität München Online Multimedia WS 2015/16 - Tutorial 03-1 Today s Agenda Quick test Server

More information

Autopopulation; Session & Cookies

Autopopulation; Session & Cookies ; Session & Cookies CGT 356 Web Programming, Development, & Database Integration Lecture 5 Session array Use the Session array to store data that needs to be recalled on later pages $_SESSION[ foo ] Use

More information

SCRIPTING, DATABASES, SYSTEM ARCHITECTURE

SCRIPTING, DATABASES, SYSTEM ARCHITECTURE introduction to SCRIPTING, DATABASES, SYSTEM ARCHITECTURE WEB SERVICES III (advanced + quiz + A11) Claus Brabrand ((( brabrand@itu.dk ))) Associate Professor, Ph.D. ((( Software and Systems ))) IT University

More information

Lab 7 Introduction to MySQL

Lab 7 Introduction to MySQL Lab 7 Introduction to MySQL Objectives: During this lab session, you will - Learn how to access the MySQL Server - Get hand-on experience on data manipulation and some PHP-to-MySQL technique that is often

More information

EXPERIMENT- 9. Login.html

EXPERIMENT- 9. Login.html EXPERIMENT- 9 To write a program that takes a name as input and on submit it shows a hello page with name taken from the request. And it shows starting time at the right top corner of the page and provides

More information

You can also set the expiration time of the cookie in another way. It may be easier than using seconds.

You can also set the expiration time of the cookie in another way. It may be easier than using seconds. What is a Cookie? 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 a page with a browser, it will

More information

Introductory workshop on PHP-MySQL

Introductory workshop on PHP-MySQL Introductory workshop on PHP-MySQL Welcome to Global Certifications and Training from Rocky Sir Download all needed s/w from monster.suven.net Full Stack development : UI + Server Side 1 or more client

More information

COMP519 Web Programming Lecture 28: PHP (Part 4) Handouts

COMP519 Web Programming Lecture 28: PHP (Part 4) Handouts COMP519 Web Programming Lecture 28: PHP (Part 4) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

Daniel Pittman October 17, 2011

Daniel Pittman October 17, 2011 Daniel Pittman October 17, 2011 SELECT target-list FROM relation-list WHERE qualification target-list A list of attributes of relations in relation-list relation-list A list of relation names qualification

More information

WEB SECURITY: WEB BACKGROUND

WEB SECURITY: WEB BACKGROUND WEB SECURITY: WEB BACKGROUND CMSC 414 FEB 20 2018 A very basic web architecture Client Server Browser Web server (Private) Data Database DB is a separate entity, logically (and often physically) A very

More information

Database Connectivity using PHP Some Points to Remember:

Database Connectivity using PHP Some Points to Remember: Database Connectivity using PHP Some Points to Remember: 1. PHP has a boolean datatype which can have 2 values: true or false. However, in PHP, the number 0 (zero) is also considered as equivalent to False.

More information

PHP Development - Introduction

PHP Development - Introduction PHP Development - Introduction Php Hypertext Processor PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports many

More information

PHP State Maintenance (Cookies, Sessions, Hidden Inputs)

PHP State Maintenance (Cookies, Sessions, Hidden Inputs) PHP State Maintenance (Cookies, Sessions, Hidden Inputs) What is meant by state? The Hypertext Transfer Protocol (HTTP) is stateless. This means that each time a browser requests a page, a connection from

More information

IS 2150 / TEL 2810 Introduction to Security

IS 2150 / TEL 2810 Introduction to Security IS 2150 / TEL 2810 Introduction to Security James Joshi Professor, SIS Lecture 15 April 20, 2016 SQL Injection Cross-Site Scripting 1 Goals Overview SQL Injection Attacks Cross-Site Scripting Attacks Some

More information

User authentication, passwords

User authentication, passwords User authentication, passwords User Authentication Nowadays most internet applications are available only for registered (paying) users How do we restrict access to our website only to privileged users?

More information

Cookies and S essions 323

Cookies and S essions 323 Cookies and Sessions 9 The Hypertext Transfer Protocol (HTTP) is a stateless technology, meaning that each individual HTML page is an unrelated entity. HTTP has no method for tracking users or retaining

More information

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310 Warm up mini-lab Lab 1 - Functions Type in the following function definition and calls to the function. Test it and understand it. function myprint($str= No String Supplied ) // the argument is optional

More information

PHP. MIT 6.470, IAP 2010 Yafim Landa

PHP. MIT 6.470, IAP 2010 Yafim Landa PHP MIT 6.470, IAP 2010 Yafim Landa (landa@mit.edu) LAMP We ll use Linux, Apache, MySQL, and PHP for this course There are alternatives Windows with IIS and ASP Java with Tomcat Other database systems

More information

zend. Number: Passing Score: 800 Time Limit: 120 min.

zend. Number: Passing Score: 800 Time Limit: 120 min. 200-710 zend Number: 200-710 Passing Score: 800 Time Limit: 120 min Exam A QUESTION 1 Which of the following items in the $_SERVER superglobal are important for authenticating the client when using HTTP

More information

Lecture 8 Database Search. INLS 760 Web Databases Spring 2013 Rob Capra

Lecture 8 Database Search. INLS 760 Web Databases Spring 2013 Rob Capra Lecture 8 Database Search INLS 760 Web Databases Spring 2013 Rob Capra Search Basics Collection A collection of documents Document A collection of words Word Basic unit Stopwords: a, an, the, of, etc.

More information

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL. Hello everyone! Welcome to our PHP + MySQL (Easy to learn) E.T.L. free online course Hope you have installed your XAMPP? And you have created your forms inside the studio file in the htdocs folder using

More information

Web Programming. Dr Walid M. Aly. Lecture 10 PHP. lec10. Web Programming CS433/CS614 22:32. Dr Walid M. Aly

Web Programming. Dr Walid M. Aly. Lecture 10 PHP. lec10. Web Programming CS433/CS614 22:32. Dr Walid M. Aly Web Programming Lecture 10 PHP 1 Purpose of Server-Side Scripting database access Web page can serve as front-end to a database Ømake requests from browser, Øpassed on to Web server, Øcalls a program to

More information

exam. Number: Passing Score: 800 Time Limit: 120 min File Version: Zend Certified Engineer

exam. Number: Passing Score: 800 Time Limit: 120 min File Version: Zend Certified Engineer 200-710.exam Number: 200-710 Passing Score: 800 Time Limit: 120 min File Version: 1.0 200-710 Zend Certified Engineer Version 1.0 Exam A QUESTION 1 Which of the following items in the $_SERVER superglobal

More information

Lecture 7: Dates/Times & Sessions. CS 383 Web Development II Wednesday, February 14, 2018

Lecture 7: Dates/Times & Sessions. CS 383 Web Development II Wednesday, February 14, 2018 Lecture 7: Dates/Times & Sessions CS 383 Web Development II Wednesday, February 14, 2018 Date/Time When working in PHP, date is primarily tracked as a UNIX timestamp, the number of seconds that have elapsed

More information

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT. Chapter 7:- PHP Compiled By:- Assistant Professor, SVBIT. Outline Starting to script on server side, Arrays, Function and forms, Advance PHP Databases:-Basic command with PHP examples, Connection to server,

More information

CITS1231 Web Technologies. PHP s, Cookies and Session Control

CITS1231 Web Technologies. PHP  s, Cookies and Session Control CITS1231 Web Technologies PHP Emails, Cookies and Session Control Sending email with PHP We have looked at storing user information using files. Email messages can also be thought of as data streams, providing

More information

University of Washington, CSE 154 Homework Assignment 7: To-Do List

University of Washington, CSE 154 Homework Assignment 7: To-Do List University of Washington, CSE 154 Homework Assignment 7: To-Do List In this assignment you will write a web application for an online to-do list. The assignment tests your understanding of user login sessions

More information

PHP INTERVIEW QUESTION-ANSWERS

PHP INTERVIEW QUESTION-ANSWERS 1. What is PHP? PHP (recursive acronym for PHP: Hypertext Preprocessor) is the most widely used open source scripting language, majorly used for web-development and application development and can be embedded

More information

Introduction to PHP. Fulvio Corno, Laura Farinetti, Dario Bonino, Marco Aime 06/11/08

Introduction to PHP. Fulvio Corno, Laura Farinetti, Dario Bonino, Marco Aime 06/11/08 Introduction to PHP Fulvio Corno, Laura Farinetti, Dario Bonino, Marco Aime Goals Understand server-side architectures based on PHP Learn the syntax and the main constructs of the PHP language Design simple

More information

Lecture 2 Unix and PHP. INLS 523 Web Databases Spring 2013 Rob Capra

Lecture 2 Unix and PHP. INLS 523 Web Databases Spring 2013 Rob Capra Lecture 2 Unix and PHP INLS 523 Web Databases Spring 2013 Rob Capra Server-Side Scripting Server-side scripting Scripts run on the server Scripts return HTML to the client Apache Open-source Perl and PHP

More information

CS4604 Prakash Spring 2016! Project 3, HTML and PHP. By Sorour Amiri and Shamimul Hasan April 20 th, 2016

CS4604 Prakash Spring 2016! Project 3, HTML and PHP. By Sorour Amiri and Shamimul Hasan April 20 th, 2016 CS4604 Prakash Spring 2016! Project 3, HTML and PHP By Sorour Amiri and Shamimul Hasan April 20 th, 2016 Project 3 Outline 1. A nice web interface to your database. (HTML) 2. Connect to database, issue,

More information

Web accessible Databases PHP

Web accessible Databases PHP Web accessible Databases PHP October 16, 2017 www.php.net Pacific University 1 HTML Primer https://www.w3schools.com/html/default.asp HOME Introduction Basic Tables Lists https://developer.mozilla.org/en-

More information

Chapter 21 How to create secure web sites

Chapter 21 How to create secure web sites Chapter 21 How to create secure web sites Murach's PHP and MySQL, C21 2014, Mike Murach & Associates, Inc. Slide 1 Objectives Applied 1. Use a secure connection and the Secure Sockets Layer (SSL) protocol

More information

I n p u t. This time. Security. Software. sanitization ); drop table slides. Continuing with. Getting insane with. New attacks and countermeasures:

I n p u t. This time. Security. Software. sanitization ); drop table slides. Continuing with. Getting insane with. New attacks and countermeasures: This time Continuing with Software Security Getting insane with I n p u t sanitization ); drop table slides New attacks and countermeasures: SQL injection Background on web architectures A very basic web

More information

USQ/CSC2406 Web Publishing

USQ/CSC2406 Web Publishing USQ/CSC2406 Web Publishing Lecture 4: HTML Forms, Server & CGI Scripts Tralvex (Rex) Yeap 19 December 2002 Outline Quick Review on Lecture 3 Topic 7: HTML Forms Topic 8: Server & CGI Scripts Class Activity

More information

Lab 4: Basic PHP Tutorial, Part 2

Lab 4: Basic PHP Tutorial, Part 2 Lab 4: Basic PHP Tutorial, Part 2 This lab activity provides a continued overview of the basic building blocks of the PHP server-side scripting language. Once again, your task is to thoroughly study the

More information

Chapter 9. Managing State Information. Understanding State Information (continued) Understanding State Information 10/29/2011.

Chapter 9. Managing State Information. Understanding State Information (continued) Understanding State Information 10/29/2011. Chapter 9 Managing State Information PHP Programming with MySQL 2 nd Edition Objectives In this chapter, you will: Learn about state information Use hidden form fields to save state information Use query

More information

Zend Zend Certified PHP Developer. Download Full Version :

Zend Zend Certified PHP Developer. Download Full Version : Zend 200-550 Zend Certified PHP Developer Download Full Version : http://killexams.com/pass4sure/exam-detail/200-550 QUESTION: 209 What is the return value of the following code: substr_compare("foobar",

More information

PHP Security. Kevin Schroeder Zend Technologies. Copyright 2007, Zend Technologies Inc.

PHP Security. Kevin Schroeder Zend Technologies. Copyright 2007, Zend Technologies Inc. PHP Security Kevin Schroeder Zend Technologies Copyright 2007, Zend Technologies Inc. Disclaimer Do not use anything you learn here for nefarious purposes Why Program Securely? Your job/reputation depends

More information

GET /index.php HTTP/1.1 Host: User- agent: Mozilla/4.0

GET /index.php HTTP/1.1 Host:   User- agent: Mozilla/4.0 State management GET /index.php HTTP/1.1 Host: www.mtech.edu User- agent: Mozilla/4.0 HTTP/1.1 200 OK Date: Thu, 17 Nov 2011 15:54:10 GMT Server: Apache/2.2.16 (Debian) Content- Length: 285 Set- Cookie:

More information

COM1004 Web and Internet Technology

COM1004 Web and Internet Technology COM1004 Web and Internet Technology When a user submits a web form, how do we save the information to a database? How do we retrieve that data later? ID NAME EMAIL MESSAGE TIMESTAMP 1 Mike mike@dcs Hi

More information

PHP Introduction. Some info on MySQL which we will cover in the next workshop...

PHP Introduction. Some info on MySQL which we will cover in the next workshop... PHP and MYSQL PHP Introduction PHP is a recursive acronym for PHP: Hypertext Preprocessor -- It is a widely-used open source general-purpose serverside scripting language that is especially suited for

More information

PHP with data handling

PHP with data handling 171 Lesson 18 PHP with data handling Aim Objectives : To provide an introduction data handling with PHP : To give an idea about, What type of data you need to handle? How PHP handle the form data? 18.1

More information

COMP519: Web Programming Autumn 2015

COMP519: Web Programming Autumn 2015 COMP519: Web Programming Autumn 2015 In the next lectures you will learn What is SQL How to access mysql database How to create a basic mysql database How to use some basic queries How to use PHP and mysql

More information

CSc 337 Final Examination December 13, 2013

CSc 337 Final Examination December 13, 2013 On my left is: (NetID) MY NetID On my right is: (NetID) CSc 337 Final Examination December 13, 2013 READ THIS FIRST Read this page now but do not turn this page until you are told to do so. Go ahead and

More information

Understanding Basic SQL Injection

Understanding Basic SQL Injection Understanding Basic SQL Injection SQL injection (also known as SQLI) is a code injection technique that occurs if the user-defined input data is not correctly filtered or sanitized of the string literal

More information

Database Systems Fundamentals

Database Systems Fundamentals Database Systems Fundamentals Using PHP Language Arman Malekzade Amirkabir University of Technology (Tehran Polytechnic) Notice: The class is held under the supervision of Dr.Shiri github.com/arman-malekzade

More information

Solution of Exercise Sheet 5

Solution of Exercise Sheet 5 Foundations of Cybersecurity (Winter 16/17) Prof. Dr. Michael Backes CISPA / Saarland University saarland university computer science Solution of Exercise Sheet 5 1 SQL Injection Consider a website foo.com

More information

Produced by. Web Development. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Produced by. Web Development. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology Web Development Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie Sessions Web Development

More information

Lecture 13: MySQL and PHP. Monday, March 26, 2018

Lecture 13: MySQL and PHP. Monday, March 26, 2018 Lecture 13: MySQL and PHP Monday, March 26, 2018 MySQL The Old Way In older versions of PHP, we typically used functions that started with mysql_ that did not belong to a class For example: o o o o mysql_connect()

More information

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks Abhay K. Kolhe Faculty, Dept. Of Computer Engineering MPSTME, NMIMS Mumbai, India Pratik Adhikari

More information

John Valance JValance Consulting

John Valance JValance Consulting John Valance JValance Consulting jvalance@sprynet.com Copyright 2011-2012: John Valance Independent consultant o Specialty is helping iseries shops develop web applications, and related skills o Training,

More information

Systems Programming & Scripting

Systems Programming & Scripting Systems Programming & Scripting Lecture 19: Database Support Sys Prog & Scripting - HW Univ 1 Typical Structure of a Web Application Client Internet Web Server Application Server Database Server Third

More information

Comp 519: Web Programming Autumn 2015

Comp 519: Web Programming Autumn 2015 Comp 519: Web Programming Autumn 2015 Advanced SQL and PHP Advanced queries Querying more than one table Searching tables to find information Aliasing tables PHP functions for using query results Using

More information

Web Security: Vulnerabilities & Attacks

Web Security: Vulnerabilities & Attacks Computer Security Course. Web Security: Vulnerabilities & Attacks Type 2 Type 1 Type 0 Three Types of XSS Type 2: Persistent or Stored The attack vector is stored at the server Type 1: Reflected The attack

More information

(Frequently Asked Questions)

(Frequently Asked Questions) (Frequently Asked Questions) Aptech Ltd. Version 1.0 Page 1 of 9 Table of Contents S# Question 1. How do you create sub domains using PHP? 2. What is the difference between echo and print statements in

More information

Final Exam. IT 3203 Introduction to Web Development. Rescheduling Final Exams. PHP Arrays. Arrays as Hashes. Looping over Arrays

Final Exam. IT 3203 Introduction to Web Development. Rescheduling Final Exams. PHP Arrays. Arrays as Hashes. Looping over Arrays IT 3203 Introduction to Web Development Introduction to PHP II April 5 Notice: This session is being recorded. Copyright 2007 by Bob Brown Final Exam The Registrar has released the final exam schedule.

More information

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 3

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 3 Jackson State University Department of Computer Science CSC 439-01/539-02 Advanced Information Security Spring 2013 Lab Project # 3 Use of CAPTCHA (Image Identification Strategy) to Prevent XSRF Attacks

More information

CN Assignment I. 1. With an example explain how cookies are used in e-commerce application to improve the performance.

CN Assignment I. 1. With an example explain how cookies are used in e-commerce application to improve the performance. CN Assignment I 1. With an example explain how cookies are used in e-commerce application to improve the performance. In an e-commerce application, when the user sends a login form to the server, the server

More information

A QUICK GUIDE TO PROGRAMMING FOR THE WEB. ssh (then type your UBIT password when prompted)

A QUICK GUIDE TO PROGRAMMING FOR THE WEB. ssh (then type your UBIT password when prompted) A QUICK GUIDE TO PROGRAMMING FOR THE WEB TO GET ACCESS TO THE SERVER: ssh Secure- Shell. A command- line program that allows you to log in to a server and access your files there as you would on your own

More information

COPYRIGHTED MATERIAL. User Registration. Plan the Directory Layout

COPYRIGHTED MATERIAL. User Registration. Plan the Directory Layout User Registration Offering account registration and user log ins is a great way of giving users a sense of individuality and serving tailored content. Such authentication is often at the very heart of

More information

Web Programming with PHP

Web Programming with PHP We know that we can use HTML to build websites, but websites built using pure HTML suffer from a serious limitation. Imagine we want to create a website that displays the current time in Cambridge, MA,

More information

CICS 515 b Internet Programming Week 2. Mike Feeley

CICS 515 b Internet Programming Week 2. Mike Feeley CICS 515 b Internet Programming Week 2 Mike Feeley 1 Software infrastructure stuff MySQL and PHP store files in public_html run on remote.mss.icics.ubc.ca access as http://ws.mss.icics.ubc.ca/~username/...

More information

How to Set Up a Custom Challenge Page for Authentication

How to Set Up a Custom Challenge Page for Authentication How to Set Up a Custom Challenge Page for Authentication Setting up a custom challenge page is a three step process: 1. Create a custom challenge page. Deploy the created custom challenge page on your

More information

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment. web.py Tutorial Tom Kelliher, CS 317 1 Acknowledgment This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment. 2 Starting So you know Python and want to make

More information

School of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University

School of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University School of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University ITS331 Information Technology Laboratory I Laboratory #8: PHP & Form Processing II Objective:

More information

Module 3 MySQL Database. Database Management System

Module 3 MySQL Database. Database Management System Module 3 MySQL Database Module 3 Contains 2 components Individual Assignment Group Assignment BOTH are due on Mon, Feb 19th Read the WIKI before attempting the lab Extensible Networking Platform 1 1 -

More information

How to create secure web sites

How to create secure web sites 2017, Mike Murach & Associates, Inc. 1/20/2019 A request made with a secure connection Chapter 21 How to create secure web sites The URL starts with https A lock icon is displayed C21, Slide 1 2017, Mike

More information

This is CS50. Harvard College Fall Quiz 1 Answer Key

This is CS50. Harvard College Fall Quiz 1 Answer Key Quiz 1 Answer Key Answers other than the below may be possible. Know Your Meme. 0. True or False. 1. T 2. F 3. F 4. F 5. T Attack. 6. By never making assumptions as to the length of users input and always

More information

Web Programming TL 9. Tutorial. Exercise 1: String Manipulation

Web Programming TL 9. Tutorial. Exercise 1: String Manipulation Exercise 1: String Manipulation Tutorial 1) Which statements print the same thing to the screen and why? echo "$var"; value of $var echo '$var'; the text '$var' echo $var ; value of $var 2) What is printed

More information

WEB PROGRAMMING SCV1223. PHP : Authentication Example. Dr. Md Sah bin Hj Salam En. Jumail bin Taliba

WEB PROGRAMMING SCV1223. PHP : Authentication Example. Dr. Md Sah bin Hj Salam En. Jumail bin Taliba WEB PROGRAMMING SCV1223 PHP : Authentication Example Dr. Md Sah bin Hj Salam En. Jumail bin Taliba Topics Form Handling Redirection Connecting to Database User Authentication Session Authentication Case

More information

Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a

Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a LAMP on Linux Working Remotely Introduction to web programming

More information

Advanced Web Technology 10) XSS, CSRF and SQL Injection

Advanced Web Technology 10) XSS, CSRF and SQL Injection Berner Fachhochschule, Technik und Informatik Advanced Web Technology 10) XSS, CSRF and SQL Injection Dr. E. Benoist Fall Semester 2010/2011 1 Table of Contents Cross Site Request Forgery - CSRF Presentation

More information

ASP.NET State Management Techniques

ASP.NET State Management Techniques ASP.NET State Management Techniques This article is for complete beginners who are new to ASP.NET and want to get some good knowledge about ASP.NET State Management. What is the need of State Management?

More information

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11 Attacks Against Websites Tom Chothia Computer Security, Lecture 11 A typical web set up TLS Server HTTP GET cookie Client HTML HTTP file HTML PHP process Display PHP SQL Typical Web Setup HTTP website:

More information

IERG 4210 Tutorial 08

IERG 4210 Tutorial 08 IERG 4210 Tutorial 08 Securing web page (II): - In principle: Cookie related security issues - In practice: Point by point checklist for Phase 4A Shizhan Zhu Logistics Content for today: Provide sample

More information

IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population

IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population In this lab, your objective is to learn the basics of creating and managing a DB system. One way to interact with the DBMS (MySQL)

More information

Web Security, Summer Term 2012

Web Security, Summer Term 2012 Table of Contents IIG University of Freiburg Web Security, Summer Term 2012 Cross Site Scripting - XSS Dr. E. Benoist Sommer Semester Presentation: Inject Javascript in a Page Javascript for manipulating

More information

Web Security, Summer Term 2012

Web Security, Summer Term 2012 IIG University of Freiburg Web Security, Summer Term 2012 Cross Site Scripting - XSS Dr. E. Benoist Sommer Semester Web Security, Summer Term 2012 5 Cross Site Scripting 1 Table of Contents Presentation:

More information

Submitting forms (client-side)

Submitting forms (client-side) Client/Server Submitting forms (client-side) Submitting forms (client-side) Submitting forms (client-side) submit.php $len = strlen($_post["password"]); $name = $_POST["name"]; print "Welcome ". $name;

More information

PHP. M hiwa ahamad aziz Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz)

PHP. M hiwa ahamad aziz  Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz) PHP M hiwa ahamad aziz www.raparinweb.com Raparin univercity 1 Server-Side Programming language asp, asp.net, php, jsp, perl, cgi... 2 Of 68 Client-Side Scripting versus Server-Side Scripting Client-side

More information

Introduction. Server-side Techniques. Introduction. 2 modes in the PHP processor:

Introduction. Server-side Techniques. Introduction. 2 modes in the PHP processor: Introduction Server-side Techniques PHP Hypertext Processor A very popular server side language on web Code embedded directly into HTML documents http://hk2.php.net/downloads.php Features Free, open source

More information

Security and Privacy. SWE 432, Fall 2016 Design and Implementation of Software for the Web

Security and Privacy. SWE 432, Fall 2016 Design and Implementation of Software for the Web Security and Privacy SWE 432, Fall 2016 Design and Implementation of Software for the Web Today Security What is it? Most important types of attacks Privacy For further reading: https://www.owasp.org/index.php/

More information

P2_L12 Web Security Page 1

P2_L12 Web Security Page 1 P2_L12 Web Security Page 1 Reference: Computer Security by Stallings and Brown, Chapter (not specified) The web is an extension of our computing environment, because most of our daily tasks involve interaction

More information

PHP 5 if...else...elseif Statements

PHP 5 if...else...elseif Statements PHP 5 if...else...elseif Statements Conditional statements are used to perform different actions based on different conditions. PHP Conditional Statements Very often when you write code, you want to perform

More information

Adding A PHP+MySQL Hit Counter to your Website

Adding A PHP+MySQL Hit Counter to your Website Adding A PHP+MySQL Hit Counter to your Website Setting up MySQL First off, decide what you want to keep track of. In this case, let s commit to tracking total number of hits on each of a number of web

More information

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang WEB SECURITY WORKSHOP TEXSAW 2014 Presented by Solomon Boyd and Jiayang Wang Introduction and Background Targets Web Applications Web Pages Databases Goals Steal data Gain access to system Bypass authentication

More information

Web Programming 4) PHP and the Web

Web Programming 4) PHP and the Web Web Programming 4) PHP and the Web Emmanuel Benoist Fall Term 2013-14 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1 PHP a language for Web applications Presentation

More information

This slide shows the OWASP Top 10 Web Application Security Risks of 2017, which is a list of the currently most dangerous web vulnerabilities in

This slide shows the OWASP Top 10 Web Application Security Risks of 2017, which is a list of the currently most dangerous web vulnerabilities in 1 This slide shows the OWASP Top 10 Web Application Security Risks of 2017, which is a list of the currently most dangerous web vulnerabilities in terms of prevalence (how much the vulnerability is widespread),

More information

HTTP Protocol and Server-Side Basics

HTTP Protocol and Server-Side Basics HTTP Protocol and Server-Side Basics Web Programming Uta Priss ZELL, Ostfalia University 2013 Web Programming HTTP Protocol and Server-Side Basics Slide 1/26 Outline The HTTP protocol Environment Variables

More information

CMPS 401 Survey of Programming Languages

CMPS 401 Survey of Programming Languages CMPS 401 Survey of Programming Languages Programming Assignment #4 PHP Language On the Ubuntu Operating System Write a PHP program (P4.php) and create a HTML (P4.html) page under the Ubuntu operating system.

More information

Project 2: Web Security

Project 2: Web Security EECS 388 September 30, 2016 Intro to Computer Security Project 2: Web Security Project 2: Web Security This project is due on Thursday, October 13 at 6 p.m. and counts for 8% of your course grade. Late

More information

SMS GATEWAY API INTEGRATION GUIDE

SMS GATEWAY API INTEGRATION GUIDE SMS GATEWAY API INTEGRATION GUIDE For PHP Developers Are you a developer or bulk SMS reseller? You can interface your application, website or system with our 247 reliable messaging gateway by using our

More information

CSC309: Introduction to Web Programming. Lecture 8

CSC309: Introduction to Web Programming. Lecture 8 CSC309: Introduction to Web Programming Lecture 8 Wael Aboulsaadat Front Layer Web Browser HTTP Request Get http://abc.ca/index.html Web (HTTP) Server HTTP Response .. How

More information