Jump to content

PHP/MYSQL broken by the evil browser Internet Explorer


ktroztafy
 Share

Recommended Posts

Hello everyone, I'm new here first post, but there's a weirdness in code that i need to share,

 

First of all, I know everyone who knows PHP/MYSQL will say the same thing... Server side code cannot be broken by a browser, especially by client side coding. I agree!!! That may be the case here too, but I have encountered one of the weirdest code ever and the client side code is causing an unexpected result in PHP/MYSQL, and only in Internet Explorer. Unexplainable, and I am seeking for an answer.

 

After hours of trouble shooting I finally targeted the the trouble code... and it's CSS, and it's affecting a MYSQL line of code in PHP...

 

#somediv { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=''); }

 

... anyways let me explain how the code should run and the problem... in one page a variable passed in the URL is being captured by PHP using the $_GET method, if that variable is empty PHP runs a code which updates a MYSQL database. That works fine, and as expected, except in INTERNET EXPLORER. On that same page, a css file which is to be included with the  output html to the browser contains the above line of css too. Now in every other browser that code works as expected, if the variable is NOT empty, update the database and then output the html code. In IE the database gets updated no matter what, whether the variable is empty of not. Now the its only the mysql code inside the IF statement that get affected, because for troubleshooting purposes I have put echo statements inside the code, to catch the problem, and the echo statements work as should, just not the mysql update statement.

 

Someone care to shed some light into this mystery?

 

 

 

 

 

 

Link to comment
Share on other sites

Just to make things clear.. here's an example of the code...

 

if (empty($_GET["variable"])){

    $update = mysql_query("UPDATE database set field='variable is empty' where id='1' ");

}

 

// then all the  html header stuff gets outputed by PHP including a linked rel CSS file wich contains the next line

#somediv {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='');  }

 

// then the BODY and HTML stuff is included... which should have no effect on the PHP, but also including a div with the id=somediv

 

... and thats pretty much it

 

in every browser, if the $_GET variable is empty the database is updated,

 

in IE, no matter what the database gets updated....

 

when i remove the line of code from the CSS, that php code works as expected...

 

how that CSS line of code affects my MYSQL database code is beyond me... but it's happening

 

 

 

Link to comment
Share on other sites

It's likely that statement is causing your page to be requested twice, once with an expected URL and once with an empty query string on the end of the URL.

 

I would log (see the error_log statement) the date/time date('Y-m-d H:i:s') and $_SERVER['REQUEST_URI'] right before your if(empty()){} logic so that you can see exactly if, when, how many times, and what is being requested on the end of the URL.

Link to comment
Share on other sites

It's likely that statement is causing your page to be requested twice, once with an expected URL and once with an empty query string on the end of the URL.

 

I agree, that is almost surely the case.  Similar to when you have an <img src=""> in your code, the browser will load the page again to try and use it for the image. 

 

The reason your only seeing the problem in IE in this case is because IE is the only browser that understands that CSS code.  Every other browser will treat that line as an error and ignore it.

 

Link to comment
Share on other sites

That's what I thought, but lets say I add an echo statement, just to keep it simple like the following...

 

if (empty($_GET["variable"])){
    $update = mysql_query("UPDATE database set field='variable is empty' where id='1' ");
    echo "DATABASE WAS UPDATE";
}

 

 

The echo statement works as expected in EVERY browser, including IE. But that MySQL line does not.

The MYSQL still updates, even if the $_GET[] is empty or not.

 

That's just weird to me.

Link to comment
Share on other sites

Echoing something on the page won't accurately show what is happening if the page is being requested twice (you will only see the output from the last time the page is being requested), because the echoed output or lack there of will be replaced by the complement (lack of echoed output or the expected echoed output) on the second page request, which is why someone recommend logging definitive information about the page requests to help troubleshoot the problem.

 

Edit: Here's another possibility that could fit these symptoms. You have a header redirect somewhere that doesn't have an exit; statement after it and when the remainder of the code on your page runs while the browser is making the request for the new page, the remainder of the code on that page causes your update query to run/not-run. This offending IE statement being present in the css on the page could affect if/when/how long the redirect takes and affects if the problem shows itself.

 

I would recommend posting enough of your code that reproduces the problem so that someone could pin down the actual cause.

Link to comment
Share on other sites

Ok here's is the EXACT code I am trouble shooting

 

 

<?
// Here we connect to the database
$database = mysql_connect("****","*****","******");
if (!$database)
die ("could not connect");
mysql_select_db("*******")
or die ("MYSQL DID NOT FIND A CONNECTION:". mysql_error());


//here is the code which is not working as expected in IE
if (empty($_GET["variable"])){
    $update = mysql_query("UPDATE database set field='variable is empty' where id='1' ");
    echo "DATABASE WAS UPDATED";
}
?>
<!DOCTYPE HTML><html lang="en" >
<head><meta charset="utf-8">
<title>TEST</title>
<style>
#somediv {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='');  }
</style>
</head>
<body>
<div id="somediv"> </div>
</body>
</html>

 

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.