Forums

Hopelessly Lost Please help!! - $_SESSION (6 posts)

  1. alfredwestlake
    Member
    Posted 2 years ago #

    Boy I am really confused now.

    I put in a simple counter
    and it is clear that the session information is unstable.
    I am lost as to why this is please help.
    Here is the simple counter I used to test:

    <?php</p>
    <p>session_start();</p>
    <p>if (empty($_SESSION['count'])) {
    $_SESSION['count'] = 1;
    } else {
    $_SESSION['count']++;
    }
    ?></p>
    <p><p>
    Hello visitor, you have seen this page <?php echo $_SESSION['count']; ?> times.
    </p>

    The number changes all around and then seems to start all over. Try it yourself:

    http://www.baguachuan/blog

    Refresh the page several times and see what it does in the left sidebar.

    Please Help I am lost.

    Alfred

  2. vtxyzzy
    Member
    Posted 2 years ago #

    I am no expert, but here are a couple of possibilities:

    • session_start() needs to be called before any output to the browser. Put the call before get_header() in your template.
    • Some themes and plugins use sessions to track other things, such as an order tracking system.

    If it isn't one of those, then I am out of ideas.

  3. alfredwestlake
    Member
    Posted 2 years ago #

    Thanks vtxyzzy,
    Yea I have tried putting the session_start() in at various places. Doesnt seem to change the result.
    Thanks again for the input,
    Alfred

  4. alfredwestlake
    Member
    Posted 2 years ago #

    I have been searching around and apparently there is a problem using sessions with word press. Not sure why they are 'disabled'. Any ideas on how to get them working would be appreciated.

    Thanks,
    Alfred

  5. f00bar
    Member
    Posted 1 year ago #

    Try going to wp-settings.php and on line 36:

    $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');

    Change this to

    $noUnset = array('_SESSION', 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');

    Which should never unset/disable sessions.

  6. arpitap
    Member
    Posted 1 year ago #

    Hi fOObar,

    I tried this but it is still not working for me.
    Can you tell me what I could be doing wrong?

    Thanks,
    Arpita

Topic Closed

This topic has been closed to new replies.

About this Topic