Download presentation
Presentation is loading. Please wait.
Published byWilla Allison Modified over 9 years ago
1
PHP Open source language for server-side scripting Works well with many databases (e.g., MySQL) Files end in.php,.php3 or.phtml Runs on all major platforms and servers Used to develop MediaWiki, Drupal, Wordpress, Moodle
2
example.php Hello World
3
How it works Embed directly into html code (anywhere) – Delimit script with – Can also use … Server-side scripting – PHP typically installed as an Apache module – Executes within Apache – then ships html to browser Can also be installed as CGI – but slower that way More stable than Perl Apache module
4
PHP Syntax Must end in.php (or workaround) Comments: /* */ for blocks; // or # for one line Lines must end in ; Output html using echo or print Variables start with $ – Case sensitive – Loosely typed (don’t need to declare before adding a value to it; type not specified in advance) Functions & class names not case sensitive
5
Concatenation example "; $txt2="What a nice day!"; echo ($txt1. $txt2); ?> Hello World! What a nice day!
6
PHP arrays (numeric) Set up using array function: $student=array(“Joe”, 1234, “C”); …or just by direct assignment: $student[] = “Joe”; $student[] = 1234; $student[] = “C”; Then print “$student[2]”; gives?…
7
PHP arrays (associative) $student=array(name=>“Joe”, idNum=>1234, grade=>“C”); OR $student[‘name’] = “Joe”; $student[‘idNum’] = 1234; $student[‘grade’] = “C”; echo “Joe is getting a “. $student[“grade”]; Can nest arrays too.
8
Superglobal Arrays $_SERVER (data about current running server) $_ENV (data about client’s environment) $_GET (data sent via ‘get’ request) $_POST (data sent via ‘post’ request) $_COOKIE (data contained in cookies on the client’s computer) $GLOBALS (array containing all global variables)
9
GET vs POST GET Query string Limited in size Reuse query (e.g., bookmark search) Not secure POST In HTTP body Larger size limit Not secure
10
Form Handling Any form element in an HTML page is automatically available to PHP scripts!
11
Cookies Created using name, value pairs: – setcookie(“Name”, $Name, time() + seconds); – Put into header, so do this call first in script Now, future requests to server will have this data in the $_COOKIE environment variable array We’ll talk more about this in later weeks
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.