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

  • SEARCH
  • Home
  • 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 6059839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:45:25+00:00 2026-05-23T08:45:25+00:00

I am stuck in a frustrating rut here. I have an authentication system (built

  • 0

I am stuck in a frustrating rut here. I have an authentication system (built from scratch) that makes use of a singleton object.

The singleton object basically manages the security of sessions and has functions that safeguard against session hijacking and other malicious activities.

These functions depend on member data.

Now the issue is that PHP seems to discard these singleton objects every time the user refreshes or moves to a new page.

Here is a prototype of the sessions class:

class session extends login{
    public   $sessionid;
    private  $fingerprint;
    public  static $temp=0;
    public  static $s_instance = NULL;

    public static function s_getinstance(){

        if (!isset(session::$s_instance) || !isset(session::$sessionid)) {
           $c = __CLASS__;
           if(isset(session::$s_instance)) {
               session::$s_instance = 0;
           }

           session::$s_instance = new $c;
           self::regenerate_id_name();                    
           self::$temp +=1;                
        }

        return session::$s_instance;
    }
}

The last function checks the data member ($s_insntance), if it is NULL it creates an object and throws it back along with managing the activities related to creating a new session.

If the data member is not null, it returns the existing object.

Or in theory, that is what it is supposed to do. However, every time I visit a new page and call upon the s_getinstance function, it tries creating a brand new object for some reason and the old data is lost. Please help me out here.

  • 1 1 Answer
  • 2 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-05-23T08:45:26+00:00Added an answer on May 23, 2026 at 8:45 am

    What we don’t see here is at any point you save the contents of your session object into the $_SESSION. Without doing so, it cannot persist across a page load.

    You need a method to save the session instance into the PHP $_SESSION and then your s_getinstance() needs to check if already exists in $_SESSION and retrieve it from there, or retrieve it from memory, or create it from scratch if it doesn’t exist anywhere.

    Start reading here… (Docs on PHP session handling)

    // assuming you've already called session_start()...
    public function storeinstance()
    {
      $_SESSION['session'] = self::s_getinstance();
    }
    
    public static function s_getinstance(){
    
        if (!isset(session::$s_instance) || !isset(session::$sessionid)) {
           $c = __CLASS__;
    
           // Check if it's already sitting in $_SESSION
           // Load it from $_SESSION if it's there, and then unset the $_SESSION var
           if (!isset(session::$s_instance) && isset($_SESSION['session'])) {
               session::$s_instance = $_SESSION['session'];
               unset($_SESSION['session']);
           }
           else if(isset(session::$s_instance)) {
               session::$s_instance = 0;
           }
    
           session::$s_instance = new $c;
           self::regenerate_id_name();                    
           self::$temp +=1;                
        }
    
        return session::$s_instance;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Kinda stuck here... I have an application with lets say 5000 rows of data
We have already built a rails app that has several users and an image
I have noticed that the output from my trace statements & dynamic text fields
Being stuck with a legacy database schema that no longer reflects your data model
Got stuck here: http://jsfiddle.net/UFkg8/ Right now the animation is top-down. What do I need
I've become stuck with an issue that I am sure is on- the- nose
So I've literally been stuck on this for hours and it's quite frustrating. I
I'm having an incredibly frustrating problem that appears to be a bug, but I
I have almost no experience with PHP and right now I'm stuck at the
so here is the case: i have a string in php (containts 2 words):

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.