Login Script... How?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Login Script... How?

Post 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!
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

Just plan before you code.

Post 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.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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!
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

You should work through some more basic tutorials.

Post 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.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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...

:P

I'll keep looking. Sorry again! Thanks :)
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

Beginning PHP4 by Wrox

Post 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.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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 :)
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

It ends it.

Post 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.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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!
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

This should work for you.

Post by Brian »

Code: Select all

<?php

$name = "Billy Bob";
$name2 = "Billy Ray";

$pass = "truck";
$pass2 = "dog";


if ( ($name != $name2) || ($pass != $pass2) ) &#123; print "<P>No soup for you!</P>
"; &#125;

  else &#123; print "<P>The variables all match their counterparts.</P>
"; &#125;

?>
Post Reply