Thursday, 4 January 2018

Session AND Cookie - php ini

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = "c:/wamp/tmp"

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 64M

; Maximum number of files that can be uploaded via a single request

max_file_uploads = 20
---------------------------------------------------------------------------------------------------

Cookies are used to identify sessions. Visit any site that is using cookies and pull up either Chrome inspect element and then network or FireBug if using Firefox.
You can see that there is a header sent to a server and also received called Cookie. Usually it contains some personal information (like an ID) that can be used on the server to identify a session. These cookies stay on your computer and your browser takes care of sending them to only the domains that are identified with it.
If there were no cookies then you would be sending a unique ID on every request via GET or POST. Cookies are like static id's that stay on your computer for some time.
session is a group of information on the server that is associated with the cookie information. If you're using PHP you can check the session.save_path location and actually "see sessions". They are either files on the server filesystem or backed in a database.

Cookies
  • Cookies are stored in browser as text file format.
  • It is stored limit amount of data. It is only allowing 4kb[4096bytes]
  • It is not holding the multiple variable in cookies.
  • We can accessing the cookies values in easily. So it is less secure.
  • The setcookie() function must appear BEFORE the tag.
Destroy Cookies:
  • If we Closing the browsers at the time.
  • Setting the cookie time to expire the cookie.
Example:
<?php

setcookie(name, value, expire, path, domain, secure, httponly);
$cookie_uame = "codingslover";
$cookie_uvalue = "website";

//set cookies for 1 hour time
setcookie($cookie_uname, $cookie_uvalue, 3600, "/");

//expire cookies
setcookie($cookie_uname,"",-3600);

?>
Sessions
  • Sessions are stored in server side.
  • It is stored unlimited amount of data.
  • It is holding the multiple variable in sessions.
Destroy Sessions :
  • Using unset() session, we will destroyed the sessions.
  • Using session_destory(), we we will destroyed the sessions.
Example:
<?php

session_start();

//session variable
$_SESSION['testvaraible'] = 'Codings';

//destroyed the entire sessions
session_destroy(); 

//Destroyed the session variable "testvaraible".
unset($_SESSION['testvaraible']);

?>

No comments:

Post a Comment