Difference between Cookie and Session Method

Slno. Cookie Session
01. A cookie is a bit of data stored by the browser and sent to the server with every request.Cookies are used to identify sessions. A cookie is mainly used to identify a user. A cookie is a small file that the server embeds on the client/user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. A session is a way to store information (in the form of variables) to be used across multiple logged in pages.They’re normally protected by some kind of server-side security.
02. Cookies are stored on browser as text file format. Sessions information are stored on server of a web site.
03. It stores limited amount of data. It stores unlimited amount of data.
04.

It stores upto 4kb [4096 bytes] size.Normally size of cookie is limited to 40 and number of cookies to be used is restricted to 20.

There is no limitation on the size or number of sessions to be used in an application.

05. It does not hold the multiple variables in cookies. It holds the multiple variables in sessions.
06. We can access the cookies value  easily. So it is less secure. We cannot access the session values easily because it is stored in binary format/encrypted form and gets decrypted at server.So it is more secure.
07. We can set the cookie time to expire it. Using session_destory() function, we can destroy the sessions.
08. The setcookie() function must appear before the html tag. The session_start() function must be the very first thing in the html document.
09. Cookies may or may not be individual for every client. Session is independent for every client i.e. individual for every client.
10. Cookies can be disabled. We cannot disable the sessions. Sessions can be used without cookies also.
11. Cookies can store information only in “String” datatype format.Hence there is no security. Session can store information in any type of data because the value is of data type of “object”.
12. Cookies are called as both persistent and non-persistent nature. Sessions are called as non-Persistent because its life time can be set manually.
13.    The disadvantage of session is that it is a burden or an overhead on server.

       

Difference between Get and Post Method

Slno. GET POST
01. The GET method is restricted to send upto 1024/2048 characters only but varies by browser and web server.. The POST method does not have any restriction on data size to be sent.However, there is an 8 MB max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file)
02. The variable names and values will be visible in URL if HTML forms submitted by the GET method. The variable names and values are invisible in URL if HTML forms submitted by the POST method.
03. only ASCII characters allowe i.e. GET method can’t be used, to send binary data like images and Word documents. The POST method can be used to send ASCII as well as binary data.
04. GET method should not be used when sending passwords or other sensitive information. POST method is secure to send passwords or other sensitive information.
05. GET method data can be accessed using PHP QUERY_STRING environment variable.
06. PHP $_GET associative array is used to access all the sent information by GET method. PHP $_POST associative array is used to access all the sent information by POST method.
07. Variables are visible in the URL so users can bookmark open page. Variables are not visible in the URL so users can’t bookmark open page.
08. The data sent by GET method is visible, hence less secure. The data sent by POST method goes through HTTP header, so security depends on HTTP protocol.Hence data is more secure.
09. Parameters remain in browser history because they are part of the URL Parameters are not saved in browser history.
10. Can be cached Not cached
11. Easier to hack for script kiddies More difficult to hack
12. Encoding type is application/x-www-form-url encoded Encoding type is multipart/form-data or application/x-www-form-url encoded.  multipart encoding is used mainly for binary data.

Difference between Include and Require Method

Slno. Include Require
01. Insert the content of specified Php file into another Php file at required place one/more times. Insert the content of specified Php file into another Php file at required place one/more times. 
02. It produces a warning message (if it fails to locate the file) and continue to execute the remaining codes.  It throws a fatal error (if it fails to locate the file) and stops the further execution of the remaining codes. 
03. Syntax=include ‘filename’; Syntax=require ‘filename’;
04.

Example=include ‘abc.php’;

Example=include “abc.php”;

Example=require ‘abc.php’;

Example=require “abc.php”;

05. It should be used mainly when the required file is not compulsory and application execution should continue when that file is not found. It should be used only when the file is required/compulsory/must for an application.

 3,016 total views,  1 views today

Categories: Php

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.