Jump to content

Recommended Posts

I am lost on where to start with an assignment. If someone could please direct me on what to do, I would be greatly appreciative. I have two files called registerUsers.html and registerUsers_handler.php.

 

The html form asks the user to register their username and password.

 

Here is my HTML CODE:

<form action="registerUsers_handler.php" method = "get" />

<h2>Registration</h2>

Please enter your user name: <br />

<input type='text' size='30' name='userName'><br /><br />

Please enter your password: <br />

<input type='text' size='30' name='password'><br /><br />

<input type='submit' value='submit' name='submit'>

<input type='reset' name='reset' value='Reset Form'>

 

The PHP form needs to call three functions.

checkForNameAndPass($uName, $pass) -- that accepts the username and password

checkForExistingUser($fh, $fileName, $user) -- that accepts the file handle, file name, and username

addUserAndPass($fh, $user, $pass) -- accepts the file handle, user name, and password

 

This is all i have so far for the code. I have a book but it is TERRIBLE and there are no examples for this there.

 

<?php

//Gets and accepts username and password

$uName = $_GET['userName'];

$pass = $_GET['password'];

strlen(trim($uName));

strlen(trim($pass));

chmod($uName);

?>

 

Any help or tips would be appreciated....

Do you know how to make a function? If not read up on them here Functions. Specifically on the ones with parameters.

 

IE:

function yourFunctionName($parameter1, $parameter2) {
    // do something with the parameters
}

 

That is a basic example of how it is setup. As suggested look into use the file operators: fopen, fread, fwrite and fclose. Since this is an assignment, I am sorry I cannot just give you the answer, you would not learn much from it. The links I have provided should be more than enough to get you going on the right track to finish your assignment.

We just had a chapter on Functions, so I know a little. The chapter that covers files and directories (what this assignement is on) does not give anything similar to what is asked. I think you have gotten me on the right track with those and i will read up on the provided links. I definitely don't want to just have the answer but sometimes i spends hours reading my book and scouring the internet and things just don't add up. PHP and me don't always get along. Thanks for your help! ::)

Thanks for your help! ::)

 

No problem. It can be frustrating, but any language is to start with. Once you get the baselines down it is much easier. If you come across a point in the code that you need help with feel free to post it, the main goal is that you try and do it/debug it yourself as when you learn with trial and error, those tend to stick out in your head. Also, if you would like it critiqued/looked over when it is finished, this forum would be a good spot to ask that.

 

Best of luck.

I forgot to add this....There is a file called users.txt which has a short list of users and passwords. these functions are supposed to allow the user to enter a user name and password, hit submit and then the functions first check to see something has been entered, then checks to see if there are duplicate usernames/pw from the exisiting file and if there are no duplicates it appends it to the end.

 

That being said, can someone look over what I have and tell me if i'm getting warmer? :)

 

</head>

<body>

<form action="registerUsers_handler.php" method = "get" />

<h2>Registration</h2>

Please enter your user name: <br />

<input type='text' size='30' name='userName'><br /><br />

Please enter your password: <br />

<input type='text' size='30' name='password'><br /><br />

<input type='submit' value='submit' name='submit'>

<input type='reset' name='reset' value='Reset Form'>

 

</body>

</html>

 

PHP

<?php

 

function checkForNameAndPass ($uName, $pass)

{

//$filename = "users.txt";

$uName = $_GET['userName'];

$pass = $_GET['password'];

$fh = open("users.txt", 'r');

strlen(trim($uName));

strlen(trim($pass));

 

if(checkForNameAndPass($uName, $pass) == TRUE){

}

echo "It works!";

 

if (checkForExistingUser($uName, $fh)){

//if true: user exist

//kick out error msg.

}else {

//close exisiting file handle

}

$fh = open("users.txt", 'a');

if (addUserAndPass ($fh, $user, $pass)) {

echo "User added";

else {

}

}

?>

Kind of, not really.

 

You do a strlen with $uName and $pass, but you are not checking it or using it in an If statement anywhere. strlen returns the length of the string. Also you are passing $uName and $pass as parameters, why are you setting them to get inside the function?

 

Third, you are calling checkForNameAndPass within itself and in an if statement. It will never return a value and as such will cause an infinite loop when called.

 

Forth the $fh is equaled to open, it should be fopen. As for the checking I would use file to read in the current file if it is allowed, as that would put each line into an array and allow you to loop through it testing if the username/password combination is there.

 

Some advice, I think you need to pay more attention to your brackets, as the "echo "It Works" line is outside of that if, so no matter what it will echo the it works line, and no action is being done inside that if. The function, checkfornames... I do not see where the function ends (no ending bracket).

 

Well hope that helps you a bit more.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.