XAMPP Installation Tutorial
XAMPP Installation Tutorial
Introducing XAMPP
An integration package containing a number of useful packages that make it easy to host web sites on various platforms. Apache MySQL - PHP WAMP or LAMP Allow the ease of installation and set up Main Page: http://www.apachefriends.org/en/xampp.html
software: Apache: the famous Web server MySQL: the widely-used, free, open source database PHP: the programming language Perl: the programming language ProFTPD: an FTP server OpenSSL: for secure sockets layer support PhpMyAdmin: for MySQL admin.
3
XAMPP Installation
Download XAMPP installer and let the install begin:
Using the installer version is the easiest way to install XAMPP. Use default directory for convenience
http://www.apachefriends.org/en/faq-xampp-windows.html
5
XAMPP Directories
XAMPP default installation directory is c:/xampp/ The directory of interest is c:/xampp/htdocs/ and its called the webroot (or document root)
PHP files are put in the webroot (c:/xampp/htdocs/) c:/xampp/htdocs/ maps to http://localhost/
For example, c:/xampp/htdocs/project/script.php maps to http://localhost/project/script.php
Installation complete!
Apache HTTP Server MySQL DBMS FileZilla FTP Client Mercury SMTP Client
Toggle button
If the server is up and running, you will get this splash screen. Click on English.
10
Once English is clicked on, the Welcome webpage is shown for XAMPP.
11
http://localhost/xampp/index.php
Youre not accessing the WWW but rather a webpage locally hosted on your computer, which is now running as a web server (localhost).
12
13
15
PHP Fundamentals
PHP Hello World Example PHP Variables Variable Types Working with User Input
17
What is PHP?
PHP: Hypertext Preprocessor
Server-side scripting language Creation of dynamic content Interaction with databases Can be embedded in HTML Open source, written in C First introduced in 1995; at that time PHP stood for Personal Home Page. Similar to Perl and C
18
<html> <head><title>Hello world page</title></head> <body> Hello HTML!<br> <?php echo "Hello PHP!"; ?> </body> </html>
PHP code is never sent to a clients Web browser; only the HTML output of the processing is sent to the browser.
20
21
PHP Comments
You can add comments to the code
Starting with "//", "#" or block in "/*" and "*/" Only "/*" "*/" can be used over several lines Comments are NOT executed
22
PHP Fundamentals
PHP Hello World Example PHP Variables Variable Types Working with User Input
23
PHP Variables
What are variables?
The values stored in computer memory are called variables. The values, or data, contained in variables are classified into categories known as data types. The name you assign to a variable is called an identifier.
24
PHP Variables
Prefixed with a $ (Perl style) Assign values with = operator Example: $name = John Doe; No need to define type Variable names are case sensitive
$name and $Name are different
25
PHP Variables
<?php // declare string variable $output $output = "<b>Hello PHP!</b>"; Echo $output; Hello PHP! ?>
26
PHP Fundamentals
PHP Hello World Example PHP Variables Variable Types Working with User Input
27
Variable/Data Types
A data type is the specific category of information that a variable contains Possible PHP Variable Types are:
Numeric (real or integer) Boolean (TRUE or FALSE) String (set of characters)
28
Variable/Data Types
Unlike C, PHP is not strictly typed. PHP decides what type a variable is based on its value. PHP can use variables in an appropriate way automatically For Example: $HST = 0.12; // HST Rate is numeric echo $HST * 100 . %; //outputs 12%
$HST is automatically converted to a string for the purpose of echo statement
29
Displaying Variables
To display a variable with the echo statement, pass the variable name to the echo statement without enclosing it in quotation marks :
$VotingAge = 18; echo $VotingAge;
To display both text strings and variables, you may used concatenation operator . :
echo "<p>The legal voting age is . $VotingAge. ".</p>";
Concat. operator Period
30
Naming Variables
The name you assign to a variable is called an identifier The following rules and conventions must be followed when naming a variable:
Identifiers must begin with a dollar sign ($) Identifiers may contain uppercase and lowercase letters, numbers, or underscores (_). The first character after the dollar sign must be a letter. Identifiers cannot contain spaces or special characters. Identifiers are case sensitive
31
32
PHP Strings
String values
Strings may be in single or double quotes
<? $output1 = "Hello PHP!"; $output2 = 'Hello again!'; ?>
Start and end quote type should match Difference between two types of quotes is the escape sequences
33
Strings escaping
Special chars in strings are escaped with backslashes (C style) Double-quoted string
$str1 = "this is \"PHP\""; echo $str1; outputs this is PHP
Single-quoted string
$str2 = ' "I\'ll be back ", he said. '; echo $str2;
outputs "I'll be back", he said.
34
Variables in strings
Double quoted strings offer something more:
$saying = "I'll be back!"; $str1 = He told me: $saying"; outputs He told me: I'll be back!
PHP Fundamentals
PHP Hello World Example PHP Variables Variable Types Working with User Input
36
37
The PHP script receives the data as $_GET and $_POST arrays and runs.
39
$_POST
$_POST is an associative array (key and value pairs) The name attribute of form input becomes
key in the array
<form method="post" action="test.php"> <input type="text" name=firstname" /> <input type="password" name="pass" /> </form>
If in the above form the user fills "John" and "mypass test.php will start with built-in array $_POST":
$_POST[firstname"] will be "John" $_POST['pass'] will be "mypass"
40
$_GET
$_GET is also associative array
If we open the URL:
http://phpcourse.com/test2.php?page=1&user=john
41
Exercise #2
Ex1.html
PHP Fundamentals
PHP Hello World Example PHP Variables Variable Types Working with User Input
44
Variable Operators
comparison operators
Equal
Using only one equal sign will initialize/overwrite the value of variables (the assignment operator).
Not Equal != Less than < greater than > Less than or equal <= greater than or equal >=
45
Combined Operators
$a = 3;//Assignment
Initializes/overwrites $a to 3
$a += 5; // Combined Assignment
sets $a to 8 sets $a to 9 $a = $a +5 $a = $a +1 $a += 1 $a -= 1
$a == 5; // Comparison operator
compares the value of $a to 5, produces false.
Strict Comparison
===, !== operators for strict comparison
different from ==, != $a="10";$b=10;$a==$b will produce true. $a="10";$b=10;$a===$b will produce false.
Strict comparison: $a === $b : TRUE if $a is equal to $b, and they are of the
same type.
47
PHP Fundamentals
PHP Hello World Example PHP Variables Variable Types Working with User Input
48
Conditional Statements
Decision making or flow control is the process of determining the order in which statements execute in a program The special types of PHP statements used for making decisions are called decision-making statements or conditional statements.
49
Conditional Statements
Decision making involves evaluating Boolean expressions (true / false) Initialize $cat_is_hungry = false;
If($cat_is_hungry == true) { /* feed cat */ } If($cat_is_hungry) { /* feed cat */ }
Conditional Statements - if
if statement allows code to be executed only if certain condition isexpression Boolean forget the brackets! Don't met
$a = 5; $b = 7; if ($a > $b) echo "A is greater than B"; if ($a % 2) { echo "A is odd"; $b = $a % 2; echo "A%2 is :".$b; } If ($a % 2) is true (i.e., = 1), this entire code block will be executed. Code blocks must start and end with opening and closing braches { }
If - else
if-else statement allows you to execute one code if condition is met or another if not. An else clause executes when the condition in an if...else statement evaluates to FALSE
$a = 5; $b = 7; if ($a > $b) echo "A is greater than B"; else echo "B is greater or equal to A";
52
if - elseif
if elseif is an extension to the ifelse statement
Allows you to add conditions for the else body
if ($a > $b) echo "A elseif ($a == echo "A else echo "B is greater than B"; $b) is equal to B"; is greater than A";
Nested if
When one decision-making statement is contained within another decision-making statement, they are referred to as nested decision-making structures
if ($SalesTotal >= 50) if ($SalesTotal <= 100) echo " <p>The sales total is between 50 and 100, inclusive.</p> ";
if ($SalesTotal >= 50 && $SalesTotal <= 100)
54
A B C F
if ($mark>= 80) echo "A"; if ($mark >= 65) echo B"; if ($mark >= 50) echo C"; else echo F";
if ($mark >= 80 && $mark < 100) echo "A"; if ($mark >= 65 && $mark < 80) echo B"; if ($mark >= 50 && $mark < 65) echo C"; else echo F";
if ($mark >= 80) echo "A"; elseif ($mark >= 65) echo B"; elseif ($mark >= 50) echo C"; else echo F";
55
Exercise #3
Ex1_c.html
Thank_You.php
56
58