Jump to content

[SOLVED] login not working


blueman378

Recommended Posts

hi guys, well im trying to use this:

 

part of index.php

<?php
if($_SESSION[loggedin] == 1)
{
$method = $_GET['method'];
if($method == "catman")
{
include("categorymanager.php");
}
elseif($method == "help")
{
include("help.php");
}
elseif($method == "prodman")
{
include("productmanager.php");
}
else
{	
include("adminhome.php");
}
}
elseif($_POST[login] == 1)
{
	$users->login($_POST[username], $_POST[password]);
	}
	else
	{
	echo "<form action=\"$_SERVER[php_SELF]\" method=\"post\">
	<label for=\"username\">Username:</label> <input type=\"text\" name=\"username\">
	<label for=\"password\">Password:</label> <input type=\"password\" name=\"password\">
	<label for=\"remember\">Remember me?</label> <input type=\"checkbox\" name=\"remember\" value=\"1\">
	<input type=\"hidden\" name=\"login\" value=\"1\">
	<input type=\"submit\" value=\"Login\">
	</form>";

}
?>

 

the login class that it references

<?php
class users
{

function login($username, $password) //Check the users username and password combo
{
$username = trim(strtolower(preg_replace("/[^a-z \d]/i", "",$username)));
$password = trim(preg_replace("/[^a-z \d]/i", "",$password));
$query = "Select * FROM users WHERE Username='$username' AND Password='$password'";
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result); 
if($num_rows == 1)
{
while ($user = mysql_fetch_array($result))
{
if($user[Active] == 1)
{
$_SESSION['username'] = "$user[username]";
$_SESSION['level'] = "$user[Level]";
$_SESSION['points'] = "$user[Points]";
$_SESSION['id'] = "$user[id]";
$_SESSION['email'] = "$user[Email]";
$_SESSION['loggedin'] = "1";
if($_POST[remember] || $_GET[remember])
{
	setcookie("id", "$user[id]", time()+31556926);
}
echo "username: $_SESSION[username] <br>";
echo "level: $_SESSION[level] <br>";
echo "points: $_SESSION[points] <br>";
echo "email: $_SESSION[email] <br>";
echo "loggedin: $_SESSION[loggedin] <br><hr>";
	echo "username: $user[username] <br>";
	echo "level: $user[Level] <br>";
	echo "points: $user[Points] <br>";
	echo "email: $user[Email] <br>";
}
else{
	echo "Your Account is either not activated to has been disabled by a administrator";
}
}
}
else{
	echo "Username/Password Combination do not match";
}
}
   

}
?>

 

when i run it i get:

username: admin

level: 3

points: 0

email: webmaster@webspirited[killbot].com

loggedin: 1

 

--------------------------------------------------------------------------------

username: admin

level: 3

points: 0

email: webmaster@webspirited[killbot].com

 

so both the sessions and the query are getting done correctly, however as soon as i try to go anywhere else it seems to kill the sessions or something, any ideas?

Link to comment
https://forums.phpfreaks.com/topic/106573-solved-login-not-working/
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.