Welcome Guest, Not a member yet? Register   Sign In
Simple Flashdata Code for PHP Sessions
#1

[eluser]Aea[/eluser]
I have a need in a project I'm current developing to have customizable flash data without the use the traditional flashdata functionality offered by the native session class (which otherwise is very nice) since I prefer to use $_SESSION[] instead of the referencing the session class, the way I see it, it's a needless call, since I'm relying on that class simply to mitigate session fixation. Thus I created the follow code...

Usage...
$_SESSION['key'] = 'My Data';
$_SESSION['key:hl'] = #PagesPersisted;

$_SESSION['key:hl'] can be set at any time, making a key act as flashdata at any time, and similarly by unset($_SESSION['key:hl']) you can revert it back to regular session data.

Code:
function _flash_countdown()
    {
        foreach ($_SESSION as $key => $value)
        {
            $search = $key.':hl';
            if (isset($_SESSION[$search]))
            {
                if ($_SESSION[$search] <= 0)
                {
                    unset($_SESSION[$key], $_SESSION[$search]);
                }
                else
                {
                    --$_SESSION[$search];
                }
            }
        }
    }

I wrote this very quickly, so if anybody has suggestions or potential problems to point out, feel free to. This code also runs quite efficiently, but I'm sure there are ways to optimize it further Smile


Messages In This Thread
Simple Flashdata Code for PHP Sessions - by El Forum - 02-13-2008, 10:53 PM
Simple Flashdata Code for PHP Sessions - by El Forum - 02-13-2008, 11:43 PM
Simple Flashdata Code for PHP Sessions - by El Forum - 02-13-2008, 11:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB