Hey guys,
Well I am making a seperate cms for my site
www.clantemplates2.com
Now what I want to do is make a login script for the admin panel on the cms. I have coded many login scripts before but this just wont work and I cant see why.
Heres the code.
PHP Code:
<div id="staff1">
<?php
/*
www.clantemplates2.com
CT2 Custom cms
Coding by Supernal and Huggy
*/
// staff login for the cms
if (!$_SESSION['ct2_logged'])
{
if (!$_POST['login'])
{
?>
<h3>CT2 Staff Login - ACP</h3>
<h5>Please Login</h5>
<form action="" name="login" method="post">
<p>Username: <input type="text" name="username" class="forms"/></p>
<p>Password: <input type="password" name="password" class="forms"/></p>
<p><input type="submit" name="login" value="Login to Staff" class="forms"/></p>
</form>
<?php
}else{
if($_POST['login'])
{
$username = addslashes(strip_tags($_POST['username']));
$password = md5(md5(addslashes($_POST['password'])));
if (!$password || !$username)
{
echo "<div class='error'>Please enter a username and password</div>";
}else{
$query = "SELECT * FROM user WHERE username = '$username' AND password = '$password'";
$result = mysql_query($query) or die (mysql_error());
$row = @mysql_fetch_array($result);
$rank = $row['usergroupid'];
if ($rank == 2)
{
echo "<div class='error'>Your rank does not support access to the CT2 ACP<br />This has been logged</div>";
echo "<meta http-equiv='refresh' content='0; url=index.php?page=login'>";
exit;
}
if ($rank == 4)
{
echo "<div class='error'>Your rank does not support access to the CT2 ACP<br />This has been logged</div>";
echo "<meta http-equiv='refresh' content='0; url=index.php?page=login'>";
exit;
}
if ($rank == 1)
{
echo "<div class='error'>Your rank does not support access to the CT2 ACP<br />This has been logged</div>";
echo "<meta http-equiv='refresh' content='0; url=index.php?page=login'>";
exit;
}
if ($rank == 3)
{
echo "<div class='error'>Your rank does not support access to the CT2 ACP<br />This has been logged</div>";
echo "<meta http-equiv='refresh' content='0; url=index.php?page=login'>";
exit;
}
if ($rank == 8)
{
echo "<div class='error'>Your rank does not support access to the CT2 ACP<br />This has been logged</div>";
echo "<meta http-equiv='refresh' content='0; url=index.php?page=login'>";
exit;
}
if ($row)
{
$_SESSION['ct2_logged'] = $username;
echo "<div class='error'>Loggin into CT2 staff ACP<br />
<a href='index.php?page=admin'>Click here if you are not auto redirected</a></div>
<meta http-equiv='refresh' content='3; url=index.php?page=admin'>
<img src='images/loading.gif' alt='Loading' title='Loading'/>";
}else{
echo "<div class='error'>Wrong username or password</div>";
echo "<meta http-equiv='refresh' content='2; url=index.php?page=login'>";
}
}
}
}
}
if ($_SESSION['ct2_logged'])
{
?>
Logged in as <?php echo $_SESSION['ct2_logged']; ?><br />
<a href="index.php?page=admin">Go to ACP</a> or <a href="index.php?page=login&action=logout">Logout</a>
<?php
if ($_GET['action'] == "logout")
{
session_start();
session_destroy();
echo "Logging out......<br />";
echo "<img src='images/loading.gif' alt='Loading' title='Loading'/>";
echo "<meta http-equiv='refresh' content='3; url=index.php?page=login'>";
}
}
?>
</div>
It just wont login, and I cannot figure out why, does anyone know of anything I should be doing different?