i have a two menu bar option which are home and my account
after login my user and pswd its show home page but when i change home to my account page its show message below and logout
Notice: Undefined index: user in folder\myaccount.php
Notice: Undefined index: pswd in folder\myaccount.php
you are not logged in

these both fields are my login page variables user and pswd

Dani AI

Generated

Short diagnosis: the PHP notices and the “logged out on refresh” behavior come from two things—reading $_POST without checking whether the request was a POST, and not reliably starting/using the session on every page. As pointed out, call session_start(); but it must appear at the very top of every script that reads or writes $_SESSION (login handler, myaccount.php, any header/menu include). Also avoid reusing the same variable names for input and DB results (that can mask whether authentication actually succeeded).

A minimal, safe pattern (guard POST, set session, then redirect):

<?php
session_start();

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    // show form or redirect to login page
    exit;
}

$inputUser = isset($_POST['userid']) ? trim($_POST['userid']) : '';
$inputPass = isset($_POST['pswd']) ? $_POST['pswd'] : '';

// authenticate with OCI (bind/execute/fetch)
// on success:
$_SESSION['userid'] = $inputUser;
header('Location: myaccount.php');
exit;

And on pages that require login (menu, myaccount.php):

<?php
session_start();
if (empty($_SESSION['userid'])) {
    header('Location: login.php');
    exit;
}
// show account content

Quick troubleshooting checklist:

  • Confirm the HTML form uses method="post" and the input names match.
  • Use isset(...) or $_POST['field'] ?? '' to avoid undefined-index notices.
  • Verify oci_fetch_array actually returned a row before trusting DB values.
  • Ensure session_start() runs before any output (no BOM/whitespace).
  • After successful login redirect (header Location) to avoid refresh/resubmit problems.
  • For debugging use print_r($_SESSION) temporarily (as did), then remove it in production.
  • For production, do not store plaintext passwords—use hashing (password_hash/password_verify).

Following those checks will remove the notices and make the login persistent across refreshes.

post your code

this is my code of login if i refresh my page its logout or menu bar also show logout

<?php
$userid = ($_POST['userid']);
$pswd = ($_POST['pswd']);
$conn = oci_connect('user', 'pswrd', 'db');

$query = "SELECT userid, pswd FROM staff
WHERE userid=:userid AND pswd=:pswd";

$stmt = oci_parse($conn, $query);
oci_bind_by_name($stmt, ':userid', $userid, 8);
oci_bind_by_name($stmt, ':pswd', $pswd, 32);
oci_execute($stmt);
list($userid, $pswd) = oci_fetch_array($stmt, OCI_NUM);
if ($userid != "" && $pswd !="")
{
$_SESSION['userid'] = $userid;
echo " logged in sucessfully!!!...";
}
else {
    echo"you are not logged in ";
    }

?>

Try this

<?php 

    session_start();

    $userid = ($_POST['userid']);
    $pswd = ($_POST['pswd']);
    $conn = oci_connect('user', 'pswrd', 'db');

    $query = "SELECT userid, pswd FROM staff
    WHERE userid=:userid AND pswd=:pswd";

    $stmt = oci_parse($conn, $query);
    oci_bind_by_name($stmt, ':userid', $userid, 8);
    oci_bind_by_name($stmt, ':pswd', $pswd, 32);
    oci_execute($stmt);
    list($userid, $pswd) = oci_fetch_array($stmt, OCI_NUM);
    if ($userid != "" && $pswd !="")
    {
    $_SESSION['userid'] = $userid;
    echo " logged in sucessfully!!!...";
    print_r($_SESSION);
    }
    else {
        echo"you are not logged in ";
        }

?>

still problem is same when i enter in url to refresh this error is show

Notice: Undefined index: userid in ...\login.php on line 3

Notice: Undefined index: pswd in ....\login.php on line 4
you are not logged in

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.