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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:58:18+00:00 2026-06-15T09:58:18+00:00

Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index im trying to create

  • 0

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

im trying to create a simple login and register page and i am getting these errors on my index .php page,why is my index undefined these are the errors i am getting

Notice: Undefined index: username in C:\xampp\htdocs\mysite\forum part two\index.php on line 7

Notice: Undefined index: password in C:\xampp\htdocs\mysite\forum part two\index.php on line 8

the codes on line 7 and 8 these respectively

$username = $_SESSION['username'];
$password = $_SESSION['password'];

this is my index page

<?php
//This will start a session
session_start();

$username = $_SESSION['username'];
$password = $_SESSION['password'];

//Check do we have username and password
if(!$username && !$password){
echo "Welcome Guest! <br> <a href=login.php>Login</a> | <a href=register.php>Register</a>";
}else{
echo "Welcome ".$username." (<a href=logout.php>Logout</a>)";
}
?> 
  • 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-15T09:58:19+00:00Added an answer on June 15, 2026 at 9:58 am

    You are getting those errors because your session has not been declared earlier,So you need to check if your session is declared earlier. you can use php empty or isset function

    <?php
    //This will start a session
    session_start();
    $username ='';$password ='';
    if(!empty($_SESSION['username']))//check if it is defined
        $username = $_SESSION['username'];
    
    if(!empty($_SESSION['password']))//check if it is defined
        $password = $_SESSION['password'];
    
    //Check do we have username and password
    if($username=='' && $password==''){
       echo "Welcome Guest! <br> <a href=login.php>Login</a> | <a href=register.php>Register</a>";
    }else{
    echo "Welcome ".$username." (<a href=logout.php>Logout</a>)";
    }
    ?> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index i am getting ranksection
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” I am getting warnings.
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” This code shows warnings
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I know its basic
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I am just learning
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index Okay, so I am
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index Reference - What does
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I want when I
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index In html code: <select
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index You all are probably

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.