Jump to content

Firefox and Explorer


Schlo_50

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.