[email protected] Posted October 6, 2010 Share Posted October 6, 2010 Hi, I'm pretty new to PHP and though i had scrambled enough info together to build my self a nice little login system with my limited knowledge and my websites need and it worked great in Firefox and safari. Then a few weeks latter (still rather pleased with myself!) I check it out in explorer and it wont login if i put in the correct user and password or show a the error message if these were wrong. I have supplied the code below. Can anyone help explain why it doesn't work in ie? thanks in advance for anyone that has a look for me, cheers, here is the code. <?php session_start(); define("USERNAME", "chris"); define("PASSWORD", "chrislaff"); if (isset( $_POST["login"])) { login(); } elseif (isset( $_GET["action"]) and $_GET["action"] == "logout") { logout(); } elseif (isset($_SESSION["username"])) { displayPage(); } else { displayLoginForm(); } ?> <?php function login() { if ( isset( $_POST["username"] ) and isset( $_POST["password"] ) ) { if ( $_POST["username"] == USERNAME and $_POST["password"] == PASSWORD ) { $_SESSION["username"] = USERNAME; session_write_close(); header("Location: index.php"); } else { displayLoginForm( "Sorry, that username/password could not be found. Please try again." ); } } } ?> <?php function logout() { unset( $_SESSION["username"] ); session_write_close(); header( "Location: index.php" ); } ?> <?php function displayPage() { displayPageHeader(); ?> <div id="wrapper"> <div id="articleadmin"> <table style="width:970px;" > <tr> <th colspan="2"> <span class="green18">Articles</span> <a href="add_article_form.php?action=add"> [ADD] </a> </th> </tr> </style> <?php //connect to slt_database $db = mysql_connect('localhost', 'root', '') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('chrislafferty', $db) or die(mysql_error($db)); ?> <?php $query = 'SELECT * FROM chris_content ORDER BY content_id DESC'; $result = mysql_query($query, $db) or die (mysql_error($db)); $odd = true; while ($row = mysql_fetch_assoc($result)) { echo ($odd == true) ? ' <tr class="odd_row"> ' : ' <tr class="even_row"> '; $odd = !$odd; echo ' <td style="width:75%;">'; echo "<span class=blue12>" . 'title: ' . "</span>" . "<span class=grey14>" . $row['title']. "</span>" . '<br/>' . "<span class=blue12>" . 'Date: ' . "</span>" . "<span class=grey14>" . $row['date']. "</span>" . '<br/>' . "<span class=blue12>" . 'Article Type: ' . "</span>" . "<span class=grey14>" . $row['content_type'] . "</span>" . '<p/>'; echo '</td> <td align="center">'; echo ' <a href="edit_article_form.php?content_id=' . $row['content_id'] . '" > EDIT </a> '; echo "<span class=green18>" . ' | ' . "</span>"; echo '<a href="delete_article.php?content_id=' . $row['content_id'] . '"> DELETE </a> '; echo '</td> </tr> '; } ?> </table > </div> <!--article admin div ends--> </div> <!-- div wrapper ends --> </body> </html> <?php } function displayLoginForm( $message="" ) { displayPageHeader(); ?> <div id="loginwrapper"> <?php if ( $message ) echo '<p>' ."<span class='green12'>". $message ."</span>". '</p>' ?> <form method="post" action="index.php"> <table> <tr> <td> <p> <span class="blue12">Enter your username</span> </td> <td> <input id="username" name="username" type="text"/> </p> </td> </tr> <tr> <td> <p> <span class="blue12">Enter your password</span> </td> <td> <input id="password" name="password" type="password"/> </p> </td> </tr> <tr> <td> </td> <td> <p> <input type="image" img src="../images/submit.gif" name="login" id="submit" value="login"/> </p> </td> </tr> </table> </form> </div> <!--div wrapper ends --> </body> </html> <?php } function displayPageHeader() { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>school magazine</title> <link rel="stylesheet" type="text/css" href="../styles.css"> <style type="text/css"> th { background-color: #FFFFFF;} .odd_row { background-color: #EAEAEA; } .even_row { background-color: #FFFFFF; } </style> </head> <body> <div id="logowrapper"> <div id="logo"><img src="../web_header.jpg" width="970" height="386"/></div> </div> <!--end of logo wrapper --> <div id="nav"> <div id="navwrapper"> <div id="navbutton1"><a href="../home.php">YOUR HOME</a></div> <div id="navbutton9"><a href="index.php?action=logout">LOGOUT</a></div> </div> <!-- end of navwrapper --> </div> <!-- end of nav div --> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/215281-php-and-ie-explorer-problems/ Share on other sites More sharing options...
[email protected] Posted October 6, 2010 Author Share Posted October 6, 2010 Well it seems submit button is at fault this works - <input type="submit" name="login" value="Login" /> yet using an image as a submit button dosn't! - <input type="image" src="Submit.jpeg" alt="Submit" name="login" /> I know its now not a php question, but as I would like to use an image as a button any one know why it won't let me use an image? Quote Link to comment https://forums.phpfreaks.com/topic/215281-php-and-ie-explorer-problems/#findComment-1119596 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2010 Share Posted October 6, 2010 Images as submit buttons only submit the x,y coordinates where the image was clicked. The browsers that are setting the 'login' name for your button are not strictly following the w3.org specification. You either need to use the name_x or name_y value (see this link - http://us.php.net/manual/en/faq.html.php#faq.html.form-image) or you need to use a hidden form field with a name/value you can test if the form was submitted. Quote Link to comment https://forums.phpfreaks.com/topic/215281-php-and-ie-explorer-problems/#findComment-1119600 Share on other sites More sharing options...
Adam Posted October 6, 2010 Share Posted October 6, 2010 Actually just to add to that.. if you specify a value for the image input then "login" would be passed too. Quote Link to comment https://forums.phpfreaks.com/topic/215281-php-and-ie-explorer-problems/#findComment-1119602 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.