...

View Full Version : Can't login after loggin out!!!!!



ausgezeichnete
11-03-2007, 08:41 PM
Well, i don't know what is the problem in my code
after creating an account ,am logged in and i can access my page
but after logging out i can't log in again!!
i don't know why??????


<?php session_start();
require "forum.inc.php";
$mainpage="<a href='main.php'>Proceed to the main page</a>";
$logoutpage="<a href='welcomepage.php'>Logout</a>";

if($username && $password){
if($logged_in_user==$username){
setup_page("Already logged in","Already logged in");
echo $username.",You are already logged in</br></br>";
echo $mainpage."</br>";
echo $logoutpage;
exit();
}
$conn=mysqli_connect("localhost","root","","forum");
$query=mysqli_query($conn,"select * from users where name='".$username."'
and password=password('".$password."')");
if(!$query)fail("database query faild",true);
if(mysqli_num_rows($query)>0){
$record=mysqli_fetch_assoc($query);
$logged_userID=$record["userID"];
session_register("logged_userID");
$logged_in_user=$username;
session_register("logged_in_user");
if($record["mod"]){
$logged_as_mod=true;
session_register("logged_as_mod");
}
setup_page("Welcome","Welcome");
echo $mainpage."</br>";
echo $logoutpage;
exit();
}else{
setup_page("login","Invalid login");
echo "Your username & password doesnt appear to match ,try again";
}
}
elseif($username || $password){
setup_page("Invalid login","Invalid login");
echo "Please fill in both fields";

}else{
setup_page("login","login");
echo "Please entr your details to login";
}
?>
<form action="forumlogin.php" method="post">
Username:
<input type="text" name="username" maxlength="20" size="20">
Password:
<input type="password" name="password" maxlength="20" size="20">
<input type="submit" value="Login">
</form>
<a href="forumregister.php">Register New User</a>

ausgezeichnete
11-03-2007, 09:35 PM
it works only when i omit the password portion

and password=password('".$password."')

_Aerospace_Eng_
11-03-2007, 09:37 PM
Where do you define $username and $password? If you don't define them and register_globals is on then it will come as a post variable however having register_globals on is a security risk. If you don't have them defined try change this

require "forum.inc.php";
$mainpage="<a href='main.php'>Proceed to the main page</a>";
$logoutpage="<a href='welcomepage.php'>Logout</a>";
to this

require "forum.inc.php";
$mainpage="<a href='main.php'>Proceed to the main page</a>";
$logoutpage="<a href='welcomepage.php'>Logout</a>";
$username= $_POST['username'];
$password= $_POST['password'];
Now you may need to change your if statement because I believe the $_POST array always returns true so something like this instead

if($username != '' && $password != ''){

ausgezeichnete
11-03-2007, 10:06 PM
thnxxxx alot
it worked
my problem that i was putting the password in the database as char(12) and it was encodes and each time i register an account it gives the first 12 letter the same encoding values
for example
username:one password=123456e
username:two password=123456e
so i changed it to char(50)
to make it look like that
username:one password=123456eertubdf
username:two password=123456eerertyu

its all about database encoding



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum