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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:19:42+00:00 2026-06-18T08:19:42+00:00

I try tow write a login-page in php, however i have problems with a

  • 0

I try tow write a login-page in php, however i have problems with a session-problem.

I have a index.php file, which should display internal/login page. Source:

<?php
include ("session_management.php");

if($_SESSION["UserID"] == -1 )
    include("login.php");
else
    include("calendar.php");
?>

my session_management.php looks like this:

<?php

    if(session_status() == PHP_SESSION_ACTIVE) {
        PRINT "session exists<br>";
        //session exists...
    }
    else {
        session_start();
                PRINT "new session<br>";

        $_SESSION["Username"] = 0;
        $_SESSION["UserID"] = -1;
    }
?>

and finally, my login.php file:

<?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        if (isset ($_POST["username"]) && isset ($_POST["pwd"])
                && $_POST["username"] != '' && $_POST["pwd"] != ''){
            $_SESSION["UserID"] = 1;
            $_SESSION["Username"] = "abc";

        }
        else
            PRINT "need name AND pwd";
    }
//.. some code...

i have no idea why that doesn’t work (userid is -1 all the time, also after login, so login.php is shown all the time)

thanks for your help!

  • 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-18T08:19:43+00:00Added an answer on June 18, 2026 at 8:19 am

    session_status() == PHP_SESSION_ACTIVE always returns false because you do not perform a session_start() before your test.

    You always need to do a session_start(). It will either start a new session if a session cookie was not recieved, or reopen the existing session.

    Change your session_management.php to this:

    <?php
        session_start();
        if ( empty($_SESSION["Username"]) ) $_SESSION["Username"] = 0;
        if ( empty($_SESSION["UserID"]) ) $_SESSION["UserID"] = -1;
    ?>
    

    And it’ll work.

    If you at some point really want to destroy the session (logout):

    <?php
        session_start();
        session_regenerate_id(true);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tow pages, first one for displaying the data in the text file
try{ File file = new File(write.txt); FileWriter writer = new FileWriter(file); PrintWriter printWriter =
try { File file = new File(sample.txt); FileWriter fw = new FileWriter(file,true); fw.append('d'); fw.write(100);
Problem Statement : Write a C++ program to evaluate postfix expressions. Your program should
Try to see which cast is faster (not necessary better): new c++ case or
I have tow tables the first d001 has two col: ACC_ID, ACC_NAME | |
try { // Create an appending file handler boolean append = true; FileHandler handler
I created WPF UserControl which enables to enter some information now I have Main
I have this HTML code generating by php code <tr class=edit_tr> <td>a1</td> <td class=edit_td>
Try to write: List<Object> list; @SuppressWarnings(unchecked) list = (List<Object>) new Object(); It will fail

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.