I don't understand what happened, I hadn't made any changes to this script, and all of the sudden, it's giving this error:
Notice: Use of undefined constant ID_my_site - assumed 'ID_my_site' in /path/to/my/script/changed/forsafety.com/login.php on line 90
As you can tell from this error, I am trying to run a login script. In the script, if everything goes ok, then this bit of script sets the cookie on the users machine. I am just assuming that this is causing the error, as it is on line 90.
This is line 89-91:
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
Anyway, as I said before, the login script has been working fine for days, and it just started doing this on it's own, I didn't touch the script, honest!
It's a bit long, but here's the entire login.php script in case you want to point out any other flaws for a newbie php man. I've changed a couple things to protect my security.
<?php
// connect to database
include 'db_config.php';
//Checks if a login cookie already exists
if(isset($_COOKIE['ID_my_site']))
//if there is, it skips the login page and takes user directly to admin area
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM mytable WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location: admin.php");
}
}
}
//if there is no cookie, load the login page
else{
//if the login form is submitted
if (isset($_POST['submit'])) {
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in all the required fields.');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM mytable WHERE username = '".$_POST['username']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=registration.php>Click Here to add a user.</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}
else
{
//check to see if the suer is required to change their password. if so, supply link to change pass script
$_POST['username'] = stripslashes($_POST['username']);
if ($info['changepass'] == 1){
die("<center>You are required to change your password at this time.<br>
Please click <a href='changepass.php'>here</a> to change your password.");
}
else{
// if login is ok then we add a cookie
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//then redirect them to the members area
header("Location: admin.php");
}
}
}
}
else {
// if they are not logged in
?>
<html><head><title>Import Auto Clinic Administrator Login</title></head><body>
<center>
<table><tr> </tr><tr> </tr><tr> </tr><tr> </tr></table>
<h1>Administrator Login</h1>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name=login>
<table border="1" cellspacing="1" cellpadding="1">
<tr><td><img src="images/auto2.png"></td><td align=center><font size=+1>Login</font></td></tr>
<tr><td align="right">Username:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td align="right">Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr><td colspan="2" align="center">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<a href="forgotpass.php"><font size="-1">Can't remember your password?</font></a></center>
</body>
</html>
<?php
}
}
?>