-1

I am very new to php doing this login form. created a file client.txt has a text "client"

after when i run the code i get

"Notice: Undefined index: password in C:\xampp\htdocs\mateen\aPanel\userform.php on line 17" ERROR

I could not able to understand where i am doing wrong.

<?php

    function isPassword($thePassword){
        $fp = fopen('datafile/client.txt', 'r');
        $code = fgets($fp);
        echo $code;
        fclose($fp);
        if(trim($code)==trim($thePassword)){
            return true;
        }else{
            return false;
        }
    }



    if(isPassword($_POST['password'])){
        session_start();
        $_SESSION['SESS_CLIENT'] = 1;   
    }else{
        session_start();
        $_SESSION['SESS_CLIENT'] = 0;   
    }


    //header("location:../index.php");
?>
Abhishek Sharma
  • 133
  • 1
  • 8

4 Answers4

2

You have to make sure that your form field that used to submit password has the attribute name "password"

ie <input type="password" name="password">

try it but this time use:

if(isset($_POST['password']) && isPassword($_POST['password'])){
divyanshm
  • 6,600
  • 7
  • 43
  • 72
1

Change if(isPassword($_POST['password'])){

to

 if(isset($_POST['password']) && isPassword($_POST['password'])){

That notice simply tells you that $_POST doesn't have "password" as an index. If you don't submit a form, it's normal.

0

"Notice: Undefined index: password in C:\xampp\htdocs\mateen\aPanel\userform.php on line 17" ERROR

That means, you didn't set name attribute to that input type or you might have someother name.

Since you didn't posted your html file, i can't exactly tell where you made mistake. But, generally it should be,

Password : <input type="password" name="password" />

& in php file you should check it's empty or not and whether variable password is set or not by,

if(isset($_POST['password']) && !empty($_POST["password"]))
  {  

   }

NOTE : Your form method should be POST.

Yuva Raj
  • 3,881
  • 1
  • 19
  • 30
0

Add a check empty data and index-

if(!empty($_POST['password']) && isPassword($_POST['password'])){....
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87