PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<? session_start(); ?>
<? require("config.php"); ?>
<?
if (isset($_GET["form"]) && $_GET['form'] == "submit") {
//get vars
$username2 = $_POST['username'];
$password2 = $_POST['password'];
$username = strtolower($username2);
$password = strtolower($password2);
if (isset($_POST['cookie'])) { $cookie = $_POST['cookie']; }
$time = time();
$pass = md5($password);
//check database
$sql="SELECT * FROM users WHERE username='$username' and password='$pass'";
$result=mysql_query($sql);
//check if there is a match
$count=mysql_num_rows($result);
if($count==1){
$data = mysql_query("SELECT * FROM users WHERE username='$username' and password='$pass'");
$info = mysql_fetch_array($data);
$ip = getenv('REMOTE_ADDR');
$date = date("F j, Y, g:i a");
$iplogs = mysql_query("SELECT * FROM `iplogs` WHERE iusername='$username' and iip='$ip'");
$logs = mysql_num_rows($iplogs);
if ($logs > 0) {
$iplogs2 = mysql_query("SELECT * FROM `iplogs` WHERE iusername='$username' and iip='$ip'");
$r = mysql_fetch_array($iplogs2);
$logins = $r['logins'];
$logins++;
$update="UPDATE `iplogs` SET logins='$logins' WHERE iusername='$username' and iip='$ip'";
mysql_query($update);
} else {
$insert = mysql_query("insert into iplogs values ('', '$username', '$date', '$ip', '1')");
}
$_SESSION['username'] = $info['username'];
$_SESSION['admin'] = $info['astatus'];
$_SESSION['fname'] = $info['fname'];
if($cookie == "yes") {
setcookie("username", $info['username'], $time + 3600); // Sets the cookie username
setcookie("password", $password, $time + 3600); // Sets the cookie password
}
}
if ($count != 1) { $login = "error"; }
}
?>
<html>
<head>
<title>The Freebie Life</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="style.css" />
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
<table id="Table_01" width="780" height="1024" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5">
<a href="index.php"><img src="images/main_01.gif" alt="" width="780" height="26" border="0"></a></td>
</tr>
<tr>
<td colspan="5">
<img src="images/main_02.gif" width="780" height="10" alt=""></td>
</tr>
<tr>
<td colspan="5">
<a href="index.php"><img src="images/main_04.gif" alt="" width="780" height="229" border="0"></a></td>
</tr>
<tr>
<td rowspan="4">
<img src="images/main_05.gif" width="18" height="47" alt=""></td>
<td colspan="3">
<img src="images/main_06.gif" width="756" height="26" alt=""></td>
<td rowspan="4">
<img src="images/main_07.gif" width="6" height="47" alt=""></td>
</tr>
<tr>
<td colspan="3">
<img src="images/main_08.gif" width="756" height="12" alt=""></td>
</tr>
<tr>
<td colspan="2">
<img src="images/top.gif" width="755" height="1" alt=""></td>
<td rowspan="2">
<img src="images/right.gif" width="1" height="9" alt=""></td>
</tr>
<tr>
<td>
<img src="images/left.gif" width="1" height="8" alt=""></td>
<td>
<img src="images/main_12.gif" width="754" height="8" alt=""></td>
</tr>
<tr align="center" valign="top">
<td height="699" colspan="5" background="images/main_13.gif"><h1> </h1>
<font size="+3">Member Login</font> <br>
<?
if (isset($_GET["form"]) && $_GET['form'] == "submit") {
if($count==1) {
echo "<b><Center>You Have Now Been Logged In</center></b>";
echo '<meta http-equiv="refresh" content="2;url=main.php">';
exit;
}
}
//check to see if already logged in
if (isset($_SESSION['username'])) { echo "<b><center>You Are Currently Logged In As ".$_SESSION['username']."</center></b><br>";
echo '<meta http-equiv="refresh" content="2;url=main.php">';
exit; }
//check to see if a cookie is set
if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
$password = $_COOKIE['password'];
$pass = md5($password);
//check database
$sql="SELECT * FROM users WHERE username='$username' and password='$pass'";
$result=mysql_query($sql);
//check if there is a match
$count=mysql_num_rows($result);
if($count==1){
$data = mysql_query("SELECT * FROM users WHERE username='$username' and password='$pass'")
or die(mysql_error());
$info = mysql_fetch_array($data);
$cname = $info['username'];
$cpassword = $_COOKIE['password'];
$cookie = "set";
}
}
?>
<form action="login.php?form=submit" method="post" name="login">
<table width="350" border="0" align="center" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF" class="table">
<tr>
<? if ($login == "error") { ?>
<td colspan="2" align="center"><? echo "<center><font color=red>Your Username or Password is Invalid</font></center>"; ?></td>
<? } else {?>
<td colspan="2"> </td>
<? } ?>
</tr>
<tr>
<td width="122"><div align="left"> Username: </div></td>
<td width="307"><input name="username" type="text" value="<? echo "$cname"; ?>" size="25" /></td>
</tr>
<tr>
<td><div align="left"> Password: </div></td>
<td><input name="password" type="password" id="Password" value="<? echo "$cpassword"; ?>" size="25" /></td>
</tr>
<? if ($cookie != "set") { ?><tr>
<td colspan="2"><div align="center">
<input name="cookie" type="checkbox" id="cookie" value="yes" />
Remember Me </div></td>
<tr>
<? } ?>
<td colspan="2"><div align="center">
<a href="forgot.php">Forgot Password</a>
</div></td>
</tr>
<Tr>
<td colspan="2"><div align="center">
<input name="submitbutton" type="submit" class="button" value="Submit">
</div></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table> </form> <p> </p></td>
</tr>
In IE7 the "meta refresh" does not take the user to main.php but rather to login.php AGAIN. this is only happening in IE7.. does anyone have any ideas?
...
if (isset($_GET["form"]) && $_GET['form'] == "submit") {
if($count==1) {
echo "<b><Center>You Have Now Been Logged In</center></b>";
echo '<meta http-equiv="refresh" content="2;url=main.php">';
exit;
}
else {
echo '<div>Debug: ', __FILE__, '@', __LINE__, ' !($count==1)</div>';
}
}
else {
echo '<div>Debug: ', __FILE__, '@', __LINE__, ' !(isset($_GET["form"]) && $_GET[form] == "submit")</div>';
}
//check to see if already logged in
if (isset($_SESSION['username'])) {
echo "<b><center>You Are Currently Logged In As ".$_SESSION['username']."</center></b><br>";
echo '<meta http-equiv="refresh" content="2;url=main.php">';
exit;
}
else {
echo '<div>Debug: ', __FILE__, '@', __LINE__, ' !(isset($_SESSION[username]))</div>';
}
//check to see if a cookie is set
...
I'm confused as to why you can't just use header().
You're using the meta tag... incorrectly. I'm pretty sure that it's meant to be in a <head> element. Kudos for IE7 if it's the only one that enforces the rule.