Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

61 users online



Login Script

Login Script

Currently viewing this thread: 1 (0 members and 1 guests)


konigwolf

konigwolf

Lead Administrator And Owner Of http://www.dragondiscussion.com
Status: Offline!

Login Script

Im Trying To Make A Login Script That Doesn't Require Going Into another file or useing the header location. it doesnt matter if it uses cookies otr sessions. does anyone know of any tutorials or have any advice.

___________________

Signature Suspended as it is in violation with the signature rules

Ynhockey

Ynhockey

Neverside Newbie
Status: Offline!

You just make it like any login script, except the action will equal none and there will be a statement like:

if (isset($_POST['username'])
{
}

(or something) around the entire code, so that it doesn't try to login when the user hasn't input any info yet.

___________________

Learn HTML

konigwolf

konigwolf

Lead Administrator And Owner Of http://www.dragondiscussion.com
Status: Offline!

My problems are usually with cookies or sessions.

___________________

Signature Suspended as it is in violation with the signature rules

Ynhockey

Ynhockey

Neverside Newbie
Status: Offline!

Well, for one, you should use sessions for sure (people hate cookies).

Just make is so that if the user has logged in successfully (username exists and matches given password in the DB), then PHP will execute something like:

session_register('logged');

And when he's logged out, make a session_unregister('logged');

and in all other places just check if (session_is_registered);

also, don't forget the session_start at the start of the page.

___________________

Learn HTML

konigwolf

konigwolf

Lead Administrator And Owner Of http://www.dragondiscussion.com
Status: Offline!

Maybe sumthin like.

PHP:

<?php

session_start
();
$username $_POST['username'];
$password$_POST['password'];
if (isset(
$_POST['username'])
{
$user_login mysql_query("SELECT * FROM users WHERE user_name = '$username' AND user_stat = '3' LIMIT 1");
while(
$user_login_data mysql_fetch_assoc($user_login))
{
if ((
$username == $user_login_data['user_name']) && ($password == $user_login_data['user_pass']) ))
{
echo 
"Thank You For Logging In.";
session_register('logged');
$_SESSION['logged'] = "in";
}else{
echo 
"Username Or Password Incorrect.";
session_register('logged');
$_SESSION['logged'] = "out";
}
}
}

?>

___________________

Signature Suspended as it is in violation with the signature rules

Ynhockey

Ynhockey

Neverside Newbie
Status: Offline!

I'm pretty sure that would work although i don't understand why you need the:

Code:


session_register('logged');
$_SESSION['logged'] = "out";


part.

Anyway, i'm not familiar with mysql_fetch_assoc (i use mysql_fetch_row and mysql_num_rows), but if you said your problem is with sessions then the SQL is probably correct.

___________________

Learn HTML

Ynhockey

Ynhockey

Neverside Newbie
Status: Offline!

Btw, i just realized something - you don't have a check to see whether the username doesn't exist.

After the SQL query you should enter:

if (mysql_num_rows($user_login) == 0) { echo 'Username does not exist' } else {

[ everything after that goes here ]

}

With your current script, if the user enters a username that doesn't exist then both UN and PASS will be equal to 0 (unset), so they'll match.

___________________

Learn HTML

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0084 seconds.