Page 1 of 1
Login Script... How?
Posted: Fri Apr 26, 2002 9:40 pm
by Jim
So far I've got the registration script down (
http://www.maxxxtorque.com/prodigy/php/ ... gister.php), now I need a login script.
How do you suggest I go about creating this? How can I try to match a username to a password on my DB?
And after I get that, how do I set a cookie that will allow the user to stay logged in after a successful login?
Thanks!
Just plan before you code.
Posted: Fri Apr 26, 2002 10:40 pm
by Brian
Resist the temptation to code. Make a flow chart and/or a structure chart first to work out the general flow of your program. Once you have everything worked out logically, then make with the coding. Once you know what you want to do, it should be easier to find out--or figure out--how to do it.
Posted: Sat Apr 27, 2002 7:54 am
by Jim
I'd do that Brian, but right now I'm more interested in learning HOW to do it rather than applying it to my site.
As of now, both the registration and login scripts work.
http://www.maxxxtorque.com/prodigy/php/ ... gister.php
http://www.maxxxtorque.com/prodigy/php/login/login.php
Now that I know how to create the scripts, I'm wondering what sort of use they could have on my site.
Do you have any ideas as to what I could offer as an incentive to join? I notice EW has a nice little member's area when users log in. How did they create that?
Thanks!
*edit*
More questions.
How do I make sure none of the fields in the registration form are left blank?
How do I make sure no one uses the same name to register?
i.e. I don't want two Daves on the database.
Gracias again!
You should work through some more basic tutorials.
Posted: Sat Apr 27, 2002 8:38 am
by Brian
How do I make sure none of the fields in the registration form are left blank?
This kind of thing is basic PHP. You really should start at the
beginning and learn about working with variables. Most of us with more PHP and general programming experience are happy to answer questions, but so many basic questions make it pretty clear that you have not done much in the way of standard, basic reading about PHP. Your enthusiasm is great, but you will have a much easier time if you work through some more basic tutorials before trying to finish a complex project.
Posted: Sat Apr 27, 2002 8:41 am
by Jim
Agreed
Sorry. I've been reading my posts and noticing that I *might* be getting a bit annoying asking super-n00b questions like I do.
I keep looking for somewhere to go to start from the beginning, but I can't find it.
I've seen something about making sure fields aren't left blank but don't remember where I saw it...
I'll keep looking. Sorry again! Thanks

Posted: Sat Apr 27, 2002 9:10 am
by jason
How do I make sure none of the fields in the registration form are left blank?
You would test them useing the
empty() function.
I suggest picking up a good book, Beginning PHP 4 by WROX would be a good start.
In fact,
here are my recommendations on
Amazon.com.
Beginning PHP4 by Wrox
Posted: Sat Apr 27, 2002 9:28 am
by Brian
I have a copy of this book myself. Although it does contain a lot of good infromation (for example, the function tables in the back are rather nice), it also contains numerous errors and sloppy code (including lots of invalid HTML) and it is not localized for the USA, so there are plenty of extra vowels and peculiar wordings. I recommend looking through it at a local store before you make your decision about whether or not to actually buy a copy.
Posted: Sat Apr 27, 2002 4:48 pm
by Jim
Wow. That empty() tag worked like a charm. I combined it with an exit; tag I'd seen, and I'm wondering if what I THINK happens happens.
Code: Select all
if(empty($name)) {
print("Sorry. You must input a valid name!");
exit;
}
Now, I know when the name field on my login script is empty, it'll throw that error. I'm wondering if that 'exit;' command ends the script there or if it doesn't serve any purpose in this case.
Graci

It ends it.
Posted: Sat Apr 27, 2002 5:05 pm
by Brian
The exit command ends the program right then and there. Be careful to not do that before you have actually printed everything you want to print, though, or you could end up with elements that are incomplete because they lack closing tags and such.
Posted: Sat Apr 27, 2002 5:16 pm
by Jim
Thanks
Another question...
Say I wanted to make sure two separate variables are equal to two others in one statement.
How would I do this?
For instance, I want to see if $name and $pass are equal to $name2 and $pass2, and if not I want to display something else.
Is that possible?
Thanks!
This should work for you.
Posted: Sat Apr 27, 2002 5:27 pm
by Brian
Code: Select all
<?php
$name = "Billy Bob";
$name2 = "Billy Ray";
$pass = "truck";
$pass2 = "dog";
if ( ($name != $name2) || ($pass != $pass2) ) { print "<P>No soup for you!</P>
"; }
else { print "<P>The variables all match their counterparts.</P>
"; }
?>