Docsity

Advanced PHP Tutorial - PHP Programming - Lecture Slides, Slides of Programming Languages

Partial preview of the text

Download Advanced PHP Tutorial - PHP Programming - Lecture Slides and more Slides Programming Languages in PDF only on Docsity!

PHP Tutorial

Advanced PHP

PHP Advanced

  • PHP Date
  • PHP Include
  • PHP File
  • PHP File Upload
  • PHP Cookies
  • PHP Sessions

PHP Date() Function

( 1 st Chapter – PHP Date)

The PHP date() function is used to format a time and/or date.

  • The PHP date() function formats a timestamp to a more readable date and time.
  • A timestamp is a sequence of characters, denoting the date and/or time at which a certain event occurred.

PHP Date() Function (cont.)

( 1 st Chapter – PHP Date)

  • Syntax date( format , timestamp ) Parameter Description Required. Specifies the format of the timestamp format Optional. Specifies a timestamp. Default is the current date and time timestamp

Format the Date (cont.)

( 1 st Chapter – PHP Date)

  • Other characters, like"/", ".", or "-" can also be inserted between the letters to add additional formatting: "; echo date("Y.m.d"). ""; echo date("Y-m-d") ?>

Format the Date (cont.)

( 1 st Chapter – PHP Date)

  • The output of the code above could be something like this: 2009/05/ 2009.05. 2009 - 05 - 11

Adding a Timestamp (cont.)

( 1 st Chapter – PHP Date)

  • Syntax for mktime()
  • mktime(hour,minute,second,month,day,year,is_dst) To go

one day in the future we simply add one to the day

argument of mktime():

php

$tomorrow =

mktime(0,0,0,date("m"),date("d")+ 1 ,date("Y"));

echo "Tomorrow is ".date("Y/m/d", $tomorrow);

  • The output of the code above could be something like this:

Tomorrow is 2009 / 05 / 12

PHP Include File

  • Server Side Includes (SSI)
  • PHP include() Function
  • PHP require() Function

Server Side Includes (SSI) (cont.)

( 2 nd Chapter – PHP Include File)

  • These two functions are used to create functions, headers, footers, or elements that will be reused on multiple pages.
  • Server side includes saves a lot of work. This means that you can create a standard header, footer, or menu file for all your web pages. When the header needs to be updated, you can only update the include file, or when you add a new page to your site, you can simply change the menu file (instead of updating the links on all your web pages).

PHP include() Function ( 2 nd Chapter – PHP Include File)

  • The include() function takes all the content in a specified file and includes it in the current file.
  • If an error occurs, the include() function generates a warning, but the script will continue execution.

PHP include() Function (cont.)

( 2 nd Chapter – PHP Include File)

  • Example 2
    • Assume we have a standard menu file, called "menu.php", that should be used on all pages:

Home

About Us

Contact Us

PHP include() Function (cont.)

( 2 nd Chapter – PHP Include File)

  • All pages in the Web site should include this menu file. Here

is how it can be done:

Welcome to my home page.

Some text.

PHP require() Function ( 2 nd Chapter – PHP Include File)

  • The require() function is identical to include(), except that it handles errors differently.
  • If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.

PHP require() Function (cont.)

( 2 nd Chapter – PHP Include File)

  • Error Example include() Function