Cookies VS Sessions

The main difference between cookies and sessions is that cookies are stored in the user’s browser, and sessions are not. This difference determines what each is best used for.

A cookie can keep information in the user’s browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie. The trouble is that a user can block cookies or delete them at any time. If, for example, your website’s shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.

Sessions are not reliant on the user allowing a cookie. They work instead like a token allowing access and passing information while the user has their browser open. The problem with sessions is that when you close your browser you also lose the session. So, if you had a site requiring a login, this couldn’t be saved as a session like it could as a cookie, and the user would be forced to re-login every time they visit.

You can of course get the best of both worlds! Once you know what each does, you can use a combination of cookies and sessions to make your site work exactly the way you want it to.

Selling PHP to your boss

If you want to use PHP in your company and your manager favours another solution, or if you are trying to convince a potential client that PHP really is a superior choice for the web, you’re going to need to have a clear-cut set of reasons why you believe PHP is the superior language. This short list should help you get started:

PHP is cross-platform. It can be run on Windows, Linux, BSD, Mac OS X, and Solaris, as well as a variety of other platforms.

PHP is free. You can download the source code, use it, and even make changes to it without ever having to pay any licensing costs. You can even give away your own modified version of PHP. Note to critics: just because PHP is free, it doesn’t mean you need to give your scripts away for free.

PHP is fast. In the majority of scripts beyond basic benchmarks, PHP will easily compete with both Perl and Python, and usually match Microsoft’s ASP.NET. Add to that the fact that PHP code can be cached for execution, and PHP’s performance is first-class.

PHP is capable. There are thousands of pre-written functions to perform a wide variety of helpful tasks – handling databases of all sorts (MySQL, Oracle, MS SQL, PostgreSQL, and many others), file uploads, FTP, email, graphical interfaces, generating Flash movies, and more.

PHP is extendable. Writing your own extension to PHP is a common and easy way to implement speed-critical functionality, and PHP’s extension API is a particularly rich and flexible system.

PHP is reliable. It already runs on millions of servers around the world, which means it is mature enough for even the most demanding of situations.

PHP is easy to debug. There are a number of debuggers, both commercial and freeware, that make debugging PHP a snap.

PHP is supported commercially. Two of the main contributors to PHP founded a company, Zend, to sell supporting products and technical support for the language, so there is no need to worry about PHP not being supported by a big company.

PHP is supported by the community. There are several very popular PHP web-sites such as www.phpbuilder.com that provide user-run technical support for PHP, as well as a variety of official mailing lists to help you get answers when you need them.

PHP is advancing. With the release of PHP 5, PHP has introduced features that have long been waited for, including more comprehensive error handling, better object orientation, and, of course, more speed.

PHP is fun! As I am sure you will agree while using this book, PHP is an enjoyable language to use – very little time is spent debugging code, and there is a large selection of pre-written functions available. OK, so your boss might not care too much about this one…

Taken from http://www.tuxradar.com/practicalphp/2/2/8

Klevis Miho Copyright © 2010