php file upload, cookies & session

18
PHP File Upload, Cookies & Session Jamshid Hashimi Trainer, Cresco Solution http://www.jamshidhashimi.com [email protected] @jamshidhashimi ajamshidhashimi Afghanistan Workforce Development Program

Upload: jamshid-hashimi

Post on 10-May-2015

2.482 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Php file upload, cookies & session

PHP File Upload, Cookies & Session

Jamshid HashimiTrainer, Cresco Solution

http://www.jamshidhashimi.com [email protected] @jamshidhashimi ajamshidhashimi

Afghanistan Workforce Development Program

Page 2: Php file upload, cookies & session

Agenda

• Date• Include & Require• File Upload• Cookies• Sessions

Page 3: Php file upload, cookies & session

Date

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

echo date("Y/m/d") . "<br>";echo date("Y.m.d") . "<br>";echo date("Y-m-d");

Page 4: Php file upload, cookies & session

Date

• The strftime function can format that timestamp in any way you’d like. You’ll pass it a format string and the timestamp and get the date back out.

echo strftime("%B %d, %Y", time());

Page 5: Php file upload, cookies & session

Date

Page 6: Php file upload, cookies & session

Include & Require

• In PHP, you can insert the content of one PHP file into another PHP file before the server executes it. – require will produce a fatal error

(E_COMPILE_ERROR) and stop the script– include will only produce a warning (E_WARNING)

and the script will continue

Page 7: Php file upload, cookies & session

Include & Require

include 'filename';

or

require 'filename';

<div class="leftmenu"><?php include 'menu.php'; ?></div>

Page 8: Php file upload, cookies & session

DEMO 1

Page 9: Php file upload, cookies & session

PHP File Upload

• With PHP, it is possible to upload files to the server.

<!DOCTYPE html><html><body><form action="upload.php" method="post"enctype="multipart/form-data"><label for="file">Filename:</label><input type="file" name="file" id="file"><br><input type="submit" name="submit" value="Submit"></form></body></html>

Page 10: Php file upload, cookies & session

DEMO 2

Page 11: Php file upload, cookies & session

Cookies

• A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

• I am not a big fan of cookies!

Page 12: Php file upload, cookies & session

Cookies

• We cannot trust data in $_COOKIES to contain legitimate values– Can easily modified!

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

setcookie("class", "AWD 01", time()+3600);

Page 13: Php file upload, cookies & session

Session

• A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.

Page 14: Php file upload, cookies & session

Sessions

• php.ini – session.save_path• Maximum size of a PHP session– 128 M

• session_start()• isset()• unset()• session_destroy()

Page 15: Php file upload, cookies & session

Sessions<?phpsession_start();// store session data$_SESSION['visit'] = 1;?>

<html><body>

<?php//retrieve session dataecho "Pageviews=". $_SESSION['visit'];?>

</body></html>

Page 16: Php file upload, cookies & session
Page 17: Php file upload, cookies & session

DEMO 3

Page 18: Php file upload, cookies & session

QUESTIONS?