PHP-File-Inclusion-A-Deep-Dive PHP Scripts
PHP-File-Inclusion-A-Deep-Dive PHP Scripts
Presented by
Prabin kandel
Understanding File Inclusion
File inclusion allows you to bring code from other files It promotes code reusability and improves the
into your main PHP script. organization of complex projects.
File inclusion (Include & Require)
In PHP, include and require are used to include files into a script to
reuse code.
1 Include 2 Require
Preventing File Inclusion
Vulnerabilities
Sanitize Input
Escape or validate user-supplied data before using it in
file paths.
Whitelisting
Restrict file inclusion to a predefined list of allowed files.
Restrict Access
Limit access to sensitive files and folders.
Sessions & cookies
Session cookies
Sessions store data on the server side and are used for temporary Cookies store small pieces of data on the client side for long-term usage .
state maintenance. Example:
Example: <?php
<?php setcookie("user", "JohnDoe", time() + (30 * 24 * 60 *
session_start(); 60), "/");
2 Data Storage
Stores session data on the server, accessible across
multiple pages.
3 Session End
Destroys the session and clears all associated data.
Implementing Cookies in PHP
Set Cookie
1 Create a cookie with a name, value, and expiration time.
Retrieve Cookie
2
Access the value of a cookie using its name.
Delete Cookie
3
Remove a cookie by setting its expiration time to the past.
Best Practices for Session and Cookie
Management
1 2 3
Secure Settings Limited Scope Regular Cleaning
Use strong session and cookie Restrict cookie access to specific Remove expired sessions and
security settings. domains and paths. cookies regularly.