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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:43:48+00:00 2026-06-10T21:43:48+00:00

I’m working on an assignment on a PHP course, and I’m stucked at the

  • 0

I’m working on an assignment on a PHP course, and I’m stucked at the last part of it.

The assignment is to create a simple login form and use a session as well as hardcoded usernames and passwords (i.e. no db).

What I have problems with is the class that handles the login, and sessions especially. There’s a lot of code and I didn’t know what I could remove and therefore I’ve put it on Pastebin instead, hope that’s alright.

Thing is that the unit tests that’s built into the class passes except for nr. 4, the one that’s checking that the user is logged in. The problem seems to be that $_SESSION[$this->loginSession] doesn’t get set, and this is what I need help with.

The variable $loginSession is declared in the beginning of the class, and should be set to “isLoggedIn” when a user types a correct username and password, but that doesn’t happen (no error message).

My class is:

<?php

class LoginHandler {

        private $loginSession;

        public function IsLoggedIn() {
                if($_SESSION[$this->loginSession] == "isLoggedIn") {
                        return true;
                }
                else {
                        return false;
                }
        }

        public function DoLogin($username, $password){

                if ($username != null && $password != null){
                        switch ($username){
                                case "hello";
                                if ($password == "1234"){
                                        $_SESSION[$this->loginSession] == "isLoggedIn";
                                        return true;
                                }
                                else return false;
                                case "hello2";
                                if ($password == "12345"){
                                        $_SESSION[$this->loginSession] == "isLoggedIn";
                                        return true;
                                }
                                else return false;
                        }
                }
                else {
                        return false;
                }
        }

        public function DoLogout(){
                unset($_SESSION[$this->loginSession]);
        }

        public function Test() {

                $this->DoLogout();

                // Test 1: Check so you're not logged in.
                if($this->IsLoggedIn() == true){
                        echo "Test 1 failed";
                        return false;
                }

                // Test 2: Check so that it's not possible to login with wrong password.
                if ($this->DoLogin("hello", "4321") == true){
                        echo "Test 2 failed";
                        return false;
                }

                // Test 3: Check that it's possible to log in.
                if ($this->DoLogin("hello", "1234") == false){
                        echo "Test 3 failed";
                        return false;
                }

                // Test 4: Check that you're logged in
                if ($this->IsLoggedIn() == false){
                        echo "Test 4 failed";
                        return false;
                }

                return true;
        }
}

?>

I hope it’s enough to include the class and not all the other files, otherwise I’ll put them up.

  • 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-10T21:43:49+00:00Added an answer on June 10, 2026 at 9:43 pm

    Now I see it 🙂

    $_SESSION[$this->loginSession] == “isLoggedIn”;

    == should be =

    == compares while = sets

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

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.