Home Computer Problems What is Difference Between Cookies and Sessions in php
Computer Problems
What is Difference Between Cookies and Sessions in php
Date: 18 Jul , 2015
Category: Computer Problems
View: 93516
Like
0 Like
Dislike
0 Des
Solutions




















Cookies

  • In php $_COOKIE super global variable is used to manage cookie.
  • Cookies are client-side files that contain user information.
  • We have to set cookie max life time manually with php code with setcookie function. In above example

    setcookie("email", 'test@example.com',time()+3600); /* expire in 1 hour */

    Cookie Name : email
    Cookie Value : test@example.com
    Expire time : I hour after current time (1 Hour = 3600 Seconds)
  • You don't need to start Cookie as It is stored in your local machine.
  • Official MAX Cookie size is 4KB
  • There is no function named unsetcookie() ,

    Although if you need to delete cookie then you have set cookie in any previous date, so that cookie will automatically disabled/deleted.
    setcookie("email", 'test@example.com',time()+3600); /* expire in 1 hour */
  • Cookie ends depends on the life time you set for it.

Sessions

  • In php $_SESSION super global variable is used to manage session.
  • Sessions are server-side files that contain user information.
  • Session Max life time is 1440 Seconds(24 Minutes) as defined in php.ini file
    in php.ini on line 1604 you can find You can edit this value if you need custom ,

    http://php.net/session.gc-maxlifetime session.gc_maxlifetime = 1440
    session life.
  • Before using $_SESSION, you have to write session_start();
    In that way session will start and you can access $_SESSION variable on that page.
  • You can store as much data as you like within in sessions.The only limits you can reach is the maximum memory a script can consume at one time, which by default is 128MB.

    php.ini line 479 ;
    http://php.net/memory-limit
    memory_limit = 128M
  • Session is dependent on COOKIE.
    Because when you start session with session_start() then SESSIONID named key will be set in COOKIE with Unique Identifier Value for your system.
    So that when you communicate with server next time then with this saved SESSIONID, Server will identify who you are?
    session_destroy(); is used to "Destroys all data registered to a session", and if you want to unset some key's of SESSION then use unset() function.

    unset($_SESSION["key1"], $_SESSION["key2"])
  • Session ends when user close his browser.



By.
BebbiSingh
Comment :

Search tags : What is Difference Between Cookies and Sessions in php Computer Problems


ADVERTISMENT



Most Popular Solutions
Copyright © TheSolveProblems.Com 2015 - 2016 All Right Reserves | Powered by EarnEDU Pvt. Ltd. | Created by Bebbisingh
>>>>>>>>>>