Webmaster Forum

Go Back   Webmaster Forum > Web Development > Web Design Lobby

Web Design Lobby Forum for general web design issues not specific to scripting or graphics.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 02-16-2009, 07:29 PM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
Exclamation php login script doesn't work for IE, but fine on ff, chrome, etc..

I built a php login page/script using "post" method that checks username and password against the mysql database for matching. If match, it redirect back to home page and shows the "welcome username" on the top right corner rather than the login form.

This script works fine in all browsers except for IE.

Here is the login form:
<form action="visitor_includes/subheader_login_action.php" method="post">


<div class="login_field_input">
<input type="text" id="header_username" name="header_username" onchange="toggle_username('header_username')" maxlength="30" value="<?php echo htmlentities($header_username); ?>" />
</div>
<div class="login_field_input">
<input type="password" id="header_password" name="header_password" onchange="toggle_password('header_password')" maxlength="30" value="<?php echo htmlentities($header_password); ?>" />
</div>
<div id="header_login_button">
<input type="image" src="direct_images/header_login_button.png" onclick="ajaxFunction();" name="login" value="Login" />
</div>
<div id="header_register_button">
<a href="new_user.php">
<img src="direct_images/header_register_button.png" />
</a>
</div>


</form>

Here is the action script:

<?php
if (confirm_logged_in()) {
redirect_to("../index.php");
}

// START FORM PROCESSING
if (isset($_POST['login'])) { // Form has been submitted.
$errors = array();

// perform validations on the form data
$required_fields = array('header_username', 'header_password');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));

$fields_with_lengths = array('header_username' => 30, 'header_password' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));

$header_username = trim(mysql_prep($_POST['header_username']));
$header_password = trim(mysql_prep($_POST['header_password']));

if (empty($errors) ) {
// Check database to see if header_username and the hashed header_password exist there.
$query = "SELECT *, username ";
$query .= "FROM visitor_users ";
$query .= "WHERE username = '{$header_username}' ";
$query .= "AND password = '{$header_password}' ";
$result_set = mysql_query($query);
confirm_query($result_set);
if (mysql_num_rows($result_set) == 1) {
// header_username/header_password authenticated
// and only 1 match
$found_user = mysql_fetch_array($result_set);
$_SESSION['user_id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];
redirect_to("../index.php");
} else {
// header_username/header_password combo was not found in the database
$message = "username/password combination incorrect.<br />
Please make sure your caps lock key is off and try again.";
}
} else {
if (count($errors) == 1) {
$message = "There was 1 error in the form.";
} else {
$message = "There were " . count($errors) . " errors in the form.";
}
}

} else { // Form has not been submitted.
if (isset($_GET['logout']) && $_GET['logout'] == 1) {
$message = "You are now logged out.";
}
$header_username = "";
$header_password = "";
}

if (isset($message)) {
echo $message;
}

?>


Thx for all the help. You guys are the best~
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 02-16-2009, 11:37 PM
sssharlasss sssharlasss is offline
Contributing Member
 
Join Date: 02-16-09
Posts: 60
iTrader: 0 / 0%
What exactly happens in Internet Explorer?

And what version of IE is it not working on?
 
Reply With Quote
  #3  
Old 02-17-2009, 02:43 AM
troublescoot troublescoot is offline
Contributing Member
 
Join Date: 02-16-09
Posts: 60
iTrader: 0 / 0%
Quote:
Originally Posted by 2939195631902 View Post
I built a php login page/script using "post" method that checks username and password against the mysql database for matching. If match, it redirect back to home page and shows the "welcome username" on the top right corner rather than the login form.

This script works fine in all browsers except for IE.

Here is the login form:
<form action="visitor_includes/subheader_login_action.php" method="post">


<div class="login_field_input">
<input type="text" id="header_username" name="header_username" onchange="toggle_username('header_username')" maxlength="30" value="<?php echo htmlentities($header_username); ?>" />
</div>
<div class="login_field_input">
<input type="password" id="header_password" name="header_password" onchange="toggle_password('header_password')" maxlength="30" value="<?php echo htmlentities($header_password); ?>" />
</div>
<div id="header_login_button">
<input type="image" src="direct_images/header_login_button.png" onclick="ajaxFunction();" name="login" value="Login" />
</div>
<div id="header_register_button">
<a href="new_user.php">
<img src="direct_images/header_register_button.png" />
</a>
</div>


</form>

Here is the action script:

<?php
if (confirm_logged_in()) {
redirect_to("../index.php");
}

// START FORM PROCESSING
if (isset($_POST['login'])) { // Form has been submitted.
$errors = array();

// perform validations on the form data
$required_fields = array('header_username', 'header_password');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));

$fields_with_lengths = array('header_username' => 30, 'header_password' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));

$header_username = trim(mysql_prep($_POST['header_username']));
$header_password = trim(mysql_prep($_POST['header_password']));

if (empty($errors) ) {
// Check database to see if header_username and the hashed header_password exist there.
$query = "SELECT *, username ";
$query .= "FROM visitor_users ";
$query .= "WHERE username = '{$header_username}' ";
$query .= "AND password = '{$header_password}' ";
$result_set = mysql_query($query);
confirm_query($result_set);
if (mysql_num_rows($result_set) == 1) {
// header_username/header_password authenticated
// and only 1 match
$found_user = mysql_fetch_array($result_set);
$_SESSION['user_id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];
redirect_to("../index.php");
} else {
// header_username/header_password combo was not found in the database
$message = "username/password combination incorrect.<br />
Please make sure your caps lock key is off and try again.";
}
} else {
if (count($errors) == 1) {
$message = "There was 1 error in the form.";
} else {
$message = "There were " . count($errors) . " errors in the form.";
}
}

} else { // Form has not been submitted.
if (isset($_GET['logout']) && $_GET['logout'] == 1) {
$message = "You are now logged out.";
}
$header_username = "";
$header_password = "";
}

if (isset($message)) {
echo $message;
}

?>


Thx for all the help. You guys are the best~
I'm gonna go out on a limb here and say the problem lies in the JavaScript/AJAX portion. You might want to try using something like jQuery that will handle these things effectively while remaining cross-browser compatible/friendly.

What does your IE Javascript log tell you when you try this?
 
Reply With Quote
  #4  
Old 02-17-2009, 02:58 PM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
I think you might be right. I realize i still have the onclick="ajaxFunction" in the input field tag. However, this onclick=...... is from previous forms and currently it is not used and the function ajaxFunction is not declared.

IE opens a blank page with the url to be the .....action.php
It seems like the page is stuck before it is loaded.

But i'll go ahead and take off the ajaxFunction part and see if it works.

Thx for your opinion
 
Reply With Quote
  #5  
Old 02-17-2009, 04:03 PM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
Well that wasn't the problem. I'm so frustrated right now, but i think i found the problem.

<input type="image" src="direct_images/header_login_button.png" onclick="ajaxFunction();" name="login" value="Login" />

The value="" and onclick="" is unnecessary, but after taken it off, the script is still bugged.

I did a bunch of test runs and realize that type="submit" will work will but not type="image". This doesn't really make sense to me, but i'm 100% sure that account for the script error.

Using the statement: if (isset($_POST['login'])) { echo "is set"; } i came to realize that if the type = "image" the script actually shows NOT set while type = "submit" shows "IS set";

Hope this gives you a better image of whats going on.
I still don't know how to fix this yet. So i would really appreciate if you could help me out.
 
Reply With Quote
  #6  
Old 02-17-2009, 09:08 PM
sssharlasss sssharlasss is offline
Contributing Member
 
Join Date: 02-16-09
Posts: 60
iTrader: 0 / 0%
My guess is that the problem is in your "redirect_to" function.
 
Reply With Quote
  #7  
Old 02-18-2009, 09:42 AM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
Lightbulb No thats not it.

Quote:
Originally Posted by sssharlasss View Post
My guess is that the problem is in your "redirect_to" function.

Thx for trying to help, but i'm sure thats not the problem because i created a new page called test.php and the only thing in there is:

<form action="test_action.php" method="post">
<input type="image" src="direct_images/header_login_button.png" name="login" />
</form>

In test_action.php the only thing is:

if (isset($_POST['login'])) {
echo "login is set";
} else {
echo "error";
}


Yet, it says "login is set" for chrome, but says "error" in IE. However, if i change the type="image" into type="submit", it works fine in both.

I'm sure you'd get the same result if you try it on your wamp.
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP Login PHP Script from Website cleo Coding Forum 19 05-14-2010 09:21 AM
Tabs dont display corectly in firefox - work fine in IE WorldwideTrading Coding Forum 3 11-19-2008 07:42 AM
free login script olddocks Coding Forum 1 06-16-2008 08:14 AM
Would one be able to fine tune phpBB archiver Script for SEO crazyhorse Coding Forum 4 06-30-2004 05:39 PM
Problems with Login Script Izzmo Coding Forum 15 02-10-2004 03:57 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 08:47 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC