Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:52:57+00:00 2026-06-07T16:52:57+00:00

I have been messing with this for a while and I know it is

  • 0

I have been messing with this for a while and I know it is something simple. I have used essentially the same code on another website and it doesn’t appear to have any problems and is running on the same server so I don’t think it is a server-side issue. This is a very simple login script:

function user_login($username, $password) {
$passcorrect = user_checkpass($username, $password);
if ($passcorrect == "1") {
    $_SESSION['eocname'] = $username;
    echo("SETTING SESSION: ".$_SESSION['eocname']."<br />");
    $success = "1";
} else {
    $success = "0";
}
return($success);
}

This does appear to be setting the SESSION variable and is in the functions.php file.

However, once you refresh the page, the SESSION appears to disappear. Here is the code on the page.php file:

<?php
    if (!isset($_SESSION['eocname'])) {
        if (!isset($_POST['username'])) {
            echo("You must login to access this page!");
            echo($_SESSION['username']);
        } else {
            $result = user_login($_POST['username'], $_POST['password']);
            if ($result == "0") { 
                echo("Incorrect Username or Password."); 
            } else { 
                echo("Login Successful!"); 
            }
        }
    } else {
        echo('Welcome back, '.$_SESSION['username'].'!');
    }
    ?>

Please note that I do realize there may be some redundant things in there, I’ve been toying with it trying to determine the problem, but it seems that everytime $_SESSION[‘eocname’] does not appear to have been set once the page is refreshed.

I have added session_start(); to the top of my functions.php file without error to ensure that it would work, but still no luck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:52:59+00:00Added an answer on June 7, 2026 at 4:52 pm

    You should create a init action in your plugin and start the session inside the function init. Your code should look like:

    add_action('init', 'initEverything');
    
    function initEverything() {
        if(!session_id()) {
            session_start();
        }
    }
    

    Other option is start the session in wp-config.php

    if(!session_id()) {
        session_start();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been messing around with writing some stored procedures in .NET code with
Ok well I have been fighting with this for a while now and have
I've been glancing at this code for a while now, and I can't seem
I know this question has been asked before, but I have tried the given
I have been messing around with Cocos2d for a while but decided that, due
I might be missing something, but I have been struggling with this problem for
I know I'm missing something here. I've been staring at this short script for
I have been messing around with Leaks trying to find which function is not
I have been messing around with my meta descriptions, trying to make them more
I have been messing around with OpenGL lately, and I noticed that the windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.