kinkster Posted January 12, 2010 Share Posted January 12, 2010 for some reason this login script will not work in chrome or IE, attached is the file it is sent to, can anyone please help??? I believe its the cookies <? if(isset($_POST['accountUser']) && isset($_POST['accountPassword'])) { include("dbase.php"); include("settings.php"); if ($_POST['accountType']=="member") { $database="chatusers"; } else if ($_POST['accountType']=="model") { $database="chatmodels"; } else if ($_POST['accountType']=="studioop") { $database="chatoperators"; } $userExists=false; $result = mysql_query("SELECT id,user,password,status FROM $database WHERE status!='pending' AND status!='rejected' "); while($row = mysql_fetch_array($result)) { $tempUser=$row["user"]; $tempPass=$row["password"]; $tempId=$row["id"]; if ($_POST['accountUser']==$tempUser && md5($_POST['accountPassword'])==$tempPass) { if ($row["status"]=="blocked") { $userExists=true; $errorMsg="Account is blocked, please contact the administrator for more details"; } else { $userExists=true; $currentTime=time(); mysql_query("UPDATE $database SET lastLogIn='$currentTime' WHERE id = '$tempId' LIMIT 1"); setcookie("usertype", $database, time()+3600); setcookie("id", $tempId, time()+3600); header("Location: cp/$database/"); } } } if (!$userExists){ $errorMsg="Wrong Username or password"; } } else if (isset($_GET['from']) && $_GET['from']=="recoverpass"){ $errorMsg="Your new password has been sent to your mail"; } else { $errorMsg="Please complete username and password fields"; } ?> <? include("_main.header.php"); ?> <table width="720" height="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center" valign="middle"><form action="login.php" method="post" enctype="application/x-www-form-urlencoded" name="form1"> <p> </p> <table width="720" border="0" align="center"> <tr> <td colspan="2"><p align="left"> <span class="error"><?php if ( isset($errorMsg) && $errorMsg!=""){ echo $errorMsg; } ?></span> <br> <br> </p></td> </tr> <tr> <td width="210" align="right" valign="top" class="form_definitions"><div align="right">Username:</div></td> <td align="left" valign="top"><input name="accountUser" type="text" id="accountUser" size="24" maxlength="24"></td> </tr> <tr> <td align="right" valign="top" class="form_definitions"><div align="right">Password:</div></td> <td align="left" valign="top"><input name="accountPassword" type="password" id="accountPassword2" size="24" maxlength="24"></td> </tr> <tr> <td align="right" valign="top" class="form_definitions"><div align="right">Account type:</div></td> <td align="left" valign="top"> <select name="accountType" id="select"> <option value="member" selected>Member</option> <option value="model">Model</option> <option value="studioop">Studio Operator</option> </select> <div align="left"></div></td> </tr> <tr> <td align="right" valign="top" class="form_definitions"> </td> <td align="left" valign="top"> <input type="submit" name="Submit" value=" Log In to your account"> </form> <div align="left"></div></td> </tr> <tr> <td align="right" valign="top" class="form_definitions"> </td> <td align="left" valign="top"><a href="lostpassword.php" class="left">Lost Password? Press Here!</a></td> </tr> </table> <br> <br> <? include("_main.footer.php"); ?> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 12, 2010 Share Posted January 12, 2010 This - enctype="application/x-www-form-urlencoded" is an invalid enctype to list for a form (Edit: because it is the default.) Remove it to get your form to work in all browsers. Your issue is not that the cookie is not working, it is that your form is not submitting any data and you are skipping over all the form processing code. Quote Link to comment Share on other sites More sharing options...
kinkster Posted January 12, 2010 Author Share Posted January 12, 2010 just tried that, still didnt work. Have been messing with the form for days, and am puzzled that it only works in FF Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2010 Share Posted January 13, 2010 After commenting out everything I don't have that your code needs to run (includes, database statements...), the cookies are set in IE8. You have not stated what it actually does do when it 'does not work'? A blank screen? The form is just redisplayed? It redirects to cp/$database/ (which by the way is not the URL of a .php page unless you are doing some url rewriting or have default documents set up.) Best guess is there is there is something in the various include files that are preventing the form in the posted code from being valid and submitting data. What have you done to determine what execution path the code IS taking and what values are in the variables and what data is being retrieved from the database and is being used in the comparisons? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2010 Share Posted January 13, 2010 You can also greatly simplify your logic if you put all the conditions you are testing into the WHERE clause in the query so that the query only returns row(s) that match the values you have. You then only need to test if a matching row was found. Any time you find yourself looping through the result set of a query, testing values to find a match, you are not using the database efficiently. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2010 Share Posted January 13, 2010 The following is the equivalent logic with a few things cleaned up (tested) - <?php $errorMsg = ''; // define empty error message if(!empty($_POST['accountUser']) && !empty($_POST['accountPassword'])){ include("dbase.php"); include("settings.php"); if ($_POST['accountType']=="member"){ $database="chatusers"; } else if ($_POST['accountType']=="model"){ $database="chatmodels"; } else if ($_POST['accountType']=="studioop"){ $database="chatoperators"; } $_POST['accountUser'] = mysql_real_escape_string($_POST['accountUser']); $query = "SELECT id,status FROM $database WHERE status NOT IN ('pending','rejected') AND user = '{$_POST['accountUser']}' AND password = MD5('{$_POST['accountPassword']}')"; $result = mysql_query($query); if($result){ if(mysql_num_rows($result)){ // query matched a row, username/password exists $row = mysql_fetch_assoc($result); if ($row["status"]=="blocked"){ $errorMsg="Account is blocked, please contact the administrator for more details"; } else { // exists and is not blocked mysql_query("UPDATE $database SET lastLogIn=UNIX_TIMESTAMP() WHERE id = {$row['id']}"); setcookie("usertype", $database, time()+3600); setcookie("id", $row['id'], time()+3600); header("Location: cp/$database/"); exit; } } else { // no matching row (usename and/or password does not match) $errorMsg="Wrong Username or password"; } } else { // the query failed to execuite due to an error - do error reporting/logging here - trigger_error(mysql_error()); } } else if (isset($_GET['from']) && $_GET['from']=="recoverpass"){ $errorMsg="Your new password has been sent to your mail"; } else { $errorMsg="Please complete username and password fields"; } include("_main.header.php"); ?> <table width="720" height="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center" valign="middle"><form action="" method="post" name="form1"> <p> </p> <table width="720" border="0" align="center"> <tr> <td colspan="2"><p align="left"> <span class="error"><?php if ( isset($errorMsg) && $errorMsg!=""){ echo $errorMsg; } ?></span> <br> <br> </p></td> </tr> <tr> <td width="210" align="right" valign="top" class="form_definitions"><div align="right">Username:</div></td> <td align="left" valign="top"><input name="accountUser" type="text" id="accountUser" size="24" maxlength="24"></td> </tr> <tr> <td align="right" valign="top" class="form_definitions"><div align="right">Password:</div></td> <td align="left" valign="top"><input name="accountPassword" type="password" id="accountPassword2" size="24" maxlength="24"></td> </tr> <tr> <td align="right" valign="top" class="form_definitions"><div align="right">Account type:</div></td> <td align="left" valign="top"> <select name="accountType" id="select"> <option value="member" selected>Member</option> <option value="model">Model</option> <option value="studioop">Studio Operator</option> </select> <div align="left"></div></td> </tr> <tr> <td align="right" valign="top" class="form_definitions"> </td> <td align="left" valign="top"> <input type="submit" name="Submit" value=" Log In to your account"> </form> <div align="left"></div></td> </tr> <tr> <td align="right" valign="top" class="form_definitions"> </td> <td align="left" valign="top"><a href="lostpassword.php" class="left">Lost Password? Press Here!</a></td> </tr> </table> <br> <br> <?php include("_main.footer.php"); ?> Edit: If you determine that your code is executing the setcookie() statements when using IE, you might want to consider the possibility that you have configured IE to reject cookies, but have forgotten that you did this. Quote Link to comment Share on other sites More sharing options...
kinkster Posted January 15, 2010 Author Share Posted January 15, 2010 thanks for all the help guys, it wound up being the dumbest thing that i didnt look for, the server time wasnt set properly Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.