Schlo_50 Posted February 13, 2008 Share Posted February 13, 2008 I have been trying to develop a login script in Firefox and Explorer for maximum compatibility and now the script works in Firefox but not Explorer. I have tried looking at each and every line of code but cannot spot why the code won't run in Explorer. There are no parse errors, and my defined error messages (incorrect password etc..) do not pop up. The code in question: <?php require_once('addtab.php'); session_start(); $error = '0'; if (isset($_POST['submitBtn'])){ // Get user input $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; // Try to login the user $error = loginUser($username,$password); } ?> <?php if ($error != '') {?> <?php if ((!isset($_SESSION['validUser'])) || ($_SESSION['validUser'] != true)){ print " <form name=\"loginform\" method=\"post\" action=\"$_SERVER[php_SELF]\"> <table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"> <tr> <td width=\"82%\"> <div align=\"right\">Username: <input type=\"text\" name=\"username\" class=\"form\" size=\"10\"> Password: <input type=\"password\" name=\"password\" class=\"form\" size=\"10\"> </div> </td> <td width=\"18%\"> <div align=\"right\"> <input type=\"image\" border=\"0\" name=\"submitBtn\" src=\"images/login.gif\" width=\"58\" height=\"19\" value=\"Login\"> </div> </td> </tr> </table> </form> "; } ?> <?php } if (isset($_POST['submitBtn'])){ ?> <?php if ($error == '') { echo "You are being directed to the User Area.<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=area.php\">"; } else echo $error; ?> <?php } ?> The login function: // being login section function loginUser($username,$password){ $errorText = ''; $validUser = false; // Check user existance $pfile = fopen("users.txt","r"); rewind($pfile); while (!feof($pfile)) { $line = fgets($pfile); $tmp = explode('|', $line); if ($tmp[0] == $username) { // User exists, check password if (trim($tmp[1]) == trim(md5($password))){ $validUser= true; $_SESSION['userName'] = $username; } break; } } fclose($pfile); if ($validUser != true) $errorText = "Invalid username or password!"; if ($validUser == true) $_SESSION['validUser'] = true; else $_SESSION['validUser'] = false; return $errorText; } Thanks in advance guys! Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/ Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 Are you doing this with AJAX? PHP is browser independent . Its run on the server, not on the users computer, and as such it doesn't matter what browser the user is using. Javascript however runs on the users computer, and therefore is browser dependent. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465706 Share on other sites More sharing options...
Schlo_50 Posted February 13, 2008 Author Share Posted February 13, 2008 Using Apache to test both browsers locally. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465713 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 How are you accessing the php script? Are you doing it directly so that it appears in your address bar, or are you using javascript to access it in the background? Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465714 Share on other sites More sharing options...
Schlo_50 Posted February 13, 2008 Author Share Posted February 13, 2008 Directly in the address bar. Im not dealing with Javascript. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465731 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 Honestly, I don't know what your problem is. But I can tell you what it definitely isn't - a browser issue. PHP isnt run on your browser at all (unless you have specifically defined some browser-dependent code. Have you?), so it must be something else. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465736 Share on other sites More sharing options...
Schlo_50 Posted February 13, 2008 Author Share Posted February 13, 2008 Ok, thanks. Im going to test this on my windows server, and then on linux failing that. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465738 Share on other sites More sharing options...
Sulman Posted February 13, 2008 Share Posted February 13, 2008 Honestly, I don't know what your problem is. But I can tell you what it definitely isn't - a browser issue. That might not be strictly true... If it's working fine on FF and not IE then it would suggest that it is a browser issue. Check to see if sessions and/or cookies are disabled on IE. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465741 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 Good luck. As a side point, it *may* be a problem with your html. You have <input>s, but you haven't closed them. They should either look like this: <input type="something" name="something" /> or like this: <input type="something" name="something></input> Its possible thats where your problem is coming from, though I don't know for sure. Edit: sulman makes a good point. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465745 Share on other sites More sharing options...
KrisNz Posted February 13, 2008 Share Posted February 13, 2008 do a print_r() on $_POST and check in both browsers, you'll notice a difference. Firefox includes the name of the image button in the postback. IE doesn't, hence your login code doesn't run in IE. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465746 Share on other sites More sharing options...
Schlo_50 Posted February 13, 2008 Author Share Posted February 13, 2008 Ok, thanks for those suggestions guys. I'll try them out now. I tried testing the code on both windows and linux servers and again, Firefox worked but Explorer didn't. Thanks again! Will post back the issue if i stumble across it. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465750 Share on other sites More sharing options...
Schlo_50 Posted February 13, 2008 Author Share Posted February 13, 2008 do a print_r() on $_POST and check in both browsers, you'll notice a difference. Firefox includes the name of the image button in the postback. IE doesn't, hence your login code doesn't run in IE. Exactly correct! Thank-you. I will also make sure i have closed all <input>'s. Thanks again! Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465755 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2008 Share Posted February 13, 2008 Read this to solve your problem (works in both browsers) - http://www.php.net/manual/en/faq.html.php#faq.html.form-image </input> is invalid. Closing an <input tag with /> is correct, but only has meaning if your DOCTYPE is one of the XHTML types. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465853 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 </input> is invalid. I believe its valid HTML. I don't write HTML though (only XHTML), so I could be wrong. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465864 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 My bad, upon doing a little research, it appears its not valid one way or another. Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465870 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2008 Share Posted February 13, 2008 It's not valid anything. There is no such element. "I believe" is not a programming term Link to comment https://forums.phpfreaks.com/topic/90876-firefox-and-explorer/#findComment-465874 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.