16
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Embed Size (px)

Citation preview

Page 1: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

IDK0040 Võrgurakendused I

harjutus 06:PHP: Introduction

Deniss Kumlander

Page 2: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

What is PHP?

• PHP stands for Hypertext Preprocessor • PHP is a server-side scripting language, like ASP • PHP scripts are executed on the server • PHP supports many databases (MySQL, Oracle etc.) • PHP is an open source software (OSS) • PHP is free to download and use

Page 3: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

What is a PHP File?

• PHP files may contain text, HTML tags and scripts

• PHP files are returned to the browser as plain HTML 

• PHP files have a file extension of ".php", ".php3", or ".phtml"

Page 4: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

NB

You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain HTML. This is because the scripts are executed on the server before the result is sent back to the browser.

Page 5: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Why PHP?

• PHP runs on different platforms (Windows, Linux, Unix, etc.)

• PHP is compatible with almost all servers 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 efficient on the server side

Page 6: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Basic PHP Syntax

A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.

<html><body>

</body> </html>

Page 7: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Basic PHP Syntax

A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.

<html><body>

<?php echo "Hello World"; ?></body>

</html>Result on client:<html> <body> Hello World </body> </html>

Page 8: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Basic PHP Syntax• A PHP scripting block always starts with <?php (or <?

depending on the server configuration) and ends with ?>.

• A PHP scripting block can be placed anywhere in the document.

• Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.

• There are two basic statements to output text with PHP: echo and print.

Page 9: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

elrond.tud.ttu.ee

<html><head></head>

<body><?php echo "Hello World"; ?>

</body> </html>

AK 213: – create this file as a xx.php and place it to W disk

Home computer:– Save the file somewhere– ftp to ftp.tud.ttu.ee using your TTU username (something like t010668) and

password– Upload the file into the public_html folder

After that run the program: – Open a browser and input into the address:

elrond.tud.ttu.ee/~t010668/xxx.php to see the result, where instead of 010688 use your (!) “matrikli number” / student code.

Page 10: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Variables in PHP• All variables in PHP start with a $ sign symbol. • Variables may contain strings, numbers, or arrays.<html>

<body><?php

$txt="Hello World"; echo $txt;

?></body>

</html>

Page 11: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Output etc.

• To concatenate two or more variables together, use the dot (.) operator

<html> <body><?php $txt1="Hello World"; $txt2=1234; echo $txt1 . " " . $txt2 ; ?></body> </html>

Page 12: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Output etc.

echo "<h1>Hello and welcome to my website.</h1>"

echo "<font face=\"Arial\" color\"#FF0000\">Hello and welcome to my website.</font>"

Page 13: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Output etc.

<html> <body>

<?php

$txt1="world";

echo "Hello $txt1, hello php!" ;

?>

</body> </html>

Page 14: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Environent variables<html> <head> <title> Example 1 </title> </head><body>

<?php // Environent variables store information about // the user's and server's environment $info=$_SERVER["HTTP_USER_AGENT"];print("You are using $info<br>");print("Your address is: " . $_SERVER["REMOTE_ADDR"]);

?></body> </html>

Page 15: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Environent variables

<?php phpinfo(); ?>

Page 16: IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander

Environent variables<html>

<head> <title> Example 1 </title> </head>

<body>

<?php

$info=$_SERVER["HTTP_USER_AGENT"];

print("You are using $info<br>");

print("Your address is: " . $_SERVER["REMOTE_ADDR"]);

?> <br/>

General info: <?php phpinfo(); ?>

</body> </html>