Google

Saturday, July 11, 2009

Difference between Cookies and Session (Cookies vs sessions) in PHP

Cookies and Session (Cookies vs sessions) in PHP

Both are use in terms of data storage in programming language...but how ? what is the preferable?, when use session?, when use cookie?, there are some question which arise in the mind at the time of of store data temp. as well as permanent.

There are differences between the two that will make each favorable in their own circumstance.

Cookies can be set to a long lifespan, which means that data stored in a cookie can be stored for months if not years. Cookies, having their data stored on the client, work smoothly when you have a cluster of web servers, whereas sessions are stored on the server, meaning if one of your web servers handles the first request, the other web servers in your cluster will not have the stored information.

Sessions are stored on the server, which means clients do not have access to the information you store about them – this is particularly important if you store shopping baskets or other information you do not want your visitors to be able to edit by hand by hacking their cookies. Session data, being stored on your server, does not need to be transmitted with each page; clients just need to send an ID and the data is loaded from the local file. Finally, sessions can be any size you want because they are held on your server, whereas many web browsers have a limit on how big cookies can be to stop rogue web sites chewing up gigabytes of data with meaningless cookie information.

So, as you can see, each have their own advantages, but at the end of the day it usually comes down to one choice: do you want your data to work when you visitor comes back the next day? If so, then your only choice is cookies – if you have any particularly sensitive information, your best bet is to store it in a database, then use the cookie to store an ID number to reference the data. If you do not need semi-permanent data, then sessions are generally preferred, as they are a little easier to use, do not require their data to be sent in entirety with each page, and are also cleaned up as soon as your visitor closes their web browser.

2 comments:

J&D said...

米蘭情趣用品情趣用品情趣飛機杯自慰套充氣娃娃AV女優按摩棒跳蛋潤滑液角色扮演情趣內衣自慰器穿戴蝴蝶變頻跳蛋無線跳蛋電動按摩棒情趣按摩棒丁字褲G點SM後庭

視訊美女視訊做愛


網頁設計
網頁設計

QualityPoint said...

In the post Finding and analysing Keyword position.it is useful for to find your site position in many search engines. You can choose multiple Search engines such as Google, Yahoo and Bing.You can also save your keywords which is used to find the keywordposition most of times.this is special offer only for this week.you can see One week Special Offer