Professional Documents
Culture Documents
Week 3
1
Step 1
2
Step 2
The installer is much the same as for any other software - just double click it to run then
follow the prompts.
3
Step 3
You won’t need to change any of the installation settings, the defaults are all good as is.
4
Step 4
Of particular note, you should leave the installation drive as the C:\ drive in order for things to
function correctly. You may also need to grant approval for XAMPP’s Apache installation to have
network access through Windows Defender or any other firewall you might be running.
5
Step 5
Continue following the prompts. When the installation is complete, leave the option checked that
says “Do you want to run the Control Panel now?”, then close the installer and you’ll see the Control
Panel appear. If you missed the chance to leave that box checked, just run XAMPP from your list of
installed software to start the Control Panel instead.
6
Step 6: How to run PHP program in Xampp step-by-
step?
● Write this program in a notepad and save it as index.php (or any other name).
○ <?php echo "Welcome to CS 207 class" ?>
● After completion of the installation, you can use the XAMPP Control Panel to start/ stop all
servers.
● Start Mysql and Apache servers.
7
Step 6: How to run PHP program in Xampp step-by-
step?
● Create a new folder inside htdocs folder (C:/XAMPP/htdocs) and name the folder with your Project name.
● Copy index.php to your folder inside htdocs.
● In order to get the dashboard for localhost: search http://localhost (or http://127.0.0.1:8080) in any browser.
8
Step 6: How to run PHP program in Xampp step-by-
step?
● Create a new folder inside htdocs folder (C:/XAMPP/htdocs) and name the folder with your Project name.
● Copy index.php to your folder inside htdocs.
● In order to get the dashboard for localhost: search http://localhost (or http://127.0.0.1:8080) in any browser.
9
INTRODUCTION : GET and POST
A client (browser) submits an HTTP request to the server; then the server returns a
response to the client. The response contains status information about the request and
may also contain the requested content.
10
GET
11
POST
12
GET - example1
13 13
POST- example1
14 14
GET - example2
<?php
if( $_GET["name"] || $_GET["age"] ) {
echo "Welcome ". $_GET['name']. "<br />";
echo "You are ". $_GET['age']. " years old.";
exit();
}
?>
<html>
<body>
</body>
</html>
15
POST- example2
<?php
if( $_POST["name"] || $_POST["age"] ) {
if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) {
die ("invalid name and name should be alpha");
}
echo "Welcome ". $_POST['name']. "<br />";
echo "You are ". $_POST['age']. " years old.";
exit();
}
?>
<html>
<body>
</body>
</html>
16
GET - example 3
<html>
<body>
</body>
</html>
17
registration.php looks like this:
<html>
<body>
Welcome <?php echo $_GET["name"]; ?>!
Your email address is <?php echo $_GET["email"]; ?>
</body>
</html>
When the user clicks on the "Submit button", the URL will be something like this:
18
POST- example3
<html>
<body>
</body>
</html>
When the user fills out and submits the form, then form data will be sent to PHP file: called
registration.php
19
registration.php page has following code to print submitted data:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?>!
Your email address is <?php echo $_POST["email"]; ?>
</body>
</html>
When the user clicks on the "Submit button", the URL will be something like this:
20
Email using PHP
HERE,
● “$to_email_address” is the email address of the mail recipient
● “$subject” is the email subject
● “$message” is the message to be sent.
● “[$headers]” is optional, it can be used to include information such as CC, BCC
21
Simple Mail Transmission Protocol (SMTP)
● PHP mailer uses Simple Mail Transmission Protocol (SMTP) to send mail.
● On a hosted server, the SMTP settings would have already been set.
● The SMTP mail settings can be configured from “php.ini” file in the PHP installation folder.
● Configuring SMTP settings on your localhost Assuming you are using xampp on windows, locate the
“php.ini” in the directory “C:\xampp\php”.
● Open it using notepad or any text editor. We will use notepad in this example. Click on the edit menu
22
Simple Mail Transmission Protocol (SMTP)
23
Simple Mail Transmission Protocol (SMTP)
24
PHP Mail Example
● Output:
25
PHP and JSON
JSON stands for JavaScript Object Notation, and is a syntax for storing and exchanging data.
Since the JSON format is a text-based format, it can easily be sent to and from a server, and used as a
data format by any programming language.
PHP has some built-in functions to handle JSON. First, we will look at the following two functions:
● json_encode()
● json_decode()
PHP - json_encode():
OUTPUT:
{"Peter":35,"Ben":37,"Joe":43}
26
PHP and JSON
PHP - json_decode():
The json_decode() function is used to decode a JSON object into a PHP object or an associative array.
● Example below shows how to access the values from a PHP object:
OUTPUT: 353743
● Example below shows how to access the values from a PHP associative array:
OUTPUT: 353743
27
Thank you
28