Jump to content

Recommended Posts

I am using session_set_save_handler() to store my sessions in the database and also added a couple more functions for my script so I don't have to use the $_SESSION variable, etc. Yeah, this is a personal choice because I hate using gaudy looking $_SESSION as variables, etc. My code is below for my script functions:

 

<?php
    // create a session.... for the script
    function _create($name, $data) {


        $name = _sql_escape($name);
        $data = _sql_escape($data);

        return $_SESSION[''.$name.''] = $data;
    }

    // read the session... for the script
    function _read($name) {
        $name = _sql_escape($name);
        return $_SESSION[''.$name.''];
    }

    // unset the session... for the script
    function _unset($name) {
        $unset = unset($_SESSION[''.$name.'']);
        return $unset;
    }
?>

 

The read and write work, but the unset() won't work just returning it or placing it in a variable I get this error message:

 

Parse error: syntax error, unexpected T_UNSET

 

When I used:

unset(_read('registered'));

I got:

Fatal error: Can't use method return value in write context 

 

 

Any ideas? I really don't want to use $_SESSION on my pages because to me it just looks like crap. Maybe I have OCD or something lol

Link to comment
https://forums.phpfreaks.com/topic/97589-quicky-about-using-unset-in-return-value/
Share on other sites

you can't unset the function

try this

<php
    function _remove($name) {
        $name = _sql_escape($name);
        unset($_SESSION[''.$name.'']);
    }
?>

 

or try this

<php
unset(_getVar($name));

    function _getVar($name) {
        $name = _sql_escape($name);
        return $$_SESSION[''.$name.''];
    }
?>

 

**untested

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.