• 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_start();
    $_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;
    
    }
    
    add_filter('the_content','replace_with_the_id');
    
    

    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)
  • Thread Starter zigx

    (@zigx)

    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:

    https://localhost/wp210/?the_id=52

    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.

    Thread Starter zigx

    (@zigx)

    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 site.com/wordpress/post-title/?the_id=blah, and this prints out “blah” fine
    – click “home” or something so im at site.com/wordpress/
    – access another post and “blah” will no longer print out

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

    Thread Starter zigx

    (@zigx)

    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?

    https://img87.imageshack.us/img87/522/untitledmo6.jpg

    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.

    Thread Starter zigx

    (@zigx)

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

    Thread Starter zigx

    (@zigx)

    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?

    Thread Starter zigx

    (@zigx)

    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.