Server-Side Application and Data Management IT IS 3105 (Spring 2010)

Slides:



Advertisements
Similar presentations
WordPress Installation for Beginners Sheila Bergman
Advertisements

UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
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.
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
XP Browser and Basics1. XP Browser and Basics2 Learn about Web browser software and Web pages The Web is a collection of files that reside.
Chapter 10 Managing State Information Using Sessions.
How Clients and Servers Work Together. Objectives Learn about the interaction of clients and servers Explore the features and functions of Web servers.
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.
CSE 154 LECTURE 13: SESSIONS. Expiration / persistent cookies setcookie("name", "value", expiration); PHP $expireTime = time() + 60*60*24*7; # 1 week.
Php cookies & sessions.
Browser and Basics Tutorial 1. Learn about Web browser software and Web pages The Web is a collection of files that reside on computers, called.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Cookies Set a cookie – setcookie() Extract data from a cookie - $_COOKIE Augment user authentication script with a cookie.
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.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
Week 9 PHP Cookies and Session Introduction to JavaScript.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
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.
Cookies & Session Web Technology
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
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.
Sessions in PHP – Page 1 of 13CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Sessions in PHP Reading: Williams.
Web Database Programming Week 7 Session Management & Authentication.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizard’s Guide to PHP by David Lash.
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
CP476 Internet Computing CGI1 Cookie –Cookie is a mechanism for a web server recall info of accessing of a client browser –A cookie is an object sent by.
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
PHP Session ISYS 475. Session The web server starts a session when a visitor visiting your web site and assigns a unique id, the session id for the session.
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.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
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.
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.
Sessions and cookies (part 2) MIS 3501, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/19/2015.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Programming for the Web Cookies & Sessions Dónal Mulligan BSc MA
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● / www,histpk.org Hidaya Institute of Science & Technology
Week 7 Server side programming PHP Scripting Language MySQL Database Apache Server IT4103 Web Programming
The need for persistence Consider these examples  Counting the number of “hits” on a website  i.e. how many times does a client load your web page source.
PHP Cookies What is a Cookie?
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
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.
Sessions and cookies (part 2)
ITM 352 Cookies.
Web Programming Language
Topics to be Covered: Sending an , Multipart Message,
Cookies and Sessions in PHP
Open Source Programming
14-мавзу. Cookie, сеанс, FTP и технологиялари
Cookies BIS1523 – Lecture 23.
Client / Session Identification Cookies
<?php require("header.htm"); ?>
Cookies Cookie :- A cookie is often used to identify a user. A cookie is often used to identify a user. A cookie is a small file that the server embeds.
Configuring Internet-related services
Web Programming Language
CSc 337 Lecture 27: Cookies.
PHP State.
Cookies and Sessions.
Web Programming Language
CSc 337 Lecture 25: Cookies.
Presentation transcript:

Server-Side Application and Data Management IT IS 3105 (Spring 2010) Lecture 23 Cookies, Sessions, FTP and Email

Cookies

Cookies What are they? Cookies reside on a particular client Cookies are, according to Netscape, "a general mechanism which server side connections (such as CGI scripts) can use to both store and retrieve information on the client side of the connection." Cookies reside on a particular client By browser This means I.E. has a different store for cookies than FireFox, etc.

Setting Cookies

To set a cookie: Notes: Name is required Rest are optional bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] ) Notes: Name is required Rest are optional Must be set before any HTML tags

Setting a Cookie Example <?php setcookie("message1", "Hello"); setcookie("message2", "there."); ?> <html> <head><title>Setting cookies></head> <body> <h1>A cookie has be set by PHP when creating this page</h1> <h2>The whole cookie is:</h2> <script> document.write(document.cookie) </script> </body> </html> Ch9/C9SetCookie.php

Getting Cookies

Cookie values kept in the global array: $_COOKIE Retrieve with traditional array functions echo $_COOKIE[‘cookie_name’];

Setting and Getting a Cookie <?php setcookie("message1", "Hello"); setcookie("message2", “again."); ?> <html> <head><title>Setting cookies></head> <body> <h1>A cookie has be set by PHP when creating this page</h1> <h2>Cookie has been set, click on link to view</h2> <a href="C9GetCookieGet.php">C9GetCookieGet.php</a> </body> </html> Ch9/C9SetCookie.php <html> <head><title>Getting cookies></head> <body> <h1>A cookie has be set by another web page</h1> <h2>Getting the Cookies:</h2> The cookies are: <?php if (isset($_COOKIE['message1'])) { echo "First cookie:" . $_COOKIE['message1']; } if (isset($_COOKIE['message2'])) echo "Second cookie:" . $_COOKIE['message2']; ?> </body> </html> Ch9/C9GetCookie.php

Setting Cookies Expiration Time

Expiring Cookies Cookies naturally expire after browser is exited bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] ) Cookies naturally expire after browser is exited ALL cookies for that browser! Can set a time for it to expire Time in seconds since Jan 1, 1970 Note: Javascipt uses milliseconds since 1/1/1970 Use time() to get the current time Add the “delay” to get the desired expiration

Cookie Expire Example: <?php setcookie("message1", "Hello"); setcookie("message2", "there.", time()+60); ?> <html> <head><title>Setting cookies></head> <body> <h1>A cookie has be set by PHP when creating this page</h1> <h2>The whole cookie is:</h2> <script> document.write(document.cookie) </script> <h3>message1 has no expiration</h3> <h3>message2 expires in 1 minute</h3> </body> </html> Ch9/C9CookieExpire1min.php

Deleting Cookies

Set the value to the null string (“”); bool setcookie ( string $name , string “” , int $expire = -1) Set the value to the null string (“”); Set the expire date to a negative time Triggers the browsers expiration function

Sessions

Sessions Information is kept on the server Information maintained from web page to web page Data kept and retrieved by name Session IDs can be kept in a cookie On the client Session can be: Cookie based Easier and safer Work with cookies disabled Has some potential for abuse

Storing Session Data

Creating and Using Session Data Creating a SESSION value Must start a session on the server to use it session_start(); For Cookie based sessions: Session must be started before any HTML output Use global array $_SESSION to set value Accessing a SESSION value Must start a session to use it Ditto on starting the session Use global array $_SESSION to retrieve value

Getting and Setting Sessions <?php session_start(); ?> <html> <head><title>Setting sessions</title></head> <body> <h1>Storing Data in Sessions</h1> <h2>Saving course information</h2> $_SESSION['name'] = "Server Side"; $_SESSION['number'] = "3105"; <br>Click on the link to read the session info on the next page:<br> <a href="C9GetSession.php">Go to C9GetSession.php</a> </body> </html> Ch9/C9SetSession.php <?php session_start(); ?> <html> <head><title>Getting session info</title></head> <body> <h1>Retriving Data in Sessions</h1> <h2>Getting course information</h2> <?php // assume the SESSION value is there echo "Name:".$_SESSION['name']; echo "\n<br>\n"; echo "Number:".$_SESSION['number']; <h2>Done</h2> </body> </html> Ch9/C9GetSession.php

Session Dumper <?php session_start(); ?> <html> <head><title>Dump Sessions</title></head> <body> <h1>Show all sessions</h1> print_r($_SESSION); <h2>Done</h2> </body> </html> Ch9/C9DumpSessions.php

Hit Counters

Hit Counters Many offered “free” from the internet To use --- --- or not to use? TANSTAFL!

Hit counters Use a session variable to keep track Check if ever sent If not “create” count set to 0 Else increment count

Hit Counter Track how often a web page is visited Problem 1: Session expires when all instances of the browser is closed How can this problem be fixed? Class discussion… Problem 2: <?php session_start(); ?> <html> <head><title>C9 Counter</title></head> <body> <h1>Example hit counter</h1> if (!isset($_SESSION['mycount'])) { echo "First time here!"; $_SESSION['mycount'] = 0; } else { $_SESSION['mycount']++; } echo "Count:".$_SESSION['mycount']; <h2>Done</h2> </body> </html> Ch9/C9Counter.php

Using Sessions Without Cookies

User blocking cookies? Enable use_trans_sid To use: By default is disabled (0) Set to 1 Set in the php.ini file To use: Set the $_SESSION as before Set PHPSESSID as a hidden input in a form Set the value to the session_id() The form will pass the hidden value to the next page The page can the access the session as before

Warnings Session id can be intercepted by “hackers” Capture the session for their use ITIS4221 teaches safe programming techniques to protect

Removing Data In Sessions

Remove data in Sessions After starting session Use unset unset($_SESSION[“session_id”]);

FTP

FTP File Transfer Protocol Note: FTP is fundamentally unsafe Transfers data from one computer to another Remote machine must have an FTP server running Local machine must have an FTP client running Defaults to port 21 Note: FTP is fundamentally unsafe Login process is “open” Data is “open” Anyone can see Use a secure ftp connection when using ftp_ssl_connect Use to get data from an FTP server The remote machine Not the browser client!

Using FTP

Using FTP Connect Log in Mandatory Optional parameters $connect = ftp_connect($host, $port, $timeout) Mandatory host Optional parameters port The port to use timeout how long before timing out Log in $result = ftp_login($connect, $uid, $pw)

FTP Getting a Directory Listing

Get a remote directory listing Get the remote machines directory listing Request listing for a directory Save in array array ftp_nlist ( resource $ftp_stream , string $directory ) Example dirArray$ = ftp_nlist($connect, “mydir”); Process the array Dump results var_dump($dirArray); Process with code foreach($dirArray as $value) { echo $value, “<br>”;}

FTP Downloading a File

Downloading Brings a file to the host machine bool ftp_get ( resource $ftp_stream , string $local_file , string $remote_file , int $mode [, int $resumepos = 0 ] ) Brings a file to the host machine Required FTP connection name for the file locally Note: can rename using a different name name of the file on the remote how to transer FTP_ASCII FTP_BINARY

FTP Uploading a File

Uploading Sends a file to the remote ftp client bool ftp_put ( resource $ftp_stream , string $remote_file , string $local_file , int $mode [, int $startpos = 0 ] ) Sends a file to the remote ftp client Required FTP connection name for the file locally Note: can rename using a different name name of the file on the remote how to transer FTP_ASCII FTP_BINARY

EMail

EMail Can send email from an html page Problems: What to do? <form … action=mailto:addr@url.com …> Problems: Client machine must have a configured email client installed Outlook Outlook Express Thunderbird Eudora What if the user only uses a hosted email service Gmail Yahoo No need for an email client What to do? Use the email client on the php host!

PHP and Email Must enable Email in the php.ini file Note: Windows and *IX version vary

Sending Email

Sending Email Uses the mail client on the server to send mail bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) Uses the mail client on the server to send mail

Sending Email with Headers

Headers Extra information cc: bcc: …

Sending Email with Attachments

Attachments Takes some extra work Read the file to attache chunk_split and base64_encode the data from the file Cram the result into the text of the email With instructions of how it is included and encoded