Jump to content

basic login using MySQL


WorldInChaos

Recommended Posts

Hello everyone, I have a simple task, yet I believe I'm overthinking it, or missing the obvious.

I am going to create user names and passes in a database table...
and then I want a user to have to login to a certain area of our site using them.
With this company, we will simply call them/email them their username and pass.

I believe I have to use a basic Select user FROM table WHERE user=$userid AND pass=$pass
then toss in a If statement for authentication...
do I have an return statement - and how do I actually know then login?
What prevents them from going straight to the page - do I have to define variables and send the url and POST user/pass?

I'm more confused on how to/if create the admin page - if it's necessary.  PHPMyAdmin does a fine job otherwise.

If you have rather simple code for an administrative front end, that's great, but not necessary, although it would be helpful if I could 'login' to a page in order to add entries, or view/print the entire database from a page.

This whole process doesn't have to be super-secure.  It is only so everyone under the sun doesn't fill out a certain form on our site.  Even if someone breaks in, the only thing they will see is a registration form for another part of a website.  ::)

This needs to be basic, I don't need any frills, and I know this has to have been done before.  If you have any code or suggestions, please post them!

Thanks!
Steve
Link to comment
Share on other sites

for example...

login.php
[code]
<?
if(!empty($_POST)){
$username=$_POST[username];
$password=md5($_POST[password]);
$result=mysql_query("SELECT * FROM users WHERE `username`='$username' AND `password`='$password' LIMIT 1");
$row=mysql_fetch_array($result);
if(!empty($row)) $_SESSION[user]=$row;
else die("Invalid Username/Password");
}
?>
[/code]
Link to comment
Share on other sites

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.