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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:49:25+00:00 2026-06-04T10:49:25+00:00

I have an admin page (../index2.php) I would like to log in as my

  • 0

I have an admin page (../index2.php) I would like to log in as my home URL when I first open the browser. You have to be logged in to view this page with username and password. Obviously if I log out and close the browser, then reopen, it should redirect to the login page. This is the top code of the index2.php page when it first opens:

<?php
      require_once ("../includes_kl/initialize.php"); // simply sets up database and other classes including session class
?>
<?php
    if(!$session->is_logged_in()) {
    redirect_to("/cms/login.php");
    }
?>

It will redirect to the login.php page, but that page does this:

require_once ("../../includes_kl/initialize.php");
if ($session->is_logged_in()) {// Skip login page if already logged in.
    redirect_to("index.php");
}

And because I am now logged in apparently (not sure when that happened), it goes to index.php.

I verify my cookiees are set when I open the browser. And the cookies do this:

  private function check_login() {

    if (isset($_COOKIE['user_id']) && (isset($_COOKIE['username']))) {
        $_SESSION['user_id']= $_COOKIE['user_id'];
        $_SESSION['username'] = $_COOKIE['username'];

    }

    if (isset($_SESSION['user_id'])) {
        $this->user_id = $_SESSION['user_id'];
        $this->username = $_SESSION['username'];
        $this->logged_in = true;
    } else {
        unset($this->user_id);
        $this->logged_in = false;
    }
}

My session Constructor:

function __construct() {
      session_start();
      $this->check_login();
}

UPDATE: I added this code to echo varibles:

function __construct() {
      session_start();
      $this->check_login();
       if ($this->logged_in) {
        echo "Session User Success: " . $this->username;
        } else {
        echo "Session User Fail";
        }
}

It returns the “Session User Fail” When I first open the browser (I took off the redirect for testing purposes in the index2.php so I can see the results).

UPDATED 2:

I have tracked down issues as Cookiees NOT being set.

Here is where I set them:

public function login($user) {
    global $database;
    if ($user) {
        $this->user_id = $_SESSION['user_id'] = $user->id;
        $this->username = $_SESSION['username'] = $user->username;
        setcookie('user_id', $this->user_id, time() + (60 * 60 * 24 * 14));
        setcookie('username', $this->username, time() + (60 * 60 * 24 * 14));
        $this->logged_in = true;
      }
}

Is this being done correct? This is part of when the user is logging in. I have verified in Chrome that the cookies are set. Yet, in the check_login() method, it odes not find them in that first “if” statement. The “isset” test fails.

  • 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-04T10:49:27+00:00Added an answer on June 4, 2026 at 10:49 am

    I figured it out with help from another question. It did have to do with Cookies. I simply need to set the path and the domain in the setcookie() method.

    setcookie(‘username’, $this->username, time() + (60 * 60 * 24 * 14), ‘/’, ‘domain.com’);

    My login.php (where the cookie was first set) was in a different folder level than my index2.php that the browser was opening up to. So the cookie was only set for the folders in the ‘domain.com/folder/HERE’ level (this is where my login.php was: domain.com/CMS/login.php).

    On the other hand, I was opening up browser to domain/index2.php where the cookie was not set. So it then sent you to the login.php page where the cookie WAS seen so it would pass the same test that it just field and redirect you to index.php where I was not logged in. So that is why my browser was opening me up in index.php AND logged in.

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

Sidebar

Related Questions

I have a URL like /admin/editblogentry?page=3&color=blue I want to alter the 'page' in the
I have a simple login page and the URL structure is like www.mydomain.com/admin/auth I
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
My folder structure is like - root admin create_page.php pages my_page1.php my_page2.php I have
My project is about a school admin I have a page called : createClass.php,
I don't have admin rights to my pc, but would like to use Mercurial
I'm building a page admin in php and have a function that lets me
Hey guys I have an admin page that checks if you are admin before
I have created a user from openfire admin page. I have entered the username,
I have a page which basically allows an admin user to create manager user

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.