all e commerce
TRANSCRIPT
-
8/3/2019 All e Commerce
1/386
INTRODUCTION TO PHP
-
8/3/2019 All e Commerce
2/386
Dynamic Web Sites
Dynamic Web Sites are flexible, accuratelydescribes as applicationsthan merely sites: Respond to different parameters (for example,
the time of day or the version of the visitorsWeb browser Have a memory allowing user registration &
login Involve HTML forms, so that people can perform
searches, provide feedback, etc Often have interfaces where administrators can
manage the sites content Easier to maintain, upgrade and build open
-
8/3/2019 All e Commerce
3/386
What is PHP?
PHP stands for PHP: HypertextPreprocessor
PHP is a server-side scripting language, likeASP
PHP scripts are executed on the server PHP supports many databases (MySQL,
Informix, Oracle, Sybase, Solid,
PostgreSQL, Generic ODBC, etc.) PHP is an open source software (OSS) PHP is free to download and use
-
8/3/2019 All e Commerce
4/386
Php.net
Figure 1: The home page for PHP
-
8/3/2019 All e Commerce
5/386
What is a PHP File?
PHP files may contain text, HTML tagsand scripts
PHP files are returned to the browseras plain HTML
PHP files have a file extension of
".php", ".php3", or ".phtml"
-
8/3/2019 All e Commerce
6/386
Why PHP?
PHP runs on different platforms(Windows, Linux, Unix, etc.)
PHP is compatible with almost allservers used today (Apache, IIS, etc.)
PHP is FREE to download from the
official PHP resource: www.php.net PHP is easy to learn and runs
efficiently on the server side
-
8/3/2019 All e Commerce
7/386
Where to Start?
Install an Apache server on a Windowsor Linux machine
Install PHP on a Windows or Linuxmachine
Install MySQL on a Windows or Linux
machine Or download FoxServ/EasyPHP
-
8/3/2019 All e Commerce
8/386
PHP Installation
Download PHP
http://www.php.net/downloads.php
Download MySQL Database
http://www.mysql.com/downloads/index.html
Download Apache Server
http://httpd.apache.org/download.cgi
-
8/3/2019 All e Commerce
9/386
What can PHP do?
Server-side scripting. You need to run the webserver, with a connected PHP installation. You canaccess the PHP program output with a webbrowser, viewing the PHP page through the server.
Command line scripting. You can make a PHPscript to run it without any server or browser.
Writing desktop applications. Ability to writecross-platform applications this way. PHP-GTK isan extension to PHP, not available in the maindistribution.
-
8/3/2019 All e Commerce
10/386
Basic syntax
To place PHP code within HTMLdocument, use
Save the file as .php
Run the file in web browser
http://localhost/filename.php
-
8/3/2019 All e Commerce
11/386
Sending data to web browser
Language constructs in PHP to displaymessage echo()
print ()
For example,
Will display: This was done using PHP
-
8/3/2019 All e Commerce
12/386
PHP, HTML & White Space
There are 3 areas where you can affectspacing :
in your PHP scripts In HTML source
In the rendered Web page
PHP is generally white space insensitive,
meaning that you can space out your codeto make your scripts more legible.
-
8/3/2019 All e Commerce
13/386
To create white space
To alter the spacing of the finished Webpage, use the HTML tags
(linebreak) and
(paragraph). To alter the spacing of the HTML sourcecreated with PHP: Use echo() orprint() over the course of
several lines Use the newline character (\n) within the double
quotation marks.
-
8/3/2019 All e Commerce
14/386
Writing comments in PHP
PHP supports three comment types: # This is a comment
// This is also a comment
/* This is a longer comment
that spans two lines */
-
8/3/2019 All e Commerce
15/386
Variables
PHP syntactical rules for creatingvariables:
A variables name (identifier) must startwith a dollar sign ($), for example $name
Can contain combination of strings,numbers & underscore ($my_report1)
First character after dollar sign ($) mustbe either a letter or an underscore (itcannot be a number)
-
8/3/2019 All e Commerce
16/386
Variables
Variable names in PHP are case-sensitive.
Variables can be assigned using theequal sign (=)
-
8/3/2019 All e Commerce
17/386
Variables: Strings
A string is a quoted chunk of letters, numbers,spaces, punctuations, etc. E.g. Ali
In my mind 1000
9 july 1978
Strings are case sensetive so $Welcome_Text isnot the same as $welcome_text
When assigning numbers to strings you do notneed to include the quotes so:
$user_id = 987would be allowed.
-
8/3/2019 All e Commerce
18/386
Outputting Variables
To display a variable on the screen uses exactly the samecode as to display text but in a slightly different form. Thefollowing code would display your welcome text:
As you can see, the only major difference is that you do notneed the quotation marks if you are printing a variable.
String variables are created and their values sent to the Webbrowser in this script
http://strings.txt/http://strings.txt/ -
8/3/2019 All e Commerce
19/386
Concatenating strings
$city = Ipoh;
$state = Perak
$address = $city . $state ;Will display: IpohPerak
To improve:
$address = $city . , .$state ; Add a comma and a space
-
8/3/2019 All e Commerce
20/386
Using numbers
Valid number-type variables can belike: 8, 3.14, 109080808, -4.524
To format the number into thousandsand round it to two decimal places:
$total = number_format ($total, 2);
-
8/3/2019 All e Commerce
21/386
Understanding Functions
Function: subroutine/individualstatements grouped into a logical unit
that performs specific task. To execute a function, must invoke or
callit from somewhere in your script.
The statement that calls a function isreferred to as a function callandconsists of the function name followedby any data of the function needs.
-
8/3/2019 All e Commerce
22/386
Understanding Functions(cont)
Arguments / Actual parameters: The data(which you place in parentheses following
the function name). Passing arguments:Sending data to a
called function.
Many functions generate, or return, some
sort of a value that you can use in yourscript.
E.g. round() function that rounds a
decimal value to the nearest whole number.
-
8/3/2019 All e Commerce
23/386
round() function
You pass a number as an argument to theround()function, which calculates andreturns the nearest whole number.
The following statements calls theround()function and passes to it a value of3.556.
The round()function calculates andreturns a value of 4, which is then displayedwith an echo statement.
-
8/3/2019 All e Commerce
24/386
round() function
Many functions can accept multiple arguments,which you separate with commas.
The following statements calls the round()
function and then passes to it a first argument of3.556 and a second argument of 2.
The round() function calculates and returns a
value of 3.56 (rounded to two decimal places)
-
8/3/2019 All e Commerce
25/386
Constants
Constants are a specific data type in PHP,that unlike variables, retain their initial value
throughout the course of a script. You cant change the value of a constant
once it has been set.
Constants can be assigned any single value
a number or a string of characters.
-
8/3/2019 All e Commerce
26/386
Defining Constants
A constant contains information that doesnot change during the course of program
execution. Common practice to use all uppercase
letters for constant names.
Use define( ) function to create constant. define(CONSTANT_NAME, value);
define(DEFAULT_LANGUAGE, Malay);
define(VOTING_AGE, 18);
-
8/3/2019 All e Commerce
27/386
Defining Constants (cont)
By default, constant names are casesensitive, but you can make constant
names case insensitive by passing aBoolean value of TRUE as thirdargument to the define function.
define(DEFAULT_LANGUAGE,Malay, TRUE);
-
8/3/2019 All e Commerce
28/386
Defining Constants (cont)
You can pass a constant name to theecho statement on the same manner
as you pass a variable name, butwithout the dollar sign.
echo
The legal voting age is ,VOTING_AGE, .
; -
8/3/2019 All e Commerce
29/386
Data TypesData Type Description
Integernumbers
The set of all positive and negativenumbers and zero, with no decimalplaces
Floating pointnumbers
Positive or negative numbers withdecimal places or numbers writtenusing exponential notation
Boolean A logical value of true or false
String Text such as Hello World
NULL An empty value, also referred ti as aNULL value
Numericdata types
-
8/3/2019 All e Commerce
30/386
Loosely Typed ProgrammingLanguages
Programming languages that do not requireyou to declare the data types of variables
are called loosely typed programminglanguages.
Loose typing is also known as dynamictyping because the data types for a variable
can change after it has been declared. In PHP, you are not required to declare the
type of variables, in fact you are not allowedto do so.
-
8/3/2019 All e Commerce
31/386
Data Types (cont)
$ChangingVar = Hello World; //
String
$ChangingVar = 8; // IntegerNumber
$ChangingVar = 5.367; // Floating
point
$ChangingVar = TRUE; // Boolean
$ChangingVar = NULL; // NULL
-
8/3/2019 All e Commerce
32/386
Single vs Double QuotationMarks
Using double quotation marks:echo "You are purchasing $quantity
widget(s) at a cost of \$$price each.With tax, the total comes to
\$$total.\n";
Using single quotation marksecho 'You are purchasing $quantity
widget(s) at a cost of \$$price each.With tax, the total comes to
\$$total.\n';
The script to demonstrate the difference between using single anddouble quotation marks
Single vs Double Quotation Marks
http://quotes.txt/http://quotes.txt/ -
8/3/2019 All e Commerce
33/386
cont
Single vs Double Quotation Marks
-
8/3/2019 All e Commerce
34/386
-
8/3/2019 All e Commerce
35/386
PROGRAMMING WITH PHP
-
8/3/2019 All e Commerce
36/386
Overview
Creating an HTML Form
Handling an HTML Form
Managing Magic Quotes
Conditionals & Operators
Validating Form Data
Arrays
-
8/3/2019 All e Commerce
37/386
Creating an HTML Form
Managing HTML forms with PHP is a 2step process:
Create the HTML form An HTML form is created using the form tags
and various input types.
Create the corresponding script that willreceive and process the form data
Form
http://form.htm/http://form.txt/http://form.txt/http://form.htm/ -
8/3/2019 All e Commerce
38/386
PHP Forms and User Input
PHP Form Handling The most important thing to notice when dealing with HTML forms and
PHP is that any form element in an HTML page will automatically beavailable to your PHP scripts.
Form example:
Name: Age:
PHP Forms and User Input
-
8/3/2019 All e Commerce
39/386
cont
The "welcome.php" file looks like this:
Welcome .
You are years old. A sample output of the above script may be:
Welcome John.You are 28 years old.
Example of PHP script to handle form
PHP Forms and User Input
http://handleform.txt/http://handleform.txt/http://handleform.txt/http://handleform.txt/ -
8/3/2019 All e Commerce
40/386
$_REQUEST
$_REQUEST is a special variable type
in PHP.
It stores all of the data sent to PHPpage through either the GET or POST
methods, as well as data accessible in
cookies.
-
8/3/2019 All e Commerce
41/386
PHP $_GET Function
The built-in $_GET function is used tocollect values from a form sent with
method="get".
Information sent from a form with the
GET method is visible to everyone (itwill be displayed in the browser'saddress bar) and has limits on the
amount of information to send (max.
-
8/3/2019 All e Commerce
42/386
Example of GET method
When the user clicks the "Submit" button, the URL sent to the server could looksomething like this:
The "welcome.php" file can now use the $_GET function to collect form data (the
names of the form fields will automatically be the keys in the $_GET array):
-
8/3/2019 All e Commerce
43/386
When to use method=GET"?
When using method="get" in HTML forms, allvariable names and values are displayed in theURL.
Note: This method should not be used whensending passwords or other sensitive information!
However, because the variables are displayed inthe URL, it is possible to bookmark the page. Thiscan be useful in some cases.
Note: The get method is not suitable for largevariable values; the value cannot exceed 100characters.
-
8/3/2019 All e Commerce
44/386
PHP $_POST Function
The built-in $_POST function is used to collectvalues from a form sent with method="post".
Information sent from a form with the POST method
is invisible to others and has no limits on theamount of information to send.
Note: However, there is an 8 Mb max size for thePOST method, by default (can be changed by
setting the post_max_size in the php.ini file).
-
8/3/2019 All e Commerce
45/386
Example of $_POST Function
When the user clicks the "Submit" button, the URL will look like this:
The "welcome.php" file can now use the $_POST function to collectform data (the names of the form fields will automatically be the keys inthe $_POST array):
-
8/3/2019 All e Commerce
46/386
When to use method="post"?
Information sent from a form with thePOST method is invisible to others and
has no limits on the amount ofinformation to send.
However, because the variables are
not displayed in the URL, it is notpossible to bookmark the page
-
8/3/2019 All e Commerce
47/386
$_REQUEST
If the PHP scripts show blank spaceswhere the variables should have
printed out, it means that the variablehave no values. Likely causes:
Misspelled or mis-capitalized the variable
names $_REQUEST is not available because
youre using an outdated version of PHP
-
8/3/2019 All e Commerce
48/386
Managing Magic Quotes
When Magic Quotes is enables, it willautomatically escape single and
double quotation marks in the valuesof variables.
In PHP, there are 2 types of Magic
Quotes magic_quotes_gpc: Applies to form,
URL & cookie data (gpc stands for get,post, cookie)
ma ic uotes runtime: A lies to data
-
8/3/2019 All e Commerce
49/386
Managing Magic Quotes
-
8/3/2019 All e Commerce
50/386
g g g
Managing Magic Quotes
-
8/3/2019 All e Commerce
51/386
The apostrophe entered in the form was escaped
automatically by PHP, generating unseemly results
-
8/3/2019 All e Commerce
52/386
To adjust Magic Quotes
Open handle_form.php
Change the first & third variable
assignment lines to$name=stripslashes($_REQUEST[nam
e]);
$comments=stripslashes($_REQUEST[comments]);
http://handle_form.txt/http://handle_form.txt/ -
8/3/2019 All e Commerce
53/386
Conditionals & Operators
PHPs three primary terms for creatingconditionals are if, else and
elseif (which can also be written astwo words else if)
IF conditions
if (condition) {//DO something!
}
-
8/3/2019 All e Commerce
54/386
If else
if (condition) {
//DO something!
} else }
//DO something else
}
-
8/3/2019 All e Commerce
55/386
if elseif
if (condition) {
//DO something!
} elseif (condition2) {
//DO something else
} else {
//DO something different
}
-
8/3/2019 All e Commerce
56/386
cont
A condition can be true in PHP for anynumber of reasons. These are
common true conditions: $var, if $var has a value other than 0, an
empty string, or NULL
isset($var),if $var has any value
other than NULL, including 0 or an emptystring
TRUE, true, True, etc
-
8/3/2019 All e Commerce
57/386
isset($var)
This function checks if a variable isset, meaning that it has a value other
than NULL. Example:
if (isset($_REQUEST['gender'])) {
$gender = $_REQUEST['gender'];} else {
$gender = NULL;
}
Form Validation
http://isset.txt/http://isset.txt/ -
8/3/2019 All e Commerce
58/386
Form Validation
The first aim of form validation isensuring that something was entered
or selected in form elements. The second goal is to ensure that
submitted data is of the right type
(numeric, string, etc) or a specificacceptable value (like &gender beingequal to either F or M.
Form Validation
-
8/3/2019 All e Commerce
59/386
cont
Validating form data requires the use of conditionalsand any number of functions, operators &expressions.
One common function to be used is isset(),which tests if a variable has a value (including 0,FALSE, or an empty string, but not NULL).
One problem with isset()function is that anempty string tests as TRUE, meaning that its not
effective way to validate text inputs and text boxesfrom an HTML form.
Form Validation
-
8/3/2019 All e Commerce
60/386
cont
To check that a user typed somethinginto textual elements like name, email,
and comments you can use theempty() function.
It checks if a variable has an empty
value: an empty string, 0, null orFALSE
Script to validate form
http://validateform.txt/http://validateform.txt/ -
8/3/2019 All e Commerce
61/386
-
8/3/2019 All e Commerce
62/386
Array: Indexed Indexed arrays use
numbers as the keys.
Example:
Array Example1: $artists
KEY VALUE
0 Rihanna
1 Madonna
2 Sting3 Daughtry
4 Maroon5
-
8/3/2019 All e Commerce
63/386
Array: Associative
Associative arrays
use strings as thekeys.
Array Example1: $states
KEY VALUE
KL Kuala Lumpur
PP Pulau Pinang
PRK Perak
KEL KELANTAN
-
8/3/2019 All e Commerce
64/386
To retrieve value from an array
To retrieve a specific value from anarray, you refer to the array name first,
followed by the key, in squarebrackets:echo $artists[2];//Sting
echo $states [KL]; //Kuala Lumpur Note that array keys are used like other values in PHP:
number (e.g., 2) are never quoted, whereas strings (KL) mustbe.
-
8/3/2019 All e Commerce
65/386
Printing array
Wrap around your array name and key in curlybraces when your array uses strings for its keys:
echo PP is the abbreviation for
{$states[PP]}.; Numerically, indexed arrays dont have this
problem, though:
echo The artist with an index of 4 is$artists[4].;
-
8/3/2019 All e Commerce
66/386
To use arrays
Open handle_form.php
Change the assignment of the $name
and $comments variables to$name = striplashes($_POST[name])$comments= striplashes($_POST[comments]);
In the previous version of this script, the values of $name and$comments were assigned by referring to the $_REQUEST
array which will work. But since these variables come from aform that uses the post method, $_POST would be moreexact, and therefore more secure
http://handle_form.txt/http://handle_form.txt/http://handle_form.txt/ -
8/3/2019 All e Commerce
67/386
cont
Alter the echo() statement
echo
Thank you,
$name, for thefollowing comments:
$comments
We will reply to you at {$_POST[email]}/
\n; -
8/3/2019 All e Commerce
68/386
-
8/3/2019 All e Commerce
69/386
Build array one by one
Example:$array[] = Tobias;
$array[] = Maeby;
$array[wife] = Lindsay; Its important to note that if you specify a key and a
value already exists indexed with that same key,the new value will overwrite the existing one. Forexample,
$array[son] = Buster;$array[son] = Michael;
Use array() function to build
-
8/3/2019 All e Commerce
70/386
Use array() function to build
an entire array in one step
$states=array(KL => Kuala Lumpur, PP => PulauPinang);
This function can be used whether or not you explicitly set the
key$artists=array (Incubus, Coldplay, Nelly); If you set the first numeric key value, the added values will be
keyed incrementally thereafter:$days=array(1=>Sunday, Monday,Tuesday);echo $day[3];//Tuesday
If you want to create an array of sequential numbers, use therange() function:$ten = range (1,10);
Calendar: To create & access arrays
http://calendar.txt/http://calendar.txt/ -
8/3/2019 All e Commerce
71/386
Multidimensional arrays
Multidimensional array is arrayconsisting of other arrays. Example:$states=array (MD =>Maryland, IL =>
Illinois, );$province=array(QC=>Quebec,AB=>Alberta,.);
Then, these two arrays could becombined into one multidimensional
array like: $abbr=array (UD=>$states,
Canada=>province);
Now, $abbr is a multidimensional
array
-
8/3/2019 All e Commerce
72/386
-
8/3/2019 All e Commerce
73/386
Arrays and strings
PHP has two functions for convertingbetween strings and arrays$array=explode (separator, $string);
$string=implode (glue, $array); When turning an array into a string, you set the glue
the characters or code that will be insertedbetween the array values in the generated string.\
Conversely, when turning into an array, you specify
the separator, which is the code that delineatesbetween the different elements in the generatedarray
Arrays and strings
-
8/3/2019 All e Commerce
74/386
cont
$string1 = Mon Tue Wed Thur Fri;
$days_array = explode( - , $string1);
The$days_arrayvariable is now a five-element
array, with Mon indexed at 0, Tue indexed at 1, etc.
$string2=implode(, , $days_array);
The$string2 variable is now a comma-separated
list of days: Mon, Tue, Wed, Thur, Fri
-
8/3/2019 All e Commerce
75/386
-
8/3/2019 All e Commerce
76/386
-
8/3/2019 All e Commerce
77/386
The while loop
condition
Do this if TRUE
Exit looponce
condition isFALSE
A flowchart representation ofhow PHP handles awhileloop
-
8/3/2019 All e Commerce
78/386
The for loop
The for loop syntax
for (initial expression;
condition; closing expression){
// Do something
}
-
8/3/2019 All e Commerce
79/386
The for loop
condition
Do this if TRUE
Exit looponce
condition isFALSE
initialexpression
afterexpression
-
8/3/2019 All e Commerce
80/386
-
8/3/2019 All e Commerce
81/386
The for loop
for ($i = 1; $i
-
8/3/2019 All e Commerce
82/386
-
8/3/2019 All e Commerce
83/386
88
CREATING DYNAMICWEB SITES
-
8/3/2019 All e Commerce
84/386
-
8/3/2019 All e Commerce
85/386
Difference between
-
8/3/2019 All e Commerce
86/386
91
Difference betweeninclude() and require()
The functions are exactly the samewhen working properly but behave
differently when they fail. If an include()function doesnt work
(it cannot include the file for some
reason), a warning will be printed onthe Web browser, but the script willcontinue to run.
Difference between
-
8/3/2019 All e Commerce
87/386
92
Difference betweeninclude() and require()
If require() fails, error is printed and the script ishalted.
These two functions are used to create functions,
headers, footers, or elements that can be reused onmultiple pages.
This can save the developer a considerable amountof time by creating a standard header or menu file.When the header needs to be updated, you can
only update this one include file, or when you add anew page to your site, you can simply change themenu file (instead of updating the links on all webpages).
-
8/3/2019 All e Commerce
88/386
93
The include() Function
The include() function takes all the text ina specified file and copies it into the file thatuses the include function.
Example 1: Assume that you have astandard header file, called "header.php".To include the header file in a page, use theinclude() function, like this:
Welcome to my home page
Sometext
-
8/3/2019 All e Commerce
89/386
94
*_once() function
Both functions have a *_once()version, which guarantees that the file
in question is included only onceregardless of how many times a scriptmay (presumeably inadvertently)attempt to include it.
require_once(filename.php);
include once(filename.php)
-
8/3/2019 All e Commerce
90/386
Site structure
-
8/3/2019 All e Commerce
91/386
96
Ease of maintenance
Using external files for holdingstandard procedures (i.e. PHP code),
CSS, JavaScript and HTML designgreatly improve the ease ofmaintaining site because commonlyedited code is placed in one centrallocation.
Site structure
-
8/3/2019 All e Commerce
92/386
97
Security
Use .inc or .html file for extensiondocuments where security is not issue (suchas HTML templates)
Use .php for files containing sensitive data(such as database access information)
You can also use both .inc and .html or.php so that a file is clearly indicated as an
include of a certain type:functions.inc.php orheader.inc.html
Site structure
-
8/3/2019 All e Commerce
93/386
98
Ease of user navigation
Structure your sites so that they areeasy for users to navigate, both by
clicking links and by manually typing aURL.
Try avoid creating too many nested
folders or using hard-to-copy directorynames and filenames containing upperand lowercase letters and all mannerof punctuation
Handling HTML Forms with
-
8/3/2019 All e Commerce
94/386
99
gPHP Redux
The previous examples showed that there are twoseparate scripts for handling HTML forms: one thatdisplayed the form and another that received it.
To have the entire process in one script, use aconditional
if (/* form has been submitted */) {
//Handle it
} else {
//Display it
}
-
8/3/2019 All e Commerce
95/386
-
8/3/2019 All e Commerce
96/386
-
8/3/2019 All e Commerce
97/386
-
8/3/2019 All e Commerce
98/386
-
8/3/2019 All e Commerce
99/386
104
Step 3: Validate the form
if(is_numeric($_POST['quantity
'])&&is_numeric($_POST['price']))
&&is_numeric($_POST['tax'])) {
The validation checks that three
submitted variables are all numeric
-
8/3/2019 All e Commerce
100/386
-
8/3/2019 All e Commerce
101/386
-
8/3/2019 All e Commerce
102/386
-
8/3/2019 All e Commerce
103/386
-
8/3/2019 All e Commerce
104/386
Creating & Calling Your Own
-
8/3/2019 All e Commerce
105/386
110
Functions
To create your own functions
Creating a function that takes
arguments Setting default argument values
Returning values from a function
-
8/3/2019 All e Commerce
106/386
-
8/3/2019 All e Commerce
107/386
-
8/3/2019 All e Commerce
108/386
-
8/3/2019 All e Commerce
109/386
-
8/3/2019 All e Commerce
110/386
-
8/3/2019 All e Commerce
111/386
-
8/3/2019 All e Commerce
112/386
-
8/3/2019 All e Commerce
113/386
-
8/3/2019 All e Commerce
114/386
-
8/3/2019 All e Commerce
115/386
Creating & Calling Your Own Functions
-
8/3/2019 All e Commerce
116/386
121
cont
The function can return a value(number/string) or a variable whose valuehas been created by the function.
When calling this function, assign thereturned value to a variable$my_sign = find_sign (July, 9);
Or use it as a parameter to find anotherfunction:print find_sign (July, 9);
Exercise: To have a function return a value
http://returnvalues.txt/http://returnvalues.txt/ -
8/3/2019 All e Commerce
117/386
V i bl S (2)
-
8/3/2019 All e Commerce
118/386
123
Variable Scope (2)
Since included files act as if they werepart of the original (including) script,variables defined before theinclude() line are available to theincluded file.
Further, variables defined within the
included file are available to the parent(including) script after the include()line.
t
Variable Scope
-
8/3/2019 All e Commerce
119/386
124
cont
Functions have their own scope, whichmeans that variables used within a functionare not available outside of it; and variables
defined outside of a function are notavailable within it.
For this reason, a variable inside of afunction can have the same name as one
outside of it and still be an entirely differentvariable with a different value. This is aconfusing concept for most beginners.
l b l() St t t
Variable Scope
-
8/3/2019 All e Commerce
120/386
125
global() Statement
To alter the variable scope within a function, usethe global() statementfunction function_name() {
global $var;
}$var = 20;function_name(); // Function call
In this example, $var inside the function is now thesame as $var outside of it. This means that the
function $var already has a value of 20, and if thevalue changes inside of the function, the external$vars value will also change
-
8/3/2019 All e Commerce
121/386
D t & Ti F ti
-
8/3/2019 All e Commerce
122/386
127
Date & Time Functions
date() function returns a string of text for acertain date and time according to a formatspecified
date (format, [timestamp]); The timestamp is an optional argument
representing the number of seconds . Itallows you to get information, like the day ofthe week, for a particular date.
If timestamp is not specified, PHP will justuse the current time on the server.
-
8/3/2019 All e Commerce
123/386
-
8/3/2019 All e Commerce
124/386
-
8/3/2019 All e Commerce
125/386
-
8/3/2019 All e Commerce
126/386
The td t ()Array
Date & Time Functions
-
8/3/2019 All e Commerce
127/386
132
The getdate()Array
KEY VALUE EXAMPLE
year Year 2005
mon Month 12
month Month name December
mday Day of the month 25
weekday Day of the week Tuesday
hours Hours 11minutes Minutes 56
seconds Seconds 47
Sending Email
-
8/3/2019 All e Commerce
128/386
133
Sending Email
Usemail() function to send email inmail ($to, $subject, $body);
$to = email address or a series of
addresses, separated by commas $subject= emails subject line $body= contents of the email. Use the
newline character (\n) within the double
quotation marks when creating your body tomake the text go over multiple lines
cont
Sending Email
-
8/3/2019 All e Commerce
129/386
134
cont
Themail() function takes a fourth,optional parameter for additionalheaders. This is where you can set the
From, Reply-To, Cc, Bccand etc. For example:
mail ([email protected],
Hello, $body, From:[email protected]);
cont
Sending Email
-
8/3/2019 All e Commerce
130/386
135
cont
To use multiple headers of differenttypes in email, separate each with
\r\n$headers = From:[email protected] \r\n;
$headers .= Cc:
[email protected]\r\n;mail ([email protected], Hello,$body, $headers);
PHP mail() dependencies
-
8/3/2019 All e Commerce
131/386
136
PHPmail() dependencies
PHPs mail function doesnt actuallysend the email itself.
Instead, it tells the mail server runningon the computer to do so.
This means, that your computer must
have a WORKING MAIL SERVER inorder for this function to work.
-
8/3/2019 All e Commerce
132/386
PHPmail() dependencies
(3)
-
8/3/2019 All e Commerce
133/386
138
(3)
If you are running on Windows and haveISP that provides with SMTP server, thisinformation can be set in the php.ini file.
Unfortunately, this will only work if your ISPdoesnt require authentication to use theSMTP server.
Otherwise, you need to install an SMTP
server on your computer. Google for freewindows smtp server.
PHPmail() dependencies
(4)
-
8/3/2019 All e Commerce
134/386
139
(4)
If you are running on Mac OS X, youllneed to enable the built-in SMTP
server (either sendmail or postfix,depending upon the specific version ofMac OS X you are running).
You can find instructions online fordoing so google: enable sendmailMac OS X
-
8/3/2019 All e Commerce
135/386
140
-
8/3/2019 All e Commerce
136/386
COOKIES ANDSESSIONS
Cookies
-
8/3/2019 All e Commerce
137/386
Cookies
A cookie is a small file that is stored onthe client computer when visiting a
website. Cookies got a bad rap a few years ago
and as a result there is a good deal ofpeople out there with their cookiesdisabled.
Cookies are harmless. Some sites willuse them to track visitor usage and
Features of a cookie
-
8/3/2019 All e Commerce
138/386
Features of a cookie
Stored on the client computer and arethus decentralized.
Can be set to a long lifespan and/orset to expire after a period of time fromseconds to years.
They work well with large sites that
may use several web servers. Wont do you any good if the client has
set their browser to disable cookies.
Features of a cookie (cont)
-
8/3/2019 All e Commerce
139/386
Features of a cookie (cont )
Limitations on size and number: abrowser can keep only the last 20cookies sent from a particular domain,and the values that a cookie can holdare limited to 4 KB in size.
Can be edited beyond your controlsince they reside on the client system.
Information set in the cookie is notavailable until the page is reloaded.
How to Create a Cookie?
-
8/3/2019 All e Commerce
140/386
How to Create a Cookie?
The setcookie() function is used to
set a cookie.
Note: The setcookie() functionmust appear BEFORE the
tag.
setcookie(name, value, expire,path, domain);
setcookie() function:
Example 1
-
8/3/2019 All e Commerce
141/386
Example 1
In the example below, we will create acookie named "user" and assign thevalue "Alex Porter" to it. We alsospecify that the cookie should expireafter one hour:
setcookie() function:
Example 2
-
8/3/2019 All e Commerce
142/386
Example 2
You can also set the expiration time of thecookie in another way. It may be easier thanusing seconds.
In the example below the expiration time isset to a month (60 sec * 60 min * 24 hours *30 days).
How to Retrieve a CookieValue?
-
8/3/2019 All e Commerce
143/386
Value?
The PHP $_COOKIE variable is used to
retrieve a cookie value.
In the example below, we retrieve the value
of the cookie named "user" and display it ona page:
How to Retrieve a CookieValue? (cont)
-
8/3/2019 All e Commerce
144/386
Value? (cont )
In the following example we use the isset() function tofind out if a cookie has been set:
How to Delete a Cookie?
-
8/3/2019 All e Commerce
145/386
How to Delete a Cookie?
When deleting a cookie you shouldassure that the expiration date is in thepast.
Delete example:
-
8/3/2019 All e Commerce
146/386
Support Cookies?
If your application deals with browsersthat do not support cookies, you willhave to use other methods to passinformation from one page to anotherin your application.
One method is to pass the datathrough forms.
What if a Browser Does NOTSupport Cookies? (cont)
-
8/3/2019 All e Commerce
147/386
Support Cookies? (cont )
-
8/3/2019 All e Commerce
148/386
PHP Sessions
PHP session
-
8/3/2019 All e Commerce
149/386
PHP session
A PHP session variable is used tostore information about, or changesettings for a user session.
Session variables hold informationabout one single user, and areavailable to all pages in oneapplication.
Features of sessions
-
8/3/2019 All e Commerce
150/386
Features of sessions
Server-size cookie can store very largeamounts of data while regular cookies arelimited in size.
Since the client-side cookie generated by asession only contains the id reference (arandom string of 32 hexadecimal digits, such asfca17f071bbg9bf7f85ca281653499a4 called a
session id) you save on bandwidth. Much more secure than regular cookies since
the data is stored on the server and cannot beedited by the user.
Features of sessions (cont)
-
8/3/2019 All e Commerce
151/386
Features of sessions (cont )
Only last until the user closes theirbrowser.
Wont work if client has cookiesdisabled in their browser unless someextra measures are taken.
Can be easily customized to store the
information created in the session to adatabase.
Information is available in your code assoon as it is set.
Advantages of PHP Sessions
-
8/3/2019 All e Commerce
152/386
Advantages of PHP Sessions
Your server-side cookie can contain verylarge amounts of data with no hassle -client-side cookies are limited in size
Your client-side cookie contains nothingother than a small reference code - asthis cookie is passed each time someonevisits a page on your site, you are saving
a lot of bandwidth by not transferringlarge client-side cookies around
Session data is much more secure - onlyyou are able to manipulate it, as opposed
to client side cookies which are editable
Cookies vs Session?
-
8/3/2019 All e Commerce
153/386
Cookies vs Session?
Cookies generally should be used for non-sensitive throw-away information like thefollowing: Displaying the users name next time they visit the
site. Simple user display preferences.
Anything small and disposable that needs to bestored for a period of time (for info like, emailaddress, contact info etc. a database should beused)
Sessions are used for more sensitive info likecontrolling user access or loading info from adatabase that expires when the session ends or
the browser window is closed
-
8/3/2019 All e Commerce
154/386
Storing a Session Variable
-
8/3/2019 All e Commerce
155/386
Storing a Session Variable
Storing a Session Variable
-
8/3/2019 All e Commerce
156/386
Storing a Session Variable
In the next example, we create asimple page-views counter.
The isset() function checks if the"views" variable has already been set.
If "views" has been set, we can
increment our counter. If "views" doesn't exist, we create a
"views" variable, and set it to 1:
Storing a Session Variable(cont)
-
8/3/2019 All e Commerce
157/386
(cont )
Destroying a Session
-
8/3/2019 All e Commerce
158/386
Destroying a Session
If you wish to delete some sessiondata, you can use the unset() or thesession_destroy() function.
The unset() function is used to free
the specified session variable:
Destroying a Session (cont)
-
8/3/2019 All e Commerce
159/386
y g ( )
You can also completely destroy thesession by calling thesession_destroy() function:
Note: session_destroy() will resetyour session and you will lose all yourstored session data.
-
8/3/2019 All e Commerce
160/386
Choosing the appropriateoption
-
8/3/2019 All e Commerce
161/386
p
The end result? They lose their informationpart-way through their visit, and what data youdo have is fragmented across your servers.There are ways around this problem, never
fear: Use a networked file system (NFS on Unix or the
equivalent). Pretty much all operating systems allowyou to connect to other computers and read/writetheir data. If you have a shared session data source,you would be able to bypass the above problem
Write your own session implementation that storesdata in a medium you can handle and share betweenall computers. This is tricky, and error-prone.
Use a database to store your sessions.
-
8/3/2019 All e Commerce
162/386
-
8/3/2019 All e Commerce
163/386
Testing for Cookies (cont)
-
8/3/2019 All e Commerce
164/386
g ( )
In Firefox on Windows
Choose Tools > Options
Click Privacy
Expand the Cookies section
Select ask me every time in the KeepCookies dropdown menu
If you are using Firefox on Mac OS X,the steps are the same, but start bychoosing Firefox > Preferences
setcookie() function
-
8/3/2019 All e Commerce
165/386
To see the effect of the setcookie() function, set your
Web browser to ask before storing cookie.
setcookie() function
-
8/3/2019 All e Commerce
166/386
To send a cookie
-
8/3/2019 All e Commerce
167/386
1. Create new PHP document
-
8/3/2019 All e Commerce
168/386
( )
$query = "SELECT user_id, first_name FROMusers WHERE email='$e' ANDpassword='$p'";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result,MYSQL_NUM);
Retrieve user_id and first_name for this user
from database.
To send a cookie (cont)
-
8/3/2019 All e Commerce
169/386
( )if ($row) { // A record was pulled from the
database.
// Set the cookies & redirect.
setcookie ('user_id', $row[0]);
setcookie ('first_name', $row[1]);
If user entered the correct information, log the userin.
The $row variable will have a value only if thepreceding query returned at least one record
To send a cookie (cont)
-
8/3/2019 All e Commerce
170/386
( )
$url = 'http://' . $_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); // Chopoff the slash.
}// Add the page.
$url .= '/loggedin.php';
header("Location: $url");
exit(); // Quit the script.
Redirect the user to another page
To send a cookie (cont)
-
8/3/2019 All e Commerce
171/386
} else { // No record matched the query.$errors[] = 'The email address and passwordentered 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.
Complete the $row conditional and the $errors conditional, and the
close the database connection
To send a cookie (cont)
-
8/3/2019 All e Commerce
172/386
// Begin the page now.
$page_title = 'Login';include ('./includes/header.html');
if (!empty($errors)) { // Print any errormessages.
echo 'Error!
The following error(s)occurred:
';foreach ($errors as $msg) { // Print each
error.echo " - $msg
\n";}
echo '
Please try again.
';}
Create the form
-
8/3/2019 All e Commerce
173/386
// Create the form.
?>
Login
Email Address:
Password:
loggedin.php
-
8/3/2019 All e Commerce
174/386
?php # Script 9.2 -
loggedin.php
// If no cookie is present,redirect the user.
if(!isset($_COOKIE['user_id'])) {
// Start defining the URL.
$ rl 'http //'
Check thepresence of acookie
loggedin.php
-
8/3/2019 All e Commerce
175/386
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR(substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1); //Chop off the slash.
}
$url .= '/index.php'; // Add the
page.header("Location: $url");
exit(); // Quit the script.
}
-
8/3/2019 All e Commerce
176/386
// Set the page title and include the HTMLheader.
$page_title = 'Logged In!'; include ('./includes/header.html');
// Print a customized message.
echo "Logged In!
You are now logged in,{$_COOKIE['first_name']}!
";
include ('./includes/footer.html');
?>
-
8/3/2019 All e Commerce
177/386
Setting cookie parameters(cont)
-
8/3/2019 All e Commerce
178/386
Expiration time is determined byadding a particular number of minutesor hours to the current moment,retrieved using the time() function.
The following line will set the expirationtime of the cookie to be 1 hour (60
seconds times 60 minutes) from thecurrent moment;
setcookie (name, value,
Setting cookie parameters(cont)
-
8/3/2019 All e Commerce
179/386
The path and domain arguments areused to limit cookie to a specific folderwithin a Web site (the path) or to aspecific host.
For example, you could restrict acookie to exist only while a user is
within the adminfolder of a domain(and the adminfolders subfolders):
setcookie (name, value,
-
8/3/2019 All e Commerce
180/386
Setting cookie parameters(cont)
-
8/3/2019 All e Commerce
181/386
As with all functions that takearguments, you must pass thesetcookie() values in order.
To skip any parameter, use NULL oran empty string.
The expiration and secure values areboth integers and are therefore notquote.
-
8/3/2019 All e Commerce
182/386
Deleting cookies
-
8/3/2019 All e Commerce
183/386
Create a new PHP document
-
8/3/2019 All e Commerce
184/386
// Start defining the URL.
$url = 'http://' . $_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 theslash.
}
$url .= '/index.php'; // Add the page.
header("Location: $url");
exit(); // Quit the script.
} else { // Delete the cookies.
setcookie ('first_name', '', time()-300, '/', '', 0);
setcookie ('user_id', '', time()-300, '/', '', 0);
}
Deleting cookies (cont)
-
8/3/2019 All e Commerce
185/386
// Set the page title and
include the HTML header.
$page_title = 'Logged Out!';
include
('./includes/header.html');
-
8/3/2019 All e Commerce
186/386
-
8/3/2019 All e Commerce
187/386
-
8/3/2019 All e Commerce
188/386
-
8/3/2019 All e Commerce
189/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-206
Copyright 2009 Pearson Education Inc Slide 11-206
Social Networks, Auctions, andPortals
-
8/3/2019 All e Commerce
190/386
Social Networks and OnlineCommunities
-
8/3/2019 All e Commerce
191/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-208
Internet began as community buildingtechnology for scientists, researchers
The Well
Early communities limited to bulletinboards, newsgroups
2002: Mobile Internet devices, blogs,
sharing of rich media began new era ofsocial networking
Social networking one of most common
What Is an Online Social Network? Area online where people who share common ties
-
8/3/2019 All e Commerce
192/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-209
Area online where people who share common ties
can interact with one
Involve:
A group of people
Shared social interaction Common ties among members
People who share an area for some period
of time e.g. MySpace, Friendster, Flickr, Facebook
Portals and social networks moving closer together asportals add social networking features and community
it dd t l lik i
-
8/3/2019 All e Commerce
193/386
-
8/3/2019 All e Commerce
194/386
Types of Social Networks AndTheir Business Models (contd)
-
8/3/2019 All e Commerce
195/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-212
( ) Interest-based social networks:
Offer focused discussion groups based on shared interest in somespecific subject
Usually advertising supported
Affinity communities: Offer focused discussion and interaction with other people who
share same affinity (self or group identification)
Advertising and revenues from sales of products
Sponsored communities: Created by government, non-profit or for-profit organizations for
purpose of pursuing organizational goals
Social Network sites for financial &business
-
8/3/2019 All e Commerce
196/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-213
LinkedIn display business profile andaccomplishment
StockTickr stock performance
Duedee users rated against theirvirtual portfolio
TradeKing to view trading styles
Motley Fool online stock investmentservices
Social network for professional
-
8/3/2019 All e Commerce
197/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-214
DailyStrength for healthcare
LawLink for law practitioners
Sermo physicians INMobile wireless industry
executives
AdGabber advertising professionals
Social Network Features andTechnologies
-
8/3/2019 All e Commerce
198/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-215
Profiles
Friends network
Network discovery
Favorites
E-mail
Storage
Instant messaging
Message boards
Online polling
Chat
Discussion groups
Experts online
Membership
management tools
-
8/3/2019 All e Commerce
199/386
Online Auctions
Online auction sites among the most
-
8/3/2019 All e Commerce
200/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-217
Online auction sites among the most
popular consumer-to-consumer sites onthe Internet
eBay: Market leader
Several hundred different auction sites inU.S. alone
Established portals and online retail sitesincreasingly are adding auctions to theirsites
-
8/3/2019 All e Commerce
201/386
Defining and Measuring the Growthof Auctions and Dynamic Pricing
-
8/3/2019 All e Commerce
202/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-219
Auctions Type of dynamic pricing
C2C auctions Auction house an intermediary
$25 billion gross revenue 2008
B2C auctions
Business owns assets; often used for excessgoods
$19 billion gross revenue 2008
Can be used to allocate, bundle resources
(contd)
-
8/3/2019 All e Commerce
203/386
-
8/3/2019 All e Commerce
204/386
-
8/3/2019 All e Commerce
205/386
Risks and Costs of Auctions forConsumers and Businesses
-
8/3/2019 All e Commerce
206/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-223
Delayed consumption costs Monitoring costs
Possible solutions include:
Fixed pricing
Watch lists
Proxy bidding
Equipment costs
Trust risks
Possible solutionrating systems (not always successful)
Fulfillment costs
Internet Auction Basics
Internet auctions different from traditional
-
8/3/2019 All e Commerce
207/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-224
te et auct o s d e e t o t ad t o a
auctions Last much longer (usually a week)
Variable number of bidders who come and
go from auction arena Market power and bias in dynamically
priced markets
Neutral: Number of buyers and sellers is fewor equal
Seller bias: Few sellers and many buyers
Buyer bias: Many sellers and few buyers
Internet Auction Basics (contd)
Price Allocation Rules
-
8/3/2019 All e Commerce
208/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-225
Price Allocation Rules
Uniform pricing rule: Multiple winners whoall pay the same price
Discriminatory pricing rule: Winners pay
different amount depending on what theybid
Public vs. private information
Prices bid may be kept secret
Bid rigging
Open markets
Bias in Dynamically Priced MarketsFigure 11.4, Page 729
-
8/3/2019 All e Commerce
209/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-226
Types of Auctions
English auctions:
-
8/3/2019 All e Commerce
210/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-227
g
Easiest to understand and most common
Single item up for sale to single seller
Highest bidder wins Traditional Dutch auction:
Uses a clock that displays starting price
Clock ticks down price until buyer stops it
Types of Auctions (contd)
Dutch Internet auction:
-
8/3/2019 All e Commerce
211/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-228
Public ascending price, multiple units
Final price is lowest successful bid, whichsets price for all higher bidders
Name Your Own Price Auctions
Pioneered by Priceline
Users specify what they are willing to payfor goods or services and multipleproviders bid for their business
Prices do not descend and are fixed
-
8/3/2019 All e Commerce
212/386
When to Use Auctions (And ForWhat) In Business
-
8/3/2019 All e Commerce
213/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-230
Factors to consider Type of product
Product life cycle
Channel management
Type of auction
Initial pricing
Bid increments
Auction length
Number of items
Price allocation rule
Closed vs. open bidding
Seller and Consumer Behavior atAuctions
-
8/3/2019 All e Commerce
214/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-231
Profit to seller: A function of arrival rate, auction length,and number of units at auction
Auction prices not necessarily the lowest
Reasons include herd behavior (tendency to gravitate toward,
and bid for, auction listing with one or more existing bids) Unintended results of participating in auctions:
Winners regret
Sellers lament
Losers lament
Consumer trust an important motivating factor inauctions
When Auction Markets Fail: Fraudand Abuse in Auctions
-
8/3/2019 All e Commerce
215/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-232
Markets fail to produce socially desirableoutcomes in four situations: informationasymmetry, monopoly power, public
goods, and externalities. Auction markets prone to fraud
Most common: Failure to deliver, failure to
pay
2008 IC3 statistics:
35.7% of Internet fraud complaints
The Growth and Evolution of Portals Portals: most frequently visited sites on
-
8/3/2019 All e Commerce
216/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-233
the Web Gateways to the 40 - 50 billion Web
pages
Most of top portals today began assearch engines
Today provide navigation of the Web,commerce, and content (own andothers)
Enterprise portals an importantfunction within organizations
Top 5 Portal/Search Engine Sitesin the United StatesFigure 11.6, Page 743
-
8/3/2019 All e Commerce
217/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-234SOURCE: Compete.com, 2008; authors estimates
Insight on Business
Battle of the PortalsClass Discussion
-
8/3/2019 All e Commerce
218/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-235
Class Discussion
How many different kinds of portals arethere?
How do portals make money? What are the strengths of the top four
portals: Yahoo, Google, MSN andAOL?
Why did Google link up with AOL whenAOL was losing audience share?
Types of Portals: General Purposeand Vertical Market
-
8/3/2019 All e Commerce
219/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-236
General purpose portals: Attempt to attract very large general
audience and then retain it on-site by
providing in-depth vertical content channels E.g. Yahoo!, MSN
Vertical market portals:
Attempt to attract highly focused, loyalaudiences with specific interest
Community (affinity group); e.g. iVillage.com
Focused content; e.g. ESPN.com
Two General Types of Portals: General Purposeand Vertical Market PortalsFigure 11.7, Page 747
-
8/3/2019 All e Commerce
220/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-237
Figure 11.7, Page 747
Portal Business Models ISP services (AOL, MSN)
-
8/3/2019 All e Commerce
221/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-238
Provide Web access, e-mail for monthly fee
General advertising revenue
Charge for impressions delivered
Tenancy deals
Fixed charge for number of impressions, exclusivepartnerships, sole providers
Commissions on sales
Sales at site by independent providers
Subscription fees
Charging for premium content
E-commerce in Action: Yahoo! Inc. Vision: Global Internet communications, commerce and
-
8/3/2019 All e Commerce
222/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-239
media company Business model: Earns money from advertising, premium
content sales, commissions and corporate services
Financial analysis: Revenues continue to grow; operating
margins positive but falling Strategic analysis
Growth through acquisition
Competition: Google, Microsoft, Time Warner/AOL
Outsources technology Future prospects dim
SUMMARYSocial NetworksGeneral communitiesPractice networks
Interest-based social networksAffinity communities
Online AuctionsDynamic pricing: Prices based on demand
characteristics of customer and supplysituation of seller
Types of dynamic pricing
-
8/3/2019 All e Commerce
223/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 11-240
Affinity communitiesSponsored communities
yp y p g
1. Bundling2. Trigger pricing3. Utilization pricing4. Personalization pricing
Types of AuctionsEnglish auctionsTraditional Dutch auctionDutch Internet auctionName Your Own Price AuctionsGroup Buying Auctions (Demand
Aggregators)Professional Service Auctions
Auction Aggregator
Types of PortalsGeneral purpose portals
Vertical market portalsCommunity (affinity group)Focused content
Portal Business ModelsISP servicesGeneral advertising revenue
Tenancy dealsCommissions on salesSubscription fees
-
8/3/2019 All e Commerce
224/386
Chapter 1
Overview of ElectronicCommerce
Learning Objectives
-
8/3/2019 All e Commerce
225/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
242
1. Define electronic commerce (EC) anddescribe its various categories.
2. Describe and discuss the content and
framework of EC.3. Describe the major types of EC
transactions.
4.
Describe the digital revolution as a driver ofEC.
5. Describe the business environment as adriver of EC.
Learning Objectives
-
8/3/2019 All e Commerce
226/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
243
6. Describe some EC business models.
7. Describe the benefits of EC toorganizations, consumers, and society.
8. Describe the limitations of EC.9. Describe the contribution of EC to
organizations responding to environmentalpressures.
10. Describe online social and businessnetworks.
Electronic Commerce:Definitions and Concepts
-
8/3/2019 All e Commerce
227/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
244
electronic commerce (EC)
The process of buying, selling,transferring, or exchanging products,services, or information via computernetworks.
Electronic Commerce:Definitions and Concepts
-
8/3/2019 All e Commerce
228/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
245
e-business
A broader definition of EC thatincludes not just the buying and sellingof goods and services, but alsoservicing customers, collaborating withbusiness partners, and conducting
electronic transactions within anorganization.
Electronic Commerce:Definitions and Concepts
-
8/3/2019 All e Commerce
229/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
246
PURE VERSUS PARTIAL EC
EC Organizations
brick-and-mortar (old economy)
organizationsOld-economy organizations (corporations)that perform their primary business off-line,selling physical products by means of
physical agents. virtual (pure-play) organizations
Organizations that conduct their businessactivities solely online.
Electronic Commerce:Definitions and Concepts
-
8/3/2019 All e Commerce
230/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
247
click-and-mortar (click-and-brick)organizations
Organizations that conduct some e-commerce activities, usually as an additional
marketing channel.
Electronic Commerce:Definitions and Concepts
-
8/3/2019 All e Commerce
231/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
248
1.1
Electronic Commerce:Definitions and Concepts
-
8/3/2019 All e Commerce
232/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
249
INTERNET VERSUS NON-INTERNETEC
intranet
An internal corporate or governmentnetwork that uses Internet tools, such asWeb browsers, and Internet protocols.
extranetA network that uses the Internet to linkmultiple intranets.
Electronic Commerce:Definitions and Concepts
-
8/3/2019 All e Commerce
233/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
250
electronic market (e-marketplace)
An online marketplace where buyersand sellers meet to exchange goods,services, money, or information.
Electronic Commerce:Definitions and Concepts
-
8/3/2019 All e Commerce
234/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
251
Interorganizational information systems(IOSs)
Communications systems that allow routine
transaction processing and information flowbetween two or more organizations.
intraorganizational information systems
Communication systems that enablee-commerce activities to go on withinindividual organizations.
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
235/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
252
The EC Framework,Classification, and Content
CLASSIFICATION OF EC BY THE NATURE
-
8/3/2019 All e Commerce
236/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
253
OF THE TRANSACTIONS ORINTERACTIONS
business-to-business (B2B)
E-commerce model in which all of the participantsare businesses or other organizations.
business-to-consumer (B2C)
E-commerce model in which businesses sell to
individual shoppers.
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
237/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
254
e-tailing
Online retailing, usually B2C.
business-to-business-to-consumer
(B2B2C)E-commerce model in which a businessprovides some product or service to aclient business that maintains its owncustomers.
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
238/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
255
consumer-to-business (C2B)
E-commerce model in which individualsuse the Internet to sell products or
services to organizations or individualswho seek sellers to bid on products orservices they need.
mobile commerce (m-commerce)
E-commerce transactions and activitiesconducted in a wireless environment.
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
239/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
256
location-based commerce (l-commerce)
M-commerce transactions targeted toindividuals in specific locations, atspecific times.
intrabusiness EC
E-commerce category that includes all
internal organizational activities thatinvolve the exchange of goods, services,or information among various units andindividuals in an organization.
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
240/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
257
business-to-employees (B2E)
E-commerce model in which anorganization delivers services,information, or products to its individualemployees.
collaborative commerce (c-commerce)
E-commerce model in which individuals
or groups communicate or collaborateonline.
consumer-to-consumer (C2C)
E-commerce model in which consumers
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
241/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
258
peer-to-peer
Technology that enables networked peercomputers to share data and processing witheach other directly; can be used in C2C, B2B,
and B2C e-commerce. e-learning
The online delivery of information for purposesof training or education.
e-government
E-commerce model in which a governmententity buys or provides goods, services, orinformation from or to businesses or individualcitizens.
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
242/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
259
exchange
A public electronic market with manybuyers and sellers.
exchange-to-exchange (E2E)E-commerce model in which electronicexchanges formally connect to oneanother for the purpose of exchanginginformation.
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
243/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
260
THE INTERDISCIPLINARY NATUREOF EC
The Google Revolution
EC Failures
EC Successes
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
244/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
261
Web 2.0
The second-generation of Internet-based services that let people
generate content, collaborate, andshare information online in perceivednew wayssuch as social networking
sites, wikis, communication tools, andfolksonomies.
The EC Framework,Classification, and Content
-
8/3/2019 All e Commerce
245/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
262
The Digital RevolutionDrives E-Commerce
-
8/3/2019 All e Commerce
246/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
263
digital economy
An economy that is based on digitaltechnologies, including digital
communication networks, computers,software, and other related informationtechnologies; also called the Internet
economy, the new economy, or theWeb economy.
The Digital RevolutionDrives E-Commerce
C
-
8/3/2019 All e Commerce
247/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
264
The digital revolution accelerates ECmainly by providing competitiveadvantage to organizations.
The digital revolution enables manyinnovations
The Business EnvironmentDrives E-Commerce
THE BUSINESS ENVIRONMENT
-
8/3/2019 All e Commerce
248/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
265
THE BUSINESS ENVIRONMENT
The Business Environment Impact Model
Business Pressures and Opportunities
Organizational Response Strategies
The Business EnvironmentDrives E-Commerce
-
8/3/2019 All e Commerce
249/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
266
EC BUSINESS MODELS
b i d l
-
8/3/2019 All e Commerce
250/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
267
business model
A method of doing business by whicha company can generate revenue to
sustain itself.
EC BUSINESS MODELS
TYPICAL EC BUSINESS MODELS
-
8/3/2019 All e Commerce
251/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
268
TYPICAL EC BUSINESS MODELS
Online direct marketing
Electronic tendering systems for procurement tendering (bidding) system
Model in which a buyer requests would-be sellers tosubmit bids; the lowest cost or highest value bidderwins.
name-your-own-price model
Model in which a buyer sets the price he or sheis willing to pay and invites sellers to supply thegood or service at that price.
EC BUSINESS MODELS
Fi d th b t i
-
8/3/2019 All e Commerce
252/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
269
Find the best price also known as a search engine model
affiliate marketing
An arrangement whereby a marketing partner (a
business, an organization, or even an individual)refers consumers to the selling companys Website.
viral marketing
Word-of-mouth marketing in which customerspromote a product or service to friends orothers.
EC BUSINESS MODELS
h i
-
8/3/2019 All e Commerce
253/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
270
group purchasing
Quantity (aggregated) purchasing thatenables groups of purchasers to obtain a
discount price on the productspurchased.
SMEs
Small-to-medium enterprises.
e-co-ops
Another name for online group purchasingorganizations.
EC BUSINESS MODELS
O li ti
-
8/3/2019 All e Commerce
254/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
271
Online auctions
Product customization and servicepersonalization
customizationCreation of a product or service according tothe buyers specifications.
personalization
The creation of a service or informationaccording to specific customer specifications.
EC BUSINESS MODELS
El t i k t l d h
-
8/3/2019 All e Commerce
255/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
272
Electronic marketplaces and exchanges
Information brokers (infomediaries)
Bartering
Value-chain integrators Value-chain service providers
Supply chain improvers
Social networks, communities, andblogging
Negotiation
EC BUSINESS MODELS
i t l ld
-
8/3/2019 All e Commerce
256/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
273
virtual world
A user-defined world in which peoplecan interact, play, and do business.
The most publicized virtual world isSecond Life.
Benefits and Limitations ofEC
THE BENEFITS OF EC
-
8/3/2019 All e Commerce
257/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
274
THE BENEFITS OF EC
Benefits to Organizations
Benefits to Consumers
Benefits to Society
Facilitating Problem Solving
Benefits and Limitations ofEC
THE LIMITATIONS AND BARRIERS OF
-
8/3/2019 All e Commerce
258/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
275
THE LIMITATIONS AND BARRIERS OFEC Technological Limitations
Nontechnological Limitations
SOCIAL AND BUSINESS NETWORKS social networks
Web sites that connect people with specifiedinterests by providing free services such as
photo presentation, e-mail, blogging, and so on. Business-Oriented Networks
Revenue Models of Social and BusinessNetworks
The Digital Enterprise
digital enterprise
-
8/3/2019 All e Commerce
259/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
276
digital enterprise
A new business model that uses IT in afundamental way to accomplish one or more
of three basic objectives: reach and engagecustomers more effectively, boost employeeproductivity, and improve operatingefficiency. It uses converged communication
and computing technology in a way thatimproves business processes.
The Digital Enterprise
corporate portal
-
8/3/2019 All e Commerce
260/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
277
corporate portal
A major gateway through whichemployees, business partners, and the
public can enter a corporate Web site.
Managerial Issues
1 Is it real?
-
8/3/2019 All e Commerce
261/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
278
1. Is it real?
2. Why is B2B e-commerce so attractive?
3. There are so many EC failureshow can
one avoid them?4. How can we exploit social/business
networking?
5.
What should be my companys strategytoward EC?
6. What are the top challenges of EC?
Summary
1 Definition of EC and description of its
-
8/3/2019 All e Commerce
262/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
279
1. Definition of EC and description of itsvarious categories.
2. The content and framework of EC.
3. The major types of EC transactions.
4. The role of the digital revolution.
5. The role of the business environmentas an EC driver.
Summary
6 The major EC business models
-
8/3/2019 All e Commerce
263/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
280
6. The major EC business models.
7. Benefits of EC to organizations,consumers, and society.
8. Barriers to EC.
9. Social and business online networks.
-
8/3/2019 All e Commerce
264/386
Chapter 1 Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
281
All rights reserved. No part of this publication may be reproduced, stored in aretrieval system, or transmitted, in any form or by any means, electronic,
mechanical, photocopying, recording, or otherwise, without the prior writtenpermission of the publisher. Printed in the United States of America.
Copyright 2009 Pearson Education, Inc.Publishing as Prentice Hall
-
8/3/2019 All e Commerce
265/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-282
Copyright 2009 Pearson Education, Inc. Slide 2-282
E-commerce BusinessModels and Concepts
E-commerce Business ModelsDefinitions Business model
-
8/3/2019 All e Commerce
266/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-284
Slide 2-284
Business model
Set of planned activities designed to result in a profitin a marketplace
Business plan
Describes a firms business model
E-commerce business model
Uses/leverages unique qualities of Internet and Web
Key Ingredients of a Business ModelTable 2.1, Page 67
-
8/3/2019 All e Commerce
267/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-285
Slide 2-285
Value Proposition
Defines how a companys product orservice fulfills the needs of customers
-
8/3/2019 All e Commerce
268/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-286
Slide 2-286
service fulfills the needs of customers
Questions to ask: Why will customers choose to do business with
your firm instead of another? What will your firm provide that others do not or
cannot?
Examples of successful value
propositions: Personalization/customization
Reduction of product search, price discoverycosts
Revenue Model
Describes how the firm will earnre en e generate profits and prod ce
-
8/3/2019 All e Commerce
269/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-287
Slide 2-287
revenue, generate profits, and producea superior return on invested capital
Major types: Advertising revenue model
Subscription revenue model
Transaction fee revenue model Sales revenue model
Affiliate revenue model
Revenue ModelRevenue
Model
Examples Revenue source
-
8/3/2019 All e Commerce
270/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-288
Model
Advertising Yahoo Fees from advertisers inexchange for advertisements
Subscription WSJ.com
Consumerreports.org
Fees from subscribers in
exchange forcontent/services
Transactionfee
eBay
E*Trade
Fees (commissions) forenabling or executing atransaction
Sales Amazon, LLBean, Gap Sales of goods, informationor services
Affiliate MyPoints Fees for business referrals
Market Opportunity
Refers to a companys intendedmarketspace and overall potential
-
8/3/2019 All e Commerce
271/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-291
Slide 2-291
marketspace and overall potentialfinancial opportunities available to thefirm in that marketspace
Marketspace
Area of actual or potential commercial value inwhich company intends to operate
Realistic market opportunity
Defined by revenue potential in each ofmarket niches in which company hopes to
Competitive Environment Refers to the other companies selling similar products
and operating in the same marketspace
-
8/3/2019 All e Commerce
272/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-292
Slide 2-292
and operating in the same marketspace. Also refers to the presence of substitute products and
potential new entrants, as well as power of customersand suppliers
Influenced by: Number of active competitors Each competitors market share Competitors profitability
Competitors pricing
Includes both direct competitors and indirectcompetitors
Competitive Advantage
Achieved when a firm can produce asuperior product and/or bring product to
-
8/3/2019 All e Commerce
273/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-293
Slide 2-293
superior product and/or bring product tomarket at a lower price than most, orall, of competitors
First mover advantage Unfair competitive advantage
Perfect market: No competitiveadvantages or asymmetries
Leverage: When a company uses itscompetitive advantage to achieve moreadvantage in surrounding markets
Market Strategy
Plan that details how a companyi t d t t k t d
-
8/3/2019 All e Commerce
274/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-294
Slide 2-294
Plan that details how a companyintends to enter a new market andattract customers
Best business concepts will fail ifnot properly marketed to potentialcustomers
Organizational Development
Plan that describes how the companywill organize the work that needs to be
-
8/3/2019 All e Commerce
275/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-295
Slide 2-295
will organize the work that needs to beaccomplished
Work is typically divided into functionaldepartments
Hiring moves from generalists to specialists ascompany grows
Management Team
Employees of the company responsiblef ki th b i d l k
-
8/3/2019 All e Commerce
276/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-296
Slide 2-296
Employees of the company responsiblefor making the business model work
Strong management team gives instant
credibility to outside investors
Strong management team may not be
able to salvage a weak businessmodel, but should be able to changethe model and redefine the business asit becomes necessar
Categorizing E-commerceBusiness Models: Some Difficulties
No one correct way
-
8/3/2019 All e Commerce
277/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-297
Slide 2-297
No one correct way
We categorize business modelsaccording to e-commerce sector (B2C,
B2B, C2C) Type of e-commerce technology used can
also affect classification of a business
model i.e., m-commerce
Some companies use multiple business
Categories of B2C
1 Portal
-
8/3/2019 All e Commerce
278/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-298
1. Portal
2. E-tailer
3. Content provider
4. Transaction broker
5. Market creator
6. Service provider7. Community provider
B2C Business Models: Portal
Offers powerful search tools plus anintegrated package of content and
-
8/3/2019 All e Commerce
279/386
Copyright 2009 PearsonEducation, Inc. Publishing asPrentice Hall
Slide 2-299
Slide 2-299
Offers powerful search tools plus anintegrated package of content andservices
Typically utilizes a combinedsubscription/advertisingrevenues/transaction fee model
Today, seen as destination site ratherthan gateway
May be general (horizontal) or