Jump to content

Login


dean7

Recommended Posts

Hi all, ive tryed coding a rather good login script but there a problem with it i carnt see..

 

When the submit button is pressed it just refreshes the page.

 

<?php
session_start();
include_once"includes/config.php";
if (strip_tags($_GET['logout']) == "yes"){
session_destroy();
echo "<meta http-equiv='refresh' content='99999999999999999;url=index.php'>";
}elseif (isset($_SESSION['username'])){
header("Location: index2.php");
exit();
}

if ($_POST['submit'] && strip_tags($_POST['username']) && strip_tags($_POST['password'])){
$username = addslashes(strip_tags($_POST['username']));
$password = addslashes(strip_tags($_POST['password']));

$ip = $REMOTE_ADDR;

///check INFO

$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1");
    $login_check = mysql_num_rows($sql);
    $inf = mysql_fetch_object($sql);
if ($login_check == "0"){
            $message="Incorrect Username or Password! Try Again!";
}elseif ($login_check != "0"){

if ($inf->status == "Banned"){
$encoded=md5(strtolower($username));
header("Location: banned.php?banned=$username&encoded=$encoded");
exit();
}
        session_register('username');
        $_SESSION['username'] = $inf->username;
         $timestamp = time()+60;
mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");
mysql_query("UPDATE users SET l_ip='$ip' WHERE username='$username'");
        header("Location: index2.php");
} else {
            $message= "Incorrect Username or Password<br />";
            
$timenow=time();
$select = mysql_query("SELECT * FROM users WHERE online > '$timenow' ORDER by id");
$num = mysql_num_rows($select);
while ($i = mysql_fetch_object($select));
}}
?>

 

Thats all the php code which is in it.

 

Thanks for your help .

Link to comment
https://forums.phpfreaks.com/topic/182427-login/
Share on other sites

1: Is your submit button actually called 'submit'?

2: Why are you using addslashes() instead of mysql_real_escape_string()?

3: You are stripping tags from the password? Why? When you could just hash the password using md5() or sha1()? What if a user has a < in their password?

4: Your code will cause some notices to pop up. When making sure that a POST variable exists, use this:

 

if(isset($_POST['submit'])){
    //etc
}

 

instead of

 

if($_POST['submit'])

Link to comment
https://forums.phpfreaks.com/topic/182427-login/#findComment-962721
Share on other sites

This is the form i am using:

 

<html>
<head>
</head>
<form method="post" name="form" id="form">
<fieldset class="fieldset">
<legend>
Login</legend>
Login Name: <br />

<input name="username" type="text" class="form" id="username" maxlength="30">
<br />
Password: <br />
<input name="password" type="password" class="form" id="password">

(<a href="lost.php">forgot?</a>)<br>
<br>
<input name="submit" type="submit" class="button" value="Login" onClick="this.value='Processing';">
</fieldset>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/182427-login/#findComment-962723
Share on other sites

Wouldn't it make sense that you need to process the password identically when they register and you save a representation of the entered password and when you attempt to compare the entered password with the values that have been saved? Kind of like comparing apples to apples rather than apples to oranges  :examine:

Link to comment
https://forums.phpfreaks.com/topic/182427-login/#findComment-962879
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.