Browser history can make PHP coding a headache

21 Aug, 2011  |  Written by  |  under Tips and Tricks

clear-your-browser-historyRecently on the DevNetwork I came across a post that stated default values were appearing within his text fields on his user login form even though his coding was not set to add any default values.

This striked me as an interesting issue that I am sure many people have experienced yet so many people know about it or realise that by understanding this little issue you could save money for not having to buy more painkillers.

The user basically asked for help regards this situation:

Hello I m new to php. I made a simple html form with two textboxes- username and password but when I run them they always have some default values- admin and a password. Where did they get this default value. I didnt put any value in them. I use xampp as php-mysql server .

His user form script was this simple code:

<h1>USER LOG IN PAGE</h1>
<form action="login.php" method="POST">User name<input type="text" name="username" />

 Password <input type="password" name="password" />

 <input type="submit" value="Submit" /></form>

His login.php script was as follows:

session_start();
 $user= $_POST['username'];
 $password= $_POST['password'];
 if ($user && $password)
 {
 $connect = mysql_connect("localhost","******","******") or die
("couldn't connect db");
 mysql_select_db('******') or die ("couldn't find db");
 $query= mysql_query("SELECT * FROM user WHERE name= '$user' ")
or die ( mysql_error());
 $num_rows= mysql_num_rows ($query);
 if($num_rows != 0)
 {
 $row=mysql_fetch_array($query);
 if( $password== $row['password'])
 {
 echo "YOU ARE LOGGED IN ! <a href="member.php">Go to</a> member page";
 $_SESSION['username']=$user;
 }
 else die ("password doesn't match");
 }
 else die ("user doesn't exist");
 }
 else die ("enter username and password");

Now as you can see from the above code this coder has not stated any default values to appear yet everytime he loads his page for some reason default values are appearing. He has struggle on with it not really knowing why this has happen. As we have all been through the blame game, he has also blamed his coding, the editor he used, and even the server he was using which was Xampp.

I turned out that all that was happening was his Firefox browser was set to remember history and it was indeed his browser that was causing this issue to arise. After 3-5 days of him checking his code, changing it, checking his server and php.ini setup in the end it took a couple of guys on DevNetwork to start coming up a number of solutions until one user just hit it on the head.

So my advice to everyone who develops in any way or form which will be viewed through some type of browser to look into your browser settings and disable your history and you will always see a fresh copy of your updated files.

I remember having simular issues when I was just starting out coding my first sites. I would change my page files, then have them in my browser ready to see the alterations. Even though I would click refresh the browser would still get 99% from your history which great aloud the diplay to load in record breaking time but still you were on your old version.

I currently have 5 browsers installed on my system and every one is set not to store my history and if the browser does not have the option to erase history on close or restart, then you can get plenty of free cleaning programs out there to help clean your system and always make sure you are seeing the most current display available to you.

One Response so far | Have Your Say!

  1. alex  |  August 25th, 2011 at 12:56 am #

    This is so true cos I did not know and spent ages looking at my code and it was my browser history so thanks for sharing sean

    alex - Gravatar

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*