Support » Fixing WordPress » How To Set and Use a Session Variable?

  • I am trying to use a session var in order to pass the value of the var around my blog but i cant figure out how to get my session to work basically.

    This is what i have so far:

    In wp-config.php:

    $_SESSION["ses_id"] = $_GET["the_id"];

    This is my plugin:

    function replace_with_the_id($content)
    //replaces in RSS feed
    if (is_feed())
    $content = str_replace("%my_id%", $_GET['the_id'], $content);
    //replaces in content of blog with value of ses_id
    if ($_SESSION["ses_id"])
    $content = str_replace("%my_id%", $_SESSION['ses_id'], $content);
    return $content;

    The RSS part works perfectly and does not need to use any kind of session stuff, but the post content need to use the session var and when i use this method the var is empty…

    any ideas? thoughts? insults 🙂 ?

    I am not looking for someone to just code the whole thing out for me — any input would be of great help, thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Is it possible that this is a server setting i need to look into ?

    thank you.

    It should work as you have it. I have just tried your plugin code as well as the session stuff in “wp-config.php”. I added the following line to a sample post:

    “BTW: the value you passed in the _SESSION[ses_id] is %my_id%.”

    I then entered this URI, specifying the _GET paramater:


    What I got displayed in the post is this:

    “BTW: the value you passed in the _SESSION[ses_id] is 52.”

    Which proves that it works.

    It may be the way your “php.ini” file is configured, although I don’t know what specifically you should look for other than to see if your webserver allows session handling.

    pizdin_dim, i really appreciate you taking the time to test this out.

    I see your result too… but this is the type of problem i see:

    – access, and this prints out “blah” fine
    – click “home” or something so im at
    – access another post and “blah” will no longer print out

    Do you see this behavior too? or maybe know why i see it?

    also, here is a screen shot from phpinfo() of my session config… anybody know what it should be set to, if that is in fact the problem?

    Ok, now I see what you’re trying to do. Change the session assignment in “wp-config.php” to say this instead:

    if (isset($_GET['the_id'])) {
       $_SESSION['ses_id'] = $_GET['the_id'];

    That way, you’re only overwriting the $_SESSION variable with the $_GET variable if the latter is specified.

    ohhhhh mAN! that makes SO much more sense!! :X i will try it out and report back. 🙂

    AH HAAA~!!! you are so the man!

    post your email and i will paypal you $5 for the help!!!

    Thanks. How about you give $10 to your favourite charity instead?

    I actually have about $1k of stuff bagged up waiting for me to take it to a local charity.

    regardless, thank you very much.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How To Set and Use a Session Variable?’ is closed to new replies.