1 / 16

IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction

IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction. Deniss Kumlander. What is PHP?. PHP stands for H ypertext P reprocessor PHP is a server-side scripting language , like ASP PHP scripts are executed on the server PHP supports many databases (MySQL, Oracle etc.)

dorit
Download Presentation

IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IDK0040 Võrgurakendused Iharjutus 06:PHP: Introduction Deniss Kumlander

  2. 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, Oracleetc.) • PHP is an open source software (OSS) • PHP is free to download and use

  3. 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"

  4. 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.

  5. 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

  6. Basic PHP Syntax A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code. <html> <body> </body> </html>

  7. 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>

  8. 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.

  9. 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.

  10. 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>

  11. 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>

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

  13. Output etc. <html> <body> <?php $txt1="world"; echo "Hello $txt1, hello php!" ; ?> </body> </html>

  14. 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>

  15. Environent variables <?php phpinfo(); ?>

  16. 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>

More Related