PDA

View Full Version : [PHP] More Help



Trigs
20-02-2009, 11:12 PM
I have tried every usersystem tut there is on the net and I have also tried myself many times but nothing works. Here's Naresh's usersystem from techtuts (edited quite a bit of course).

Lets start with the login page. It doesn't work. For some reason clicking login just refreshes the page.

Source:

<?php
ob_start();
include('config.php');
if (!$logged['username']) {
if (!clean($_POST['login'])) {
echo('
<form method="post" enctype="text/plain">
Username: <br />
<input type="text" maxlength="30" name="l_username"> <br /><br />

Password: <br />
<input type="text" maxlength="30" name="l_password"> <br /><br />

<input type="submit" value="Login" name="login"> <br /><br />
</form>
<a href="register.php">Register</a> | Forgot Passowrd

');
}

if ($_POST['login']) {
$username = clean($_POST['l_username']);
$password = encrypt(clean($_POST['l_password']));

$info = mysql_query("SELECT * FROM users WHERE username = '$username'");
$data = mysql_fetch_array($info);

if($data['password'] != $password) {
echo 'The username and/or password you entered was incorrect.';
} else {
$query = mysql_query("SELECT * FROM users WHERE username = '$username'");
$user = mysql_fetch_array($query);

setcookie('id', $user['id'],time()+(60*60*24*5), "/", "");
setcookie('pass', $user['password'],time()+(60*60*24*5), "/", "");
echo 'Thanks for logging in <b>'.$logged['username'].'</b>. Click <a href="index.php">here</a> to return to the main page.';
}
}
} else {
echo 'You are already logged in. Click <a href="index.php">here</a> to return to the main page.';
}
?>

Blinger1
21-02-2009, 08:28 AM
What is that
clean($_POST['login')) crap?

Try this:


<?php
ob_start();
include('config.php');
if (!$logged['username']) {


if ($_POST['login']) {
$username = clean($_POST['l_username']);
$password = encrypt(clean($_POST['l_password']));

$info = mysql_query("SELECT * FROM users WHERE username = '$username'");
$data = mysql_fetch_array($info);

if($data['password'] != $password) {
echo 'The username and/or password you entered was incorrect.';
} else {
$query = mysql_query("SELECT * FROM users WHERE username = '$username'");
$user = mysql_fetch_array($query);

setcookie('id', $user['id'],time()+(60*60*24*5), "/", "");
setcookie('pass', $user['password'],time()+(60*60*24*5), "/", "");
echo 'Thanks for logging in <b>'.$logged['username'].'</b>. Click <a href="index.php">here</a> to return to the main page.';
}
} else {
echo('
<form method="post">
Username: <br />
<input type="text" maxlength="30" name="l_username"> <br /><br />

Password: <br />
<input type="text" maxlength="30" name="l_password"> <br /><br />

<input type="submit" value="Login" name="login"> <br /><br />
</form>
<a href="register.php">Register</a> | Forgot Passowrd

');
}
} else {
echo 'You are already logged in. Click <a href="index.php">here</a> to return to the main page.';
}
?>

Sameer!
21-02-2009, 08:42 AM
Wait, are you trying to connect to a MySQL database where the usernames and password is stored?

Trigs
21-02-2009, 03:52 PM
The clean() functions and database connection are all in config.php. I'll try that Blinger.

Want to hide these adverts? Register an account for free!