WordPress.org

Ready to get started?Download WordPress

Forums

Passing variable form page to page nightmare (3 posts)

  1. scdwb
    Member
    Posted 4 years ago #

    Hey,

    I'm having a real problem passing variables from page to page in wordpress. I have tried to enable sessions in wordpress by placing the following into functions.php of my theme:

    function cp_admin_init() {
    if (!session_id())
    session_start();
    }

    I then add this in my header:

    $_SESSION['mykeyword'] = $_GET['keyword'];

    What I'm trying to do is save the keyword, which is appended to a url, to the session and pass it around the website.

    So, I send users to a URL like this: domain.com/home?keyword=testing.

    When they land on the page everything works. I echo the session variable to test and it appear on the screen.

    However, as soon as I move to another page that variable is lost. I've printed the entire session (Print_r ($_SESSION);) and the "mykeyword" empties it self as soon as I change page.

    Am I missing something obvious?

    Many thanks inadvance!

    Steven

  2. davidsword
    Member
    Posted 3 years ago #

    *bump* same problem here - find a solution?

  3. davidsword
    Member
    Posted 3 years ago #

    its an issue with register_globals, they needed to be off (this may pose a security issue)

    the problematic wp function doing the deed is wp_unregister_globals()

    & afaik session_start() should be in wp-config.php

Topic Closed

This topic has been closed to new replies.

About this Topic