Home arrow PHP arrow Page 4 - Introduction to Maintaining the State of Applications with PHP Sessions

More session functions ahead: finding out the name of active sessions - PHP

In PHP, session management is used to help web applications maintain their state across several HTTP requests when needed. In this first part of a series, you will learn the basics of the PHP built-in session mechanism, as well as some of its many useful functions.

TABLE OF CONTENTS:
  1. Introduction to Maintaining the State of Applications with PHP Sessions
  2. Working with persistent data: the basics of session management
  3. Ending a session: using the “session_destroy()” function
  4. More session functions ahead: finding out the name of active sessions
  5. Configuring the PHP session module: using some helpful session functions
By: Alejandro Gervasio
Rating: starstarstarstarstar / 18
April 26, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Just in case you didn’t know, the PHP session module offers many other helpful functions that can be used for obtaining the values of specific parameters, which are included within the set of directives of the php.ini configuration file. However, let me first show you another illustrative example, which displays the name of an active session:

session_start();
echo session_name(); // displays PHPSESSID
// generate new session name
session_name('NEW_SESSION_NAME'); //displays NEW_SESSION_NAME
echo session_name();

As shown in the above script, the name of a session can be obtained by using the “session_name()” function. Very similar to the “session_id()” function that I described a few lines above, this function returns the name of the active session or assigns a new name to it.

After running the previous snippet, the output I get on my browser is the following:

PHPSESSID
NEW_SESSION_NAME

If a new session is started with the same browser or even with a different one, the value returned by the “session_name()” function (without passing any argument to it) will always be “PHPSESSID,” because this is the default session name assigned in the php.ini configuration file.

Right, as you saw, the PHP session module exposes many interesting functions, either for retrieving or manipulating some parameters assigned as default values within the php.ini file. Keeping in mind this concept, join me in the next section to learn how these values can be used (or eventually changed) within your PHP scripts.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: