It filter the variable as per the specified ID
Example
It filter the variable as per the specified ID
Example
| FILTER_VALIDATE_IP | Check whether the given IP is valid or not |
| FILTER_VALIDATE_EMAIL | Check whether the email is valid or not |
| FILTER_VALIDATE_INT | Check whether the value is Integer or not |
| FILTER_VALIDATE_FLOAT | Check whether the value is float or not |
| FILTER_VALIDATE_URL | Check whether the url is valid or not |
| FILTER_SANITIZE_SPECIAL_CHARS | It Escapes special characters like &,< etc |
| FILTER_CALLBACK | It can be used to call a user defined function to filter the value |
| FILTER_SANITIZE_STRING | Strip tags and encode special characters |
| FILTER_SANITIZE_STRIPPED | Strips or encodes unwanted characters |
| FILTER_SANITIZE_ENCODED | Encode special characters |
| FILTER_SANITIZE_EMAIL | Remove all illegal email characters |
| FILTER_SANITIZE_NUMBER_INT | Remove all illegal integer characters |
| FILTER_SANITIZE_NUMBER_FLOAT | Remove all illegal characters from a float number |
| FILTER_SANITIZE_MAGIC_QUOTES | It adds slashes before quotes |
| FILTER_UNSAFE_RAW | Encode special characters |
| FILTER_VALIDATE_BOOLEAN | Return TRUE for “true”, “1”, “on” and “yes”, FALSE for “0”, “false”, “off”, “no”, and “”, NULL otherwise |
| FILTER_SANITIZE_URL | Remove all unwanterd characters form a URL |
| filter_var() | – It gets variable and filter the same as per the ID given |
| filter_has_var() | – Can be used to check whether a variable of specified input type exists |
| filter_input() | – Read the input from the outside script and filter the same |
| filter_var_array() | – Filter multiple variable after reading them |
| filter_id() | – Diaplay the ID number of a given filter |
| filter_input_array() | – Read more than one input from the outside script and filter all |
| filter_list() | – print all filter as an array |
PHP Filters are extensions use to validate inputs from a user or web services .
We must use filter functions to filter the data
Mainly two types of files are out there (Validating filters and sanitizing filters)
Example :
filter_var(variable, filter, options)
Variable : its holds the values to be filtered
filter : Its the id of filter .its an optional and the default filter is FILTER_SANITIZE_STRING
options : can be an array of options/flags
You can delete the cookie by setting expiration date in the past
Example:
<?php
setcookie(“user”, “”, time()-3600);
?>
// Display cookie value
<?php
echo $_COOKIE[“user_name”];
?>
You can view all cookies as follows
<?php
print_r($_COOKIE);
?>
Cookies can be created using the function ‘ setcookie(name,Value ,exp,path,domain)’ and its arguments are given below
Name :Name of the cookie that store the value and it is using to retrieve the stored data
Value : Its the value to be stored in the cookie ()generally we store login details like username , password)
exp : This is the the time that cookie lasts . if its not set ,the cookie will get destroyed when the browser closed .
path : This is path where the cookie to be stored
Domain: Domain where the cookie to be generated
Example
======
<?php
setcookie(“user_name”, “phpcodez”, time()+3600);
?>
Cookies can be used to store user information for future use . Cookies allow us to store data in users’ machine it self . Cookie is a small file that the server generate in user machine and using that file server can identify the user .When ever the browser send http request to the server , it send the cookies as well . Cookies can be created using PHP functions .
You can delete / Destroy session using the PHP function unset()
Example
<?php
session_start();
if(isset($_SESSION[‘phpcodez_views’]))
unset($_SESSION[‘phpcodez_views’]);
?>
Also its possible to completely delete the data using the function session_destroy ()
Example
<?php
session_destroy();
?>
Before using a session variable ,we must check if that variable exists in $_SESSION array and that can be done using the function .
Example
<?php
session_start();
if(isset($_SESSION[‘phpcodez_views’]))
$_SESSION[‘phpcodez_views’] = $_SESSION[‘phpcodez_views’]+ 1;
else
$_SESSION[‘phpcodez_views’] = 1;
?>