Web Guide UK - Web Design Articles & Tutorials
Home | Articles | Tutorials | Contact
Tutorial Categories
  • All Tutorials
  • CSS
  • Javascript
  • PHP
  • XHTML
Site Stats
  • Tutorials: 21
  • Tutorial Views: 14760
  • Articles: 5
  • Article Views: 1469
Site Partners
  • Good Tutorials
  • Links Lounge
  • Pixel 2 Life
  • Tiz Tag

Home > Tutorials > php > Naming Your Sessions

Naming Your Sessions

In PHP when you create a session and give it a name always make the name unique and not the same name as any variables you have.

For example if you create a session like this:


<?php
   $_SESSION
['username'] = $username;
?>




You could override the session with the variable username a common example of this is if you had a list of user and had a query pulling out all the usernames from your database the loop would cause the last username in the loop to override the session, In this case the session is now the last user in the loop and is a major security vulnerability.

To avoid this just make the session name unique from all variables used throughout the site like:


<?php
   $_SESSION
['loggedin'] = $username;
?>




This makes sure it won't be over written and will save you hours of trying to find out whats going wrong.

Posted on Tuesday, April 29th, 2008 viewed 152 times, 0 Comments

Comments

No comments yet

Add a Comment

Name:

Email: 

Comments

Are you human? if so type "webguideuk" in the box below

Back to Top

© Web Guide UK 2005 - 2008 Design by Nutty Coder - Web Design Hull