Php file upload, cookies & session
-
Upload
jamshid-hashimi -
Category
Technology
-
view
2.485 -
download
4
Transcript of Php file upload, cookies & session
![Page 1: Php file upload, cookies & session](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/1.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/2.jpg)
Agenda
• Date• Include & Require• File Upload• Cookies• Sessions
![Page 3: Php file upload, cookies & session](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/5.jpg)
Date
![Page 6: Php file upload, cookies & session](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/7.jpg)
Include & Require
include 'filename';
or
require 'filename';
<div class="leftmenu"><?php include 'menu.php'; ?></div>
![Page 8: Php file upload, cookies & session](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/8.jpg)
DEMO 1
![Page 9: Php file upload, cookies & session](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/9.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/10.jpg)
DEMO 2
![Page 11: Php file upload, cookies & session](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/11.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/15.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/16.jpg)
![Page 17: Php file upload, cookies & session](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/17.jpg)
DEMO 3
![Page 18: Php file upload, cookies & session](https://reader036.fdocuments.net/reader036/viewer/2022062300/554f1543b4c9058b388b4988/html5/thumbnails/18.jpg)
QUESTIONS?