Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP syntax basics. Personal Home Page This is a Hypertext processor It works on the server side It demands a Web-server to be installed.

Similar presentations

Presentation on theme: "PHP syntax basics. Personal Home Page This is a Hypertext processor It works on the server side It demands a Web-server to be installed."— Presentation transcript:

1 PHP syntax basics

2 Personal Home Page This is a Hypertext processor It works on the server side It demands a Web-server to be installed

3 What is a Web-server? A program hat helps to deliver content that can be accessed through the Internet. It use a protocol to deliver the data.Internet It has a load limit – up to 1000 per one IP and totally up to 80.000 concurrent connections

4 The overloaded server can: Deny the access and return an error Allow unauthorized access Typical server-side http Errors: 500 – internal server error (many possible reasons) 502 – bad gateway (can’t connected to the specific address) 503 – service is not available 504 – gateway timeout

5 Typical Client-side Errors 400 – bad request (syntax error in the request) 403 – forbidden 404 – not found (accessing non-existing page) 444 – no response

6 World leaders Apache – free software developed by an open commuunity IIS – Microsoft, a part of Windows – Server XX OS

7 XAMPP – free, ready for use software

8 GET and POST HTTP methods Both the method submit a form to the server GET – is the default method POST allows encoding data GET" is basically for just getting (retrieving) data whereas "POST" may involve anything, like storing or updating data, or ordering a product, or sending E-mail

9 How it works "get" - -, the user agent takes the value of action, appends a ? to it, then appends the form data set, encoded using the application/x-www-form- urlencoded content type. form data are restricted to ASCII codes. "post" --, the user agent conducts an HTTP post transaction using the value of the action attribute and a message created according to the content type specified by the enctype attribute.

10 Practical Example

11 Starting PHP 1.Install XAMPP, run it as an application 2.Check if it works If not – check the ports (e.g. Skype) 3. Create “Hello World” in your root 4. Start it from the browser using “localhost”

12 Assignment 1 Php, html and JavaScript Example 2 dd dd “); Example 3 echo ("\n \n"."alert (\"JavaScript\");". " \n"); ?>

13 Variables of PHP and HTML PHP variables must start with the character '$'. $username = "Christopher"; echo ($username); Accessing HTML variables from PHP Please type your name here: You typed:

14 Assignment One page with a text field and a button. User clicks the button a new page appears and prints the user input.

15 PHP code as a link Open a PHP in a new window: Welcome Show name.

16 PHP constants Example: if the constant exists? if (defined("YELLOW")) { echo (" \n"); }

17 Assignment Define a contant Create PHP code for the link Click the link anf output the php constant

18 Built-in constants and functions CASE SENSITIVE !!! echo(PHP_OS); phpinfo() echo php_uname(); get_browser ([ string $user_agent [, bool $return_array = false ]] ) $browser = get_browser(null, true); print_r($browser);

19 Strings and and type casting $str = "222B Baker Street"; // conversion $x = 3 + $str; // $x = 225; echo($x); $first = "Phineas"; // concatenation $last = "Phop"; $full = $first. " ". $last; $a = 11.2; $a = (int) $a; $a = (double) $a; $b = (string) $a; echo($a);

20 Assignment Create two text fields: name and family name Create a button The user clicks the button, the system outputs family name + first name

21 Type validation is_int(), is_integer(), is_long() And so on…. echo(is_float($a)); $ProductID = "432BB"; $i = intval($ProductID); // result is 432

22 If operator $i=2; if ($i > 1) { echo(">1"); } else { echo("<=1");} ?>

23 Error supression // do not output the error to the browser

24 Assignment Simple validator Two text fields and a button. If the user leave a field empty the system reports an error and FORMS a link back

25 Loops while (condition) { // statements } do { echo ("\t $i \n"); } while (++$i < $total_parts); for ($i = 1; $i < 11; ++$i) { echo ("$i \n"); // Prints from 1 to 10 }

26 Assignment 012345678 9876543210 The same, but each number in a cell of the table The same but if the user clicks a button FOR 3 EXTRA POINTS! Output it sequentially (one number per second)

27 functions

28 Variables and its Scope Global variables are listed in $GLOBALS

29 Arrays $countries[0] = "cr"; $countries[1] = "de"; $countries[2] = "us"; Or $countries = array ("cr", "de", "us"); Example for ($idx = 0; $idx < count ($countries); ++$idx) { // Print each element on its own line: echo ("$countries[$idx] \n"); }

30 Arrays : Sorting { "@context": "", "@type": "ImageObject", "contentUrl": "", "name": "Arrays : Sorting

31 Multi-dimensional arrays $continents = array ("Europe" => array ("de", "uk"), "North America" => array ("ca", "cr", "us"));

32 Files int fopen(string filename, string mode); Value Description a - appending only. r Open a file for reading only. w Open a file for writing only. They also use a+, r+ w+ $file=fopen(“mydata.txt", “r") $text = fread($file, 10); int fclose(int fp); fclose($file);

33 Files : reading

34 Example and appending writing

35 Assignments add two numbers on the client side with php The same but on the server side Save input to a file Input data to a text area, sort and save to a file Input a text in textarea and save it to a file but one symbol per line.

36 Assignment 4 Modify index.htm automatically. Every 2 minutes generate a text string and place it to the body of index.htm Use different categories.

Download ppt "PHP syntax basics. Personal Home Page This is a Hypertext processor It works on the server side It demands a Web-server to be installed."

Similar presentations

Ads by Google