Albert wavering bobby seng
This presentation is the property of its rightful owner.
Sponsored Links
1 / 25

CPSP 229D: Web desiGN PowerPoint PPT Presentation


  • 79 Views
  • Uploaded on
  • Presentation posted in: General

ALBERT WAVERING BOBBY SENG. CPSP 229D: Web desiGN. Week Whatever: PHP. Announcements/questions/complaints. What is PHP?. Server-side scripting language P HP: H ypertext P rocessor Created in 1995; current version 5.3.3 Dynamically typed (like JavaScript) Other scripting languages:

Download Presentation

CPSP 229D: Web desiGN

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Albert wavering bobby seng

ALBERT WAVERING

BOBBY SENG

CPSP 229D: Web desiGN


Week whatever php

Week Whatever: PHP

  • Announcements/questions/complaints


What is php

What is PHP?

  • Server-side scripting language

  • PHP: Hypertext Processor

  • Created in 1995; current version 5.3.3

  • Dynamically typed (like JavaScript)

  • Other scripting languages:

    • Microsoft ASP

    • Adobe ColdFusion

    • Java (using JSP)

    • Ruby (using Rails)


Cpsp 229d web design

PHP

  • Scripts are stored on a server

  • Interpreted on servers when a page is requested

    • I request example.php

    • Server looks up the file

    • PHP software processes PHP file

    • Output is HTML+CSS+JavaScript that is returned as the requested page


Real life examples

Real Life Examples

  • Facebook

    • ‘Compressed’ PHP

  • Wikipedia

  • Photobucket

  • Yahoo!

  • YouTube


Cpsp 229d web design

PHP

  • Can run on most operating systems

  • Compatible with most servers (Apache, IIS, etc)

  • Lets you create dynamic webpages

    • Most useful when you want to insert specific custom data

  • Where does this data come from?

    • Databases!


Php mysql

PHP + MySQL

  • MySQL is a Structured Query Language database platform

  • PHP has native built-in support for MySQL

  • While interpreting a PHP script, PHP software can make multiple requests to multiple MySQL databases

  • PHP also supports many other databases


Php basics

PHP Basics

  • PHP Script can contain:

    • HTML

    • CSS

    • JavaScript

    • PHP script

  • PHP files have extension .php

    • If you save them as .html, the PHP software will not process them

  • Closed source – your users cannot read your code (unlike JavaScript)


Php basics1

PHP Basics

  • PHP scripts are written inside a <?php ?> tag

  • Anything you want interpreted has to be inside these tags

  • Example:

    <html><body><?phpecho "Hello World";?></body></html>


Php basics2

PHP Basics

  • Like Java, every line in PHP ends with a semicolon;

  • //Single-line comments

  • /*Multi-linecomments*/


Php basics3

PHP Basics

  • PHP variable names are always preceded by a $

  • Assigning a value to a variable:$variable_name = value;

  • PHP variables are loosely typed

    • Don’t have to declare variables before using them

    • Can reassign variables to hold different types of values


Php basics4

PHP Basics

  • Variables can only include alphanumeric characters and the underscore

  • Variables must start with a letter or an underscore

  • PHP variables have a single scope, usually

    • Variables in functions are limited to those functions

    • The keyword global will use global variables inside a function


The global keyword

The global keyword

<?php$a = 1;$b = 2;function Sum(){    global $a, $b;    $b = $a + $b;} Sum();echo $b;?>


Operators

Operators

+Addition+=

-Subtraction-=

*Multiplication*=

/Division/=

%Modulus%=

++Increment

--Decrement

=Assignment

.=Concatenate (Strings)


Comparison operators

Comparison Operators

==Equal to

!=Not equal to<>

<Less than

<=Less than or equal to

>Greater than

>=Greater than or equal to


Logical operators

Logical Operators

&&andAND

||orOR

!not

xorXOR


If elseif else

If/elseif/else

if (condition)

statement;

elseif (condition)

statement;

else

statement;


Switch

Switch

switch(variable){

case a:

statement;

break;

case b:

statement;

break;

default:

statement;

}


Loops

Loops

while (condition){

statements;

}

for (initialization; condition; increment){

statements;

}


Arrays

Arrays

  • Numerically indexed

  • Associatively indexed (maps)

  • Multidimensional (combination of one or any of the above)

  • Create an array with $var_name = array();

  • Index with $var_name[0] = assignment;

    or

    $var_name[$other_var] = assignment;


Php get

PHP GET

  • Built-in functions to get data from pages

  • $_GET function collects values from a form sent with method = get

    HTML Page:

    <form action="welcome.php" method="get">

    Name: <input type="text" name="fname" />

    Age: <input type="text" name="age" />

    <input type="submit" />

    </form>

    PHP Response:

    Welcome <?php echo $_GET["fname"]; ?>.<br />

    You are <?php echo $_GET["age"]; ?> years old!


Php post

PHP POST

  • Get is limited to 100 characters

    • Not awesome

  • Post has 8Mb maximum

    • Awesome


Php post1

PHP Post

HTML Page:

<form action="welcome.php" method="post">

Name: <input type="text" name="fname" />

Age: <input type="text" name="age" />

<input type="submit" />

</form>

PHP Response:

Welcome <?php echo $_POST["fname"]; ?>.<br />

You are <?php echo $_POST["age"]; ?> years old!


Resources

Resources

  • Ask Jeeves

  • AltaVista

  • http://php.net/manual/en

    • Language Reference

    • Your new best friend

      • Code examples, user questions, hints

  • http://www.w3schools.com/php/default.asp


Homework

Homework

  • Create a PHP script that outputs the current date to a page, inserted among other usual HTML elements in a full page

    • http://php.net/manual/en/function.date.php

  • Use one additional construct of PHP (array, loop, if/else, etc)

  • Upload to your account on my server as a .php file by the start of next class

  • Be creative!

  • Databases next time (real fun starts)


  • Login