script SESSION prepends

What is a script’s SESSION prepend?

A SESSION variable name is something like this: $_SESSION['var_name']. Now, let’s say a user is running a session between his/her browser and the server. Furthermore, let’s say he/she is running two different scripts from your web application in separate browser tabs. There could end up being a collision in that each one of those two different scripts has a session variable with the same name. For example let’s say the two scripts are script_1.php and script_2.php. Script script_1.php has a variable called $_SESSION['yourPick']. Script script_2.php also has a variable called $_SESSION['yourPick']. Well what’s going to happen if the user hops between browser tabs and works on both scripts simultaneously? I’ll tell you what will eventually happen: The value of that session variable will become tainted and it won’t make any sense (unless of course you want that session variable to be like some kind of global thing).

Having a script specific session prepend is the solution to this problem. So how does that work?

What will it all look like?

Continuing with our example, we’ll assign S1 to be the script prepend for script_1.php and S2 to be the script prepend for script_2.php. The corresponding session variables will be $_SESSION['S1_yourPick'] and $_SESSION['S2_yourPick'].

Prepend naming:

The prepend has to be unique to the particular app script. Other than that here is a list of things unique to my web app.

  • I choose the first letter of each word in the script name.
  • I use capital letters.
  • I use the usedScriptSESSION_Prepends.php script to make sure my prepend is unique.
  • If it’s not unique I alter it.

About samehramzylabib

See About on
This entry was posted in Coding, PHP Script Writing, PHP Sessions Cookies and Header and tagged , , . Bookmark the permalink.


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s