Forum Moderators: coopster

Message Too Old, No Replies

PHP Login

         

SteveM11

7:52 pm on Apr 23, 2005 (gmt 0)



I am creating a new site which will include a few pages that only registered memebers of our organization can view. Our host supports PHP and MySQL but I am unsure how to go about creating such a login area. If possible, can I asign each member a username and temp password where then can then login and change their password? I do not need a registration page because only the members I select can go ahead and use our members only area. Can anyone give me advice. Kind of new at this but I have been reading up. Have never used PHP but willing to learn. THANKS!

jd01

10:01 pm on Apr 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe you have 3 options:

1. You can create a php script that independenlty protects the directory/files you are using.

2. You can create a php script that interacts with .htaccess and use that for password/username creation.

3. You can find a pre-written script for either of these and install/adapt it to your specific needs.

The best method is really the one that works best for your specific situation. It might help to decide if you will use php other than for this script.

If not, it might be more cost/time effective to find one that is already written.

If you will, it might be a good project/learning experience to work through on that is complete, or near complete and just needs 'tweeking'.

You can find more information about writing, and constructing a login script with php using the search for 'php login' I checked to make sure, and there are quite a few examples that are in the process or very nearly complete, and should give you a good idea of what it will take to create your own.

Hope this helps

Justin

ramoneguru

6:24 am on Apr 24, 2005 (gmt 0)

10+ Year Member



I had a similar problem when first starting. So, I tried the very basic things out first.

1. Do a simple hello world test to make sure everything on the server is up and running somewhat.

<?php
//file name should be hello.php
echo "Hello world<br/>";
?>

2. Connect to the mysql database on the server after you have created an account on the server.

if (mysql_connect(localhost, username, password))
echo "connection successful<br/>";
else
echo mysql_error();

3. Do some tutorials from w3schools and other places including here. I actually learned how to do a login page from webmasterworld and everyone here is very supportive. Also, just make scripts that do things like evaluate regular expression, work with POST data, SESSION variables, tables, queries, etc...

For a simple login there are a few steps involved:
1. Check to make sure the input is accurate (so if you have usernames that are only letters and nothign else then you would check just to make sure the input is alphabetic characters ([a-zA-Z] type of expression)

2. Check to see if the username is in the database, if it is then check to see if the username and password are in the database (in the same row of course).

3. Redirect to a "homepage" of some sort or whatever page you want the user to see first, so something like header("Location: hompage.php");
would do the trick.

That's pretty basic though, I'm sure other people on here have better ways of doing it. Just keep looking and searching until you find something you like and can understand.
--Nick

jatar_k

3:04 pm on Apr 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld SteveM11,

this might give you some direction as well
PHP User Authentication and Passwords [webmasterworld.com]

IamStang

3:20 pm on Apr 24, 2005 (gmt 0)

10+ Year Member



Another thing to put into the back of your mind.

If I can do this, anyone can!

I have been a land surveyor for several years. About 6 months ago, I decided to try to learn what makes the web go round. I dove right in and have been very intrigued by what I have learned. So much, that I have developed a "Phone Message Center" for my company, a few smaller scripts for friends and currently working on a "Budget" script for my family (which seems to be the hardest of the bunch to date).

The best thing I can point out to you is this. NEVER be afraid to ask even the simplist of questions if you need help. The folks at this board are great at helping out on simple to very complex problems. I have yet to not get help with any question I've asked.

I have found though, that it is best to spend some time looking for your answer first. A great place to start is the search feature of this site. If you need to ask it, it's probably already been covered at this board. So, look first, then ask.

Even if you decide to use a pre-made script, PHP is a fun and challenging language to learn and work with. And I hope you will find yourself atleast dabbling in it.

IamStang