+ All Categories
Home > Documents > Pertemuan 2 PHP HTML State

Pertemuan 2 PHP HTML State

Date post: 06-Apr-2018
Category:
Upload: habib-imron
View: 220 times
Download: 0 times
Share this document with a friend

of 13

Transcript
  • 8/2/2019 Pertemuan 2 PHP HTML State

    1/13

    28/02/20

    Page 1

    PHP, HTML, STATE

    Achmad Arwan, S.Kom

    Page 2

    PHP( PHP: Hypertext Preprocessor)

    A programming language devised by Rasmus Lerdorf in1994 for building dynamic, interactiveWeb sites.

    Cross-platform:

    Most PHP code can be processed without alteration on

    computers running many different operating systems.

    For example, a PHP script that runs on Linux generally

    also runs well on Windows.

    HTML-embedded:

    PHP code can be written in files containing a mixture ofPHP instructions and HTML code.

  • 8/2/2019 Pertemuan 2 PHP HTML State

    2/13

    28/02/20

    Page 3

    PHP( PHP: Hypertext Preprocessor)

    Server-side:

    The PHP programs are run on a serverspecifically aWeb server.

    Web-scripting language:

    PHP programs run via a Web browser.

    Case Sensitive

    Page 4

    System requirem entTo run php code you will need at least the following software:

    1. Server software (an operating system such as Windows 7or Linux)

    2. A PHP-compatible Web server (such as Apache orInternet Information Server (IIS)

    3. PHP5 (get the download from www.php.net)

    4. A relational database system (we use SQLite or MySQL)

    5. A Web browser (such as IE, Mozilla, and so on)

    6. A text editor, such as Notepad, Emacs, vi, BBEdit, and soon.

  • 8/2/2019 Pertemuan 2 PHP HTML State

    3/13

    28/02/20

    Page 5

    Hello.php

    PHP Test

    Page 6

    Variables

    Issues concerning creating variables:

    1. Naming

    2. Data type

    3. Scop

  • 8/2/2019 Pertemuan 2 PHP HTML State

    4/13

    28/02/20

    Page 7

    Naming Variables

    1. Variable names begin with a dollar sign ($).

    2. The first character after the dollar sign must bea letter or an underscore.

    3. The remaining characters in the name may beletters, numbers, or underscores without afixed limit

    example

    Page 8

    PHP Data TypesData type Description

    Boolean Scalar; either True or False

    Integer Scalar; a whole number

    Float Scalar; a number which may have adecimal place

    String Scalar; a series of characters

    Array Compound; an ordered map (containsnames mapped to values)

    Object Compound; a type that may containproperties and methods

    Resource Special; contains a reference to anexternal resource, such as a handler toan open file

    NULL Special; may only contain NULL as avalue, meaning the variable; explicitlydoes not contain any value

  • 8/2/2019 Pertemuan 2 PHP HTML State

    5/13

    28/02/20

    Page 9

    Operators

    Operator NameDescription

    Example Result

    x + y AdditionSum of xand y

    2 + 2 4

    x - y SubtractionDifferenceof x and y

    5 - 2 3

    x * yMultiplication

    Product ofx and y

    5 * 2 10

    x / y DivisionQuotient ofx and y

    15 / 5 3

    x % y Modulus

    Remainder

    of x dividedby y

    5 % 2

    10 % 810 % 2

    1

    20

    - x NegationOpposite ofx

    - 2

    Page 10

    Operators

    http://www.w3schools.com/php/php_operators.asp

  • 8/2/2019 Pertemuan 2 PHP HTML State

    6/13

    28/02/20

    Page 11

    Variable Scope

    Local Scope

    Any Variable used inside function

    Global Scope

    Any variable outside function

    Page 12

    Super Global arraysArray Description

    $GLOBALS Has a reference to every variable that has global scope in aPHP program. Many of the variables in it are also in othersuperglobal arrays

    $_SERVER Includes everything sent by server in the HTTP response,such as the name of the currently executing script, servername, version of HTTP, remote IP address, and so on.Although most Web server software produces the sameserver variables, not all do, and not all server variablesnecessarily have data in them

    $_GET Contains all the querystring variables that were attached tothe URL, or produced as a result of using the GET method

    $_POST Contains all the submitted form variables and their data.You use variables from the $_POST or $_REQUEST arraysextensively in most of your PHP programs. For example, tomake use of a username or password (or any other data)submitted as part of a form, you'll use PHP variables fromthe $_REQUEST array

  • 8/2/2019 Pertemuan 2 PHP HTML State

    7/13

    28/02/20

    Page 13

    Super Global arrays

    Array Description

    $_COOKIE Contains all cookies sent to the server by the browser. Theyare turned into variables you can read from this array, andyou can write cookies to the user's browser using thesetcookie() function. Cookies provide a means of identifyinga user across page requests (or beyond, depending uponwhen the cookie expires) and are often used automaticallyin session handling

    $_FILES Contains any items uploaded to the server when the POSTmethod is used. It's different from the $_POST arraybecause it specifically contains items uploaded (such as anuploaded image file), not the contents of submitted formfields

    $_ENV Contains data about the environment the server and PHP

    are operating in, such as the computer name, operatingsystem, and system drive

    $_REQUEST Contains the contents of the $_GET, $_POST, and$COOKIE arrays, all in one

    Page 14

    Query String Sometime, you could write a PHP program that

    generates a query string attached to a URL using codesuch as this (assuming you had the $first_name and$last_name variables already set):

    Ex:

  • 8/2/2019 Pertemuan 2 PHP HTML State

    8/13

    28/02/20

    Page 15

    Attributs Forms Elements

    Action Attribute Tells to server which page to go to

    ...

    Method Attribute The method attribute controls the way that information is

    sent to the server.

    or

    Page 16

    Get Value

    Browser automatically appends theinformation to the URL when it sends thepage request to the web server

    Ex

  • 8/2/2019 Pertemuan 2 PHP HTML State

    9/13

    28/02/20

    Page 17

    URL EncodingCharacter URL Encoding

    Tab %09

    Space %20

    ! %21

    " %22

    # %23

    % %25

    & %26

    ( %28

    ) %29

    + %2B

    , %2C

    . %2E

    / %2F

    : %3A

    ; %3B

    %3E

    = %3D

    ? %3F

    @ %40

    \ %5C

    Page 18

    Post Value

    Information in the form is sent inthe body of http request anddoesnt appear in the url

  • 8/2/2019 Pertemuan 2 PHP HTML State

    10/13

    28/02/20

    Page 19

    HTML Form Fields

    Text Fields

    Password Field

    Radio Buttons

    Checkboxes

    Submit Button

    Hidden fields

  • 8/2/2019 Pertemuan 2 PHP HTML State

    11/13

    28/02/20

    Page 21

    Consept of State

    How to keep login on facebookwhile you browse your friendsprofiles

    How to keep your shopping cartwhile you browse your favoritegoods

    Page 22

    COOKIES

    A cookie is a small file that theserver embeds on the user'scomputer.

    A cookie is often used to identify auser.

    Web sites can usually only modifytheir own cookies.

  • 8/2/2019 Pertemuan 2 PHP HTML State

    12/13

    28/02/20

    Page 23

    COOKIES

    Set cookies setcookie(name, value, expire, path, domain);

    Retrieve cookies $_COOKIE[name cookie"];

    Page 24

    SESSIONS

    With Session user allowed to storeinformation on the server for lateruse (i.e username, shopping item).

    Session information is temporaryand will be deleted after the userhas left the website.

    Sessions work by creating a uniqueid (UID) for each visitor and storevariables based on this UID.

  • 8/2/2019 Pertemuan 2 PHP HTML State

    13/13

    28/02/20

    Page 25

    SESSIONS

    Starting session

    Storing session

    Retrieve session

    Destroy Session

    Page 26


Recommended