Forum Moderators: coopster

Message Too Old, No Replies

Looking for a PHP login script

         

joe1182

6:58 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



I need a PHP login script that if correct for USER1 would direct them to a certain URL but, if USER2 logged in he would not be directed to the same URL as USER1. I need each indivdual user to be directed to a custom page that I specify. I need it to be where only USER1 could accesss this page. Any help I could get regarding this would be great. I would store the members records in a MySQL Database. Is there a script out there that could help me?

jatar_k

11:07 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



there are a ton of login scripts around.

You could also look at this thread
Password Encryption and the Basics of User Authentication [webmasterworld.com]
msg 3 in particular

It shouldn't be a big deal to do the redirect once the user is authenticated. You could just use the header function really.

When you design these custom urls to forward your visitor to I would suggest either storing the path to forward them to in the db or making logical paths that you could construct based on user data.

joe1182

11:06 am on Nov 23, 2004 (gmt 0)

10+ Year Member



I have used the header function to direct all users to the same page but, I haven't directed each individual member to their own unique page. Would I include this in the login script? How do I do that for multiple members and each one be redirected to a different page. Could you show me what the code should look like? Thanks

Bonusbana

11:12 am on Nov 23, 2004 (gmt 0)

10+ Year Member



You could take the value from the username $_POST and redirect them to a directory named after the username where you have a $_SESSION to check if the user has the rights to access the directory.

joe1182

11:18 am on Nov 23, 2004 (gmt 0)

10+ Year Member



Could you show me an example in a code? I am sorry I am very new at this.

mipapage

11:19 am on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, when each user enters the site you want them to go to a different landing page. Lets call that a User Specific Landing Page (USLP).

If your login works with a db that stores the users username and encrypted password, for example, it could also store the value of the url for that users USLP. (If you wanted you could instead store the value for USLP in a cookie on the users system...)

Once the user is verified he/she would then be sent to the approprote landing page via:

header("Location: h*tp://www.mysite.com/$USLP_VALUE");

So, building off of Jatar K's post in the link he provided:

session_start();
$username = $_POST['username'];
$userpass = md5($_POST['userpass']);
$sql = "select * from usertable where username='$username' and password='$userpass'";
$result = mysql_query($sql);
if (mysql_num_rows($result)!= 1) {
$error = "Login failed";
include "loginform.php";
} else {
$row = mysql_fetch_array($result);
$_SESSION['username'] = "$username";
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
// any other data needed to navigate the site or
// to authenticate the user can be added here
header("Location: h*tp://www.mysite.com/$row['USLP_VALUE']");
}

joe1182

11:32 am on Nov 23, 2004 (gmt 0)

10+ Year Member



Thank you all so much. I believe this has given me what I need. If I need more help I know where to come. You guys are great!

joe1182

1:28 pm on Nov 23, 2004 (gmt 0)

10+ Year Member



o.k. one more thing. Please correct me if I am wrong. I need to create the "login.html" page. Then I need to create a database in MySQL with 3 fields. "Username", "Password" and "USLP_Value". I also need to create a html page where I can enter new client information. The action of the html form needs to point to the script you gave me. Is this correct? Do any scripts need entered in MySQL? If the scripts need entered in MySQL then how do I do that?

jatar_k

7:29 pm on Nov 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> Is this correct?

sounds right

>> Do any scripts need entered in MySQL?

I'm sorry I don't understand what you mean, could you clarify?

joe1182

7:34 pm on Nov 24, 2004 (gmt 0)

10+ Year Member



Well I know that in SQL sever you have to run a server rule. I didn't think you had to do that with MySQL but, wanted to make sure. Also how does the PHP script know which database to query? Do I need a database connect script? Would anyone happen to have one? Where would I place it in regards to the rest of the scripts? Whith The login?

coopster

8:08 pm on Nov 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



One common practice is to keep a db connection script below the public root of the http server pages. In that single connection script you have your connection information which usually includes the database you want to use.

You can find an example of a connection script in our PHP Library [webmasterworld.com]. It's in the thread called Basics of extracting data from MySQL using PHP [webmasterworld.com].

joe1182

10:16 pm on Nov 24, 2004 (gmt 0)

10+ Year Member



Thank You