Specific Login/Password Script Needed!

software development

#1

I would like to have a login box that, when a specific user logs in, they will be directed to a certain page/directory. Basically a client log in area.

I’m not much of a programmer, but willing to learn or read about some scripts that might make this happen. I’m not looking for something with a huge database of login names/passwords. There probably won’t be more than 5 or 10 user/pass combinations. That could be set manually if it makes a difference.

Someone please enlighten me. Thanks!

Jamie


#2

[quote]I’m not much of a programmer, but willing to learn or read about > some scripts that might make this happen. I’m not looking for
something with a huge database of login names/passwords. There
probably won’t be more than 5 or 10 user/pass combinations. That
could be set manually if it makes a difference.

[/quote]

Depending on your needs - and since you only need 5-10 such combinations - you may not need a script at all.

Why don’t you create a subdirectory for each client, and password protect them using the password protection feature in the web panel?

For example, you could have the following directories (named after each client’s username):

http://www.yourdomain.com/clients/user1/
http://www.yourdomain.com/clients/user2/
http://www.yourdomain.com/clients/user3/
http://www.yourdomain.com/clients/user4/

…and password protect them with a username/password, here:

https://panel.dreamhost.com/index.cgi?tree=goodies.htaccess

That’d probably work pretty well for such a small-scale need, and would be pretty simple to set up (ie. no need for a script).

  • Jeff @ DreamHost
  • DH Discussion Forum Admin

#3

Jeff-
Thanks. I’m actually aware of the htaccess and use it for my own purposes just as you described. But this is for another site I’m building and they need a more traditional log in scenario with one and only one log in area.

Jamie


#4

Jamie,

This exactly solves what you’re asking it to do. This is code that is NOT being used for production yet, but so far it hasn’t failed.

It uses MySQL, PHP and Sessions. (Overkill for what you’re trying to accomplish and there are things that can be optimized in code…but you might gather some ideas from it.)

For obvious reasons, I’ve changed the MySQL, domain, username and password info.

Basically, I put this in the public area. Login page. If it finds the username/password in the database, it redirects via javascript to a “members only” area. There, I have a script to test for a valid session and it throws the user back to this public area login page if they try to go there without logging in.

The BINARY password reference forces the query to match the case. That is, if the password is catsup, the user must match the case and Catsup would fail.

Jim

<?php session_start(); session_register('validlogin'); $Dbname="sqldatabasename"; $Link=mysql_connect("mysqldomain.dreamhost.com", "databaseusername", "databaseuserpass"); $Query="Select * from login2"; $Result=mysql_db_query($Dbname, $Query, $Link); if ($Link==FALSE) { Print "Database connection failed."; exit; } $Query2="Select * from login2 where userid = '$UserName' and BINARY password='$Password'"; $Result2=mysql_query($Query2); $chkRes = mysql_num_rows($Result2); If ($chkRes > 0) { $validlogin="yes"; while ($row = mysql_fetch_array ($Result2)) { $cust_num=$row[userseq]; } $CookieVal="$cust_num" . "$UserName"; setcookie("JimsCookie", "$CookieVal"); #setcookie("JimsCookie", "", time()-100); print "Form Results"; print "Good Login

"; print "$JimsCookie"; print "$cust_num"; print "Successful Login..."; echo ""; } else { $validlogin="no"; print "Invalid Login"; print "Sorry. The userid and/or password you entered were incorrect.

"; echo "Click here to try again.
"; echo "Or, if you are a new user, you need to signup by clicking here.

"; } #print $chkRes; print "
"; print "
"; ?>

#5

Jim-
Thanks for this. I’m a bit new to the PHP thing…just getting into it, but I’m going to save this and try it out the first chance I get.

Jamie