php “personal home page hypertext pre-processor” (a recursive acronym) allows you to create...

14
PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database.

Upload: eric-ray

Post on 21-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

PHP

“Personal Home Page Hypertext Pre-processor”

(a recursive acronym)

Allows you to create dynamic web pages and link web pages to a database.

Page 2: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

Update (Oct 2013): change of server name

• Please note the server name is no longer rm4ftp but is now ictweb

• E.g. wherever you see the server address rm4ftp, use ictweb instead, e.g.

http://rm4ftp/php/helloworld.php

change to:

http://ictweb/php/helloworld.php

Page 3: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

PHP – open and closing tags

<?php?>

<php? ------ split ------- ?>

<? = opening tag

?> = closing tag

<?php

php code in here

?>

Option 2 – only use if web server enabled to recognise this

<??>

<? ------ split ------- ?>

<? = opening tag

?> = closing tag

<?

php code in here

?>

Option 1 – safest – this is the standard format. Note the mirror symmetry.

Page 4: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

PHPPHP can be included directly within the HTML source code itself.

Save the file with the .php extension and upload it to a PHP enabled web server (check with your host)

In the example opposite, the page was uploaded to a local intranet testing server and opened in Internet Explorer (link below to try)

helloworld.php

Create source codeSave with .php extension, upload to web server

Open page in browser using the web URL for the page

Notice the web server has “parsed” the PHP script before sending it to web browser (right click > view source)

OUTPUT

Page 5: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

PHPPHP may be separately coded without additional HTML (i.e. without the <HTML>, <BODY>, <HEAD> , etc.), and opened in a web browser

Save the file with the .php extension and upload it to a PHP enabled web server (check with your host). Link to example, below:

helloworld2.php

Create source codeSave with .php extension, upload to web server

Open page in browser using the web URL for the page

OUTPUT

Page 6: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

PHP – default home page

The default name for a home page is normally “index” (e.g. index.html). E.g. save the page below as index.php then upload to web server.

Enter website address, in the example opposite this is the local intranet testing server

Page 7: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

PHP InfoCreate a page with the code shown opposite.

Save the page as phpinfo.php

Upload the file to the server

phpinfo.php

The phpinfo() function outputs server information. For security, only use this temporarily, remove it afterwards

Page 8: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

includeThe page opposite was created using 3 files:

• include.php• header.html• footer.html

These are uploaded to the PHP enabled web server.

Here is the final page:

include.php

header.html

footer.html

Page 9: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

includeHere are the 3 web pages shown separately:

• header.html (top)

• include.php (middle)

• footer.html (bottom)

Common elements such as the header and footer can be created as separate files then combined using the include statement

Page 10: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

includeHere is an example of the source code for combining other web pages using the include statement.

header.html

footer.html

Page 11: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

echoEcho is a “language construct” that looks like a function.

It allows more than one value to be output to screen (printed).

Examples

<?php

echo "This is a better place ";echo ("This is a better place");echo ("This is a <b>better</b> place");

?>

Page 12: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

php.netPHP can be downloaded and installed easily, and is freely available

There is also a lot of support for PHP

Page 13: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

WAMP

“Windows Apache MySQL PHP”

(WAMP Server)

Allows you to create a testing server on your own PC and configure the server to run PHP and MySQP.

Alternatives web servers include MAMP (Mac), LAMP (Linux) and XAMPP

Page 14: PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database

sourceforge.netWampServer is a Windows web development environment. It allows you to create web applications with Apache2, PHP and a MySQL database.

WAMP can be installed by searching for a reputable source to download from, e.g. sourceforge.net

url: http://localhost