Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Undefined index – username & password

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #198411
    cscodismith
    Participant

    I am in the middle of following the tutorial here and cannot seem to find the answer to this problem myself. I have the code as it is in the tutorial but am getting an error that doesn’t seem to be common with others that are doing the tutorial.

    In the error displayed here it shows that my ‘username’ and ‘password’ on line(s) 34 & 35 are undefined index. If you know the problem all answers are greatly appreciated! You can view the code of my login.php here.

    Best regards,
    Codi

    #198415
    Anonymous
    Inactive

    Hi Codi,

    You seem to be having a similar issue to what you presented in your previous thread:

    https://css-tricks.com/forums/topic/pdo-statements-registration-page/

    Did you take traq’s advice and read up on some PHP basics? He linked you to some pretty useful resources.

    The tutorial assumes you have an understanding of PHP programming from the outset. You have just copied line for line what the tutorial demonstrates, while the author is assuming you will understand where to put his code.

    The error:

    <?php
    if($_POST) {
        // Do stuff
    } else {
        $username = $_POST['username'];
    }
    

    You are only using the post array if it is empty. Of course the username index is not defined. If you don’t understand what I mean by that last sentence, then you can find some info on arrays here: http://php.net/manual/en/language.types.array.php.

    If it’s important for you to have a working system, then you would be better off paying someone to write it for you, or using a plug and play solution already written. If this is purely a learning exercise then please follow traq’s advice and use a better resource to learn PHP. Learning by doing is lovely, but you need a basic foundation to start building on.

    #198416
    cscodismith
    Participant

    Thanks for the reply, I just don’t understand how the tutorial’s code is working fine for others but not me. The code he provides doesn’t seem to have any additional array(s).

    #198417
    Anonymous
    Inactive

    Ok. As I say in my reply above, he’s assuming you’ll know where to put your code. And you haven’t put it where he’s expecting you to.

    Instead of accessing $_POST indexes when the array is empty, he is expecting you to access them when it’s not. Does that help?

    I don’t really want to just post line-for-line what he’s expecting, so I realise the above may come across as a little patronising. It’s genuinely not meant to, but I couldn’t work out a different way of expressing that.

    #198426
    cscodismith
    Participant

    Alright, that made it more clear. My apologies – sorry about that. Just seems there is a lot to learn to complete a simple task. Not really sure where I am going from here. Thanks for the help, appreciate it.

    Best regards,
    Codi

    #198428
    cscodismith
    Participant

    lmao very good example you put there, I will be sure to look up some of the basics of PHP and study them. I am for sure going to go back to the other post and see the link that you provided there to see some of the things that I need to better understand. I guess its just one of those things that I ‘have’ that I feel uncomfortable or am paranoid that if my code looks differently then how the tutorials code is – something will go wrong or not work the way it should. Thanks for pointing it out.

    #198430
    cscodismith
    Participant

    Hey, its me again! lol – I am researching into the problems and am in the process of working with the PasswordHash. I have downloaded the Phpass 0.3 and got the ‘premade’ PasswordHash.php from there but seems to be missing some more elements that are needed whice are:

    • The stored_hash variable as shown here.

    I take it that I need to add the variable and in some way which I have tried but failed within the explanation provided here. Perhaps you can point me into the right direction or provide me with something that can guide me through this a little easier as far as creating the stored_hash variable correctly. Hope to talk soon!

    #198434
    Anonymous
    Inactive

    The impression I’m getting from your last post is that you are comparing the submitted password to the submitted password (albeit after hashing). The intention behind the code is that you produce the hash during registration, save that to the database, then retrieve it to compare to the submitted password during login.

    As to your undefined username indexes – have you changed where you try to use the $_POST array?

    #198435
    cscodismith
    Participant

    I have not come across a fix to changing the $_POST array yet and the last post with the ‘update’ can be ignored as that really did not fix any problems so my current errors as of now are the undefined index on the username and password and also undefined variable – stored_hash

    You can view the errors I am receiving here. The additional code that I manually inserted into the PasswordHash.php is as follows:

    $hash_obj = new PasswordHash( 8, false );
    
    #198452
    Anonymous
    Inactive

    I’m on my mobile in my lunchbreak, so this code is minimal, but hopefully illustrative.

    $user = null;
    if($user) {
        echo $user['name'];
    } else {
        echo $user['password'];
    }
    

    What’s going to happen here? More importantly, what does the $user array have to equal in order for thatcode to echo the password?

Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘Back End’ is closed to new topics and replies.