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 6822237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:38:20+00:00 2026-05-26T21:38:20+00:00

class userSessionManager { public $_uname; private $_pword; private $_userDB_Accessor; function __construct($userAccessor) { $this->_userDB_Accessor =

  • 0
            class userSessionManager
{
    public $_uname;
    private $_pword;
    private $_userDB_Accessor;

    function __construct($userAccessor)
    {
        $this->_userDB_Accessor = $userAccessor;            
    }
    function tryLogin()
    {
        //  get user information
        if ($_SERVER['REQUEST_METHOD'] == 'POST')
        {
            // get username and pasword from POST data and make it safe for database
            $this->_uname = quote_smart(htmlspecialchars($_POST['userName']));
            $this->_pword = quote_smart(htmlspecialchars($_POST['password']));
        }
        else // username and password were not set
        {
            return false;
        }

        $loginPassed = $this->_userDB_Accessor->login($this->_uname, $this->_pword);

        if($loginPassed == true)
        {
            $this->makeSession();
        }

        return $loginPassed;
    }
    private function makeSession()
    {
        session_start();
        $_SESSION['userName'] = $this->_uname;
    }
    function userHasSession()
    {
        session_start();
        if(! isset($_SESSION['userName']))  // session not properly created
        {
            return false;
        }

        $this->_uname = $_SESSION['userName'];  //save username to object

        //destroy and recreate session for security reasons
        session_destroy();
        $this->makeSession();
        return true;
    }
}

So, I read this article on how someone could gain access to an account with the session ID number. One solution listed was to reset the session ID number each time the page is loaded. Would this be a secure implementation of that idea?


Thank you all for the suggestions here is what I did to use them:

        private function makeSession()
    {
        session_start();
        session_regenerate_id();    // reset session id for securty
        $_SESSION['userName'] = $this->_uname;
        $_SESSION['userIP'] = $_SERVER['REMOTE_ADDR'];
        $_SESSION['userBrowser'] = $_SERVER['HTTP_USER_AGENT'];
    }
    function userHasSession()
    {
        session_start();

        if(!isset($_SESSION['userName']) || // check for a created user
            $_SESSION['userIP'] != $_SERVER['REMOTE_ADDR'] || // check for the same IP address
            $_SESSION['userBrowser'] != $_SERVER['HTTP_USER_AGENT'] //check for same Browser and OS
            ) 
        {
            session_regenerate_id();
            session_unset();
            session_destroy();
            return false;
        }
        return true;    // legit user
    }
  • 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-05-26T21:38:21+00:00Added an answer on May 26, 2026 at 9:38 pm

    If the session identifier is regenerated every time there is a change in the level of privilege,
    the risk of session fixation is practically eliminated:

    session_regenerate_id()

    <?php
    $_SESSION['logged_in'] = FALSE;
    if (check_login())
    {
    session_regenerate_id();
    $_SESSION['logged_in'] = TRUE;
    }
    ?>
    

    I do not recommend regenerating the session identifier on every page.
    While this seems like a secure approach—and it is—it provides no more
    protection than regenerating the session identifier whenever there is
    a change in the level of privilege. More importantly, it can adversely
    affect your legitimate users, especially if the session identifier is
    being propagated in the URL. A user might use the browser’s history
    mechanism to return to a previous page, and the links on that page
    will reference a session identifier that no longer exists. If you
    regenerate the session identifier only when there is a change in the
    level of privilege, the same situation is possible, but a user who
    returns to a page prior to the change in the level of privilege is
    less likely to be surprised by a loss of session, and this situation
    is also less common.

    Have a look at http://phpsecurity.org/ch04.pdf for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class MyClass { var $lambda; function __construct() { $this->lambda = function() {echo 'hello world';};
class LinkedList{ private $first; public function Merge(LinkedList $ll){ //We can't access $ll->first for merging
class MyClass { public: void setVar(const char *str); private: std::string mStr; int maxLength; //we
class Test extends JPanel implements MouseListener { private JButton b1, b2, b3, b4; public
class foo { public: void set(const int a) {b=a;} private: int b; }; Here
class myClass { public $user=array( 'first_name' => 'Andi', 'last_name' => 'Abdulloh', 'result' => array('A','B','C','D','E'));
class token { private: char m_chIcon; //actual ascii char that shows up for this
class ApplicationContext{ private final NetworkObject networkObject = new networkObject(); public ApplicationContext(){ networkObject.setHost(host); networkObject.setParams(param); }
class person { var $name; var $email; //Getters function get_name() { return $this->name; }
class Message(db.Model): user = db.ReferenceProperty(User, required=True, collection_name='Message_set') text = db.TextProperty(required=True) I tried this but

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.