0

I am having problem on this code of mine, I made a short javascript pop-up notice everytime a user logs a incorrect password or a correct pass, and when I typed the correct username and password, it is still invalid but when i delete these codes:

session_register('myusername');
session_register('mypassword');
$_SESSION['myusername']==$myusername;

it logs in well and there's no little security on my login... Please help me guys!

PHP Code:

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="db"; // Database name 
$tbl_name="members"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];


$encrypted_mypassword=md5($mypassword);


$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count == '1') {

session_register('myusername');
session_register('mypassword');
$_SESSION['myusername']==$myusername;
echo '1';
}
else 
{
  echo '0';
}
?>

Javascript Login:

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".loading").hide();
$(".message").hide();
$("#login_form").submit(function()
{
$(".login_form").hide();
$(".loading").fadeIn(100);
$.post("checklogin.php",{ myusername:$('#myusername').val(),mypassword:$('#mypassword').val()} ,function(data)
{
$(".loading").hide();
if(data == '1')
{
$('.message').html('<p>Success - Redirecting...</p>');
window.location.replace("members/ld.php");
}
else
{
$('.message').html('<p>Login Failed - Please Try Again</p>');
$(".login_form").fadeIn("slow");
}
$(".message").fadeIn("slow").delay(700).fadeOut(700);
});
return false;
});
});
</script>

Login Form:

<center><div class="message" style="color:red;font-weight:bold"></div></center>
			<form id="login_form" name="form1" method="post" action="" class="login">
				<h2>Login</h2><br class="spacer" />
				<label>Username: </label><br class="spacer" />
				<input name="myusername" type="text" id="myusername" /><br class="spacer" />
				<label>Password: </label><br class="spacer" />
				<input name="mypassword" type="password" id="mypassword" /><br class="spacer" />
				<input name="" type="checkbox" value="" class="check" /><p>Remember my password</p>
				<input name="button" id="button" value="Submit" type="image" src="images/login_btn.jpg" title="Login" class="loginBtn" />
				<!-- <a href="#" class="registerBtn"><img src="images/register_btn.jpg" title="Register"/></a> -->
			</form><br class="spacer" />

Edited by drelix01: n/a

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by rajeevphp2011
-1

To solve this problem simply delete the session_register() function wherever you have used it and also at the top of each page (on line 1) place the following.

<?php session_start();

That should solve it.

0

It doesn't work, I put the code that you gave me in the first line below the <?php and also deleted the session_register, and still no luck, any other solutions? Thanks by the way.

-1

Do you have cookies enabled because having cookies disabled will disable sessions. If you want to know how to use sessions with cookies disabled then click here.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.