<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simply Breath Teching... &#187; Coding Help</title>
	<atom:link href="http://www.breathteching.com/category/coding-help/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.breathteching.com</link>
	<description>Resources for PHP Programmers and Small Business Operators</description>
	<lastBuildDate>Tue, 01 Mar 2011 09:35:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Content Is Not Allowed In Prolog &#8211; Google API</title>
		<link>http://www.breathteching.com/2011/02/01/content-is-not-allowed-in-prolog-google-api/</link>
		<comments>http://www.breathteching.com/2011/02/01/content-is-not-allowed-in-prolog-google-api/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 03:27:30 +0000</pubDate>
		<dc:creator>chrisb</dc:creator>
				<category><![CDATA[Coding Help]]></category>
		<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[content not allowed in prolog]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[email settings]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[gapps]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[provisioning]]></category>
		<category><![CDATA[PUT]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/?p=71</guid>
		<description><![CDATA[Recently I&#8217;ve been having to work with the Google Provisioning and Email Settings API, which  I thought would be no big deal.  But soon, like a child who&#8217;s ice cream has just fallen on the ground, I was in tears and frustrated. The issue wasn&#8217;t necessarily the API, or the PHP code that I was [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been having to work with the <a href="http://code.google.com/googleapps/domain/gdata_provisioning_api_v2.0_developers_protocol.html" target="_blank">Google Provisioning</a> and <a href="http://code.google.com/googleapps/domain/email_settings/developers_guide_protocol.html" target="_blank">Email Settings</a> API, which  I thought would be no big deal.  But soon, like a child who&#8217;s ice cream has just fallen on the ground, I was in tears and frustrated.</p>
<p>The issue wasn&#8217;t necessarily the API, or the PHP code that I was using to generate the calls to the API, but it was the error message that I kept getting back when I tried to send my PUT requests.</p>
<p><code><br />
Content Is Not Allowed In Prolog.<br />
</code></p>
<p>Generally, this error indicates that there is content before the XML declaration, for example a space, or pehaps a gremlin.  But in my case, there was nothing in before the <code>&lt;?xml version="1.0" encoding="utf-8"?&gt;</code>, and I checked and checked, then checked some more.  And after that I checked some more, before checking even more.</p>
<p>So, after weeks of trying everything from different XML classes, writing the XML to a file, and creating a wig from the hair I&#8217;d ripped out of my head to cover my new found baldness, I finally figure it out!</p>
<p>With the Google API, like most API&#8217;s, it requires authentication.  For the purposes of the app I&#8217;m working on we are <a href="http://code.google.com/googleapps/domain/gdata_provisioning_api_v2.0_developers_protocol.html#Authenticating_To_Your_Domain" target="_blank">ClientLogin</a> authentication method which requires you to send an authentication token as part of your request headers.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/atom+xml; charset=utf-8'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Content-Length: '</span><span style="color: #339933;">.</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Authorization: GoogleLogin '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$authToken</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Connection: close'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Those were the headers I was sending to those who do no evil (of course that depends on what you&#8217;re definition of evil is).<br />
After dumping the headers to the browser I noticed something unusual&#8230;. after the last character of the auth token.. there was a <strong>SPACE</strong>.<br />
So I changed</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'Authorization: GoogleLogin '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$authToken</span><span style="color: #339933;">,</span></pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'Authorization: GoogleLogin '</span><span style="color: #339933;">.</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authToken</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></pre></div></div>

<p>and voila, no more <code>Content is not allowed in prolog</code> error.</p>
<p>Hopefully, this will help some other poor sod out there who has been pulling their hair out.  On the plus side, I now have a very cool wig.</p>
<p>Oh, and because I had so much trouble finding information on sending a put request to Google, here is some sample code:<br />
<em>Note: This code assumes you already have the auth token from Google.</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/atom+xml; charset=utf-8'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Content-Length: '</span><span style="color: #339933;">.</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Authorization: GoogleLogin '</span><span style="color: #339933;">.</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authToken</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Connection: close'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Initiate Curl</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Tell curl what URL we are putting the information too</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$PUTUrl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Open the file we are going to put to the URL</span>
<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test.xml'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Tell curl we are using the PUT request</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_PUT<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Give curl the handle of the file we just opened</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_INFILE<span style="color: #339933;">,</span> <span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* We need to know the size of the file 
   (I had previously created the xml earlier in the 
   script and saved it to a file, hence the reason 
   I'm using a variable called $xml */</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_INFILESIZE<span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the user agent</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #0000ff;">'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the timeout.  If the request has not completed in 30 seconds, terminate the call and show results</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add our headers</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Close the file</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Do the curl request</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'An error occurred with the request'</span><span style="color: #339933;">.</span> <span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2011/02/01/content-is-not-allowed-in-prolog-google-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Messenger won&#8217;t sign in on mac</title>
		<link>http://www.breathteching.com/2010/09/29/messenger-wont-sign-in-on-mac/</link>
		<comments>http://www.breathteching.com/2010/09/29/messenger-wont-sign-in-on-mac/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 01:08:05 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>
		<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[Software Help]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/?p=64</guid>
		<description><![CDATA[If you can&#8217;t seem to sign in to MSN messenger or windows live messenger on the Mac and it keeps saying there is an error or possible network connection. Click Sign in with a different account or change your online status -> Click the Clear Account History Button -> Restart the program -> Sign In [...]]]></description>
			<content:encoded><![CDATA[<p>If you can&#8217;t seem to sign in to MSN messenger or windows live messenger on the Mac and it keeps saying there is an error or possible network connection. </p>
<p>Click Sign in with a different account or change your online status -> Click the Clear Account History Button -> Restart the program -> Sign In</p>
<p>Worked for me &#8211; i think it&#8217;s an issue with at one stage logging in through hotmail messenger. </p>
<p>Hope this helps</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2010/09/29/messenger-wont-sign-in-on-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SWFUpload gets stuck at uploading&#8230;</title>
		<link>http://www.breathteching.com/2010/03/06/swfupload-gets-stuck-at-uploading/</link>
		<comments>http://www.breathteching.com/2010/03/06/swfupload-gets-stuck-at-uploading/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 02:22:21 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>
		<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/?p=41</guid>
		<description><![CDATA[Recently I came across a problem while installing SWFUpload on my latest site. I had the problem before but couldn&#8217;t remember what the solution was. When I uploaded a file with SWFUpload on my mac (OSX 10.5) it would get stuck at the uploading&#8230; status This was cause by my upload_url file not returning any [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I came across a problem while installing SWFUpload on my latest site. I had the problem before but couldn&#8217;t remember what the solution was.</p>
<p>When I uploaded a file with SWFUpload on my mac (OSX 10.5) it would get stuck at the uploading&#8230; status</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>This was cause by my upload_url file not returning any text at all. Make sure when you set up the system that for every error case that some sort of output is displayed. And also on success.</p>
<p>In PHP I simply output the error message then die;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2010/03/06/swfupload-gets-stuck-at-uploading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can&#8217;t get image width or height using javascript in IE 7 and 8</title>
		<link>http://www.breathteching.com/2009/11/27/cant-get-image-width-or-height-using-javascript-in-ie-7-and-8/</link>
		<comments>http://www.breathteching.com/2009/11/27/cant-get-image-width-or-height-using-javascript-in-ie-7-and-8/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 02:00:43 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>
		<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/?p=38</guid>
		<description><![CDATA[Came across this one whilst working with an TinyMCE plugin. I had some additional css on the image i was trying to get the height and width of &#8211; display:none; That&#8217;s the problem. Just use visibility:hidden; in your CSS and all will be fine in the world. Oh just in case you are using the [...]]]></description>
			<content:encoded><![CDATA[<p>Came across this one whilst working with an TinyMCE plugin.</p>
<p>I had some additional css on the image i was trying to get the height and width of &#8211; display:none;</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>That&#8217;s the problem. Just use visibility:hidden; in your CSS and all will be fine in the world.</p>
<p>Oh just in case you are using the incorrect javascript as well.</p>
<p>alert(document.getElementById(&#8216;imageId&#8217;).width);</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2009/11/27/cant-get-image-width-or-height-using-javascript-in-ie-7-and-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forms won&#8217;t submit in IE when pressing enter</title>
		<link>http://www.breathteching.com/2009/06/23/forms-wont-submit-in-ie-when-pressing-enter/</link>
		<comments>http://www.breathteching.com/2009/06/23/forms-wont-submit-in-ie-when-pressing-enter/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 05:48:52 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>
		<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/2009/06/23/forms-wont-submit-in-ie-when-pressing-enter/</guid>
		<description><![CDATA[Hi All I&#8217;ve come across this issue yet again. Realised I&#8217;d forgotten to post it the first time. Instance 1 &#8211; Form has 1 text field, when pressing enter the form doesn&#8217;t submit correctly, either won&#8217;t submit, or won&#8217;t send submit button value through to php. Solution - if ($noOfTextFields == 1) { //fix IE [...]]]></description>
			<content:encoded><![CDATA[<p>Hi All</p>
<p>I&#8217;ve come across this issue yet again. Realised I&#8217;d forgotten to post it the first time.</p>
<p>Instance 1 &#8211; Form has 1 text field, when pressing enter the form doesn&#8217;t submit correctly, either won&#8217;t submit, or won&#8217;t send submit button value through to php.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Solution -</p>
<p><code>if ($noOfTextFields == 1)<br />
{<br />
//fix IE bug where if there is only 1 text field you can't press enter to submit form (it doesn't send submit button name value pair)<br />
$output .= "&lt;input name='" . time() . "' style='display: none;' type='text' / &gt;";<br />
}</code></p>
<p>That should fix that instance</p>
<p>Instance 2 &#8211; Only seems to be happening in IE8 &#8211; When a form is either being hidden (using CSS display or visibility tags) or being creating dynamically when you press enter nothing will happen</p>
<p>Solution &#8211; add the following code to your form tag &#8211; Special thanks to Chris from <a href="http://chrisbegg.com">chrisbegg.com</a> for providing me with an example he used to solve the ajax problem</p>
<p><code>onkeypress=" var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true; if (keycode == 13) {this.submit()}else {return true;}"</code></p>
<p>Make sure that it&#8217;s all on one line you know how javascript dislikes multiple lines.</p>
<p>Good luck to you all. If you find any other occurrences of this problem that aren&#8217;t covered here let me know</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2009/06/23/forms-wont-submit-in-ie-when-pressing-enter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image Caching &#8211; Specifically for Firefox</title>
		<link>http://www.breathteching.com/2009/06/05/image-caching-specifically-for-firefox/</link>
		<comments>http://www.breathteching.com/2009/06/05/image-caching-specifically-for-firefox/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 04:59:16 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>
		<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/2009/06/05/image-caching-specifically-for-firefox/</guid>
		<description><![CDATA[Ok so it&#8217;s Friday and it&#8217;s 2:45pm. So close to the weekend and i just spent an hour or so figuring out how to get my image caching to work on my thumbnails. Against all odds i have managed to get firefox to cache images properly &#8211; well maybe how i want it is a [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so it&#8217;s Friday and it&#8217;s 2:45pm. So close to the weekend and i just spent an hour or so figuring out how to get my image caching to work on my thumbnails. Against all odds i have managed to get firefox to cache images properly &#8211; well maybe how i want it is a better term</p>
<p>So let me explain my thumbnail creator &#8211; Thumbercules, as i have named it (in reference to Gumbercules, a line said my Zoidberg on Futurama (Gumbercules, in reference to someone having the flexibility of Gumbi and the strength of Hercules)), dynamically created thumbnails at a certain height and width specified in the Url that i call eg http://www.domain.com/webimages/x/756/y/160/src/slideshows/images/4a288b1905e1b.jpg. It will check my thumb folder for an already created copy. If it finds one it will return the image from the folder. If not it creates the file then returns it.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>What was happening with my previous caching method was that Firefox would download the image, if i pressed reload it would use the cached version it had. But if i pressed reload again it would download it again and start the process over again. It wasn&#8217;t recreating the image, only clearing the cache.</p>
<p>So numerous tests were performed until i was able to come up with the following:</p>
<p><code>function returnImageFile($fileName, $imageType)<br />
{<br />
$expires = 10800;<br />
header("Expires: " . gmdate("D, d M Y H:i:s", strtotime( "+$expires seconds")) . " GMT");<br />
header("Cache-Control: public, max-age=$expires, pre-check=$expires");<br />
header("Pragma: cache", true);<br />
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))<br />
{<br />
// if the browser has a cached version of this image, send 304<br />
header("Last-Modified: " . gmdate('D, d M Y H:i:s', filemtime($fileName)).' GMT');<br />
header("HTTP/1.1 304 Not Modified");<br />
die;<br />
}else if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &amp;&amp; (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($fileName)))<br />
{<br />
// option 2, if you have a file to base your mod date off:<br />
// send the last mod time of the file back<br />
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($fileName)).' GMT',<br />
true, 304);<br />
header("HTTP/1.1 304 Not Modified");<br />
die;<br />
}else<br />
{<br />
header("Last-Modified: " . gmdate('D, d M Y H:i:s', filemtime($fileName)).' GMT');<br />
}<br />
switch ($imageType)<br />
{<br />
case '1':<br />
case 'gif':<br />
header("Content-type: image/gif");<br />
ob_start();<br />
readfile($fileName);<br />
$ImageData = ob_get_contents();<br />
$ImageDataLength = ob_get_length();<br />
ob_end_clean();<br />
header("Content-Length: ".$ImageDataLength);<br />
echo $ImageData;<br />
break;<br />
case '2':<br />
case 'jpg':<br />
case 'jpeg':<br />
header("Content-type: image/jpeg");<br />
ob_start();<br />
readfile($fileName);<br />
$ImageData = ob_get_contents();<br />
$ImageDataLength = ob_get_length();<br />
ob_end_clean();<br />
header("Content-Length: ".$ImageDataLength);<br />
echo $ImageData;<br />
break;<br />
case '3':<br />
case 'png':<br />
header("Content-type: image/png");<br />
ob_start();<br />
readfile($fileName);<br />
$ImageData = ob_get_contents();<br />
$ImageDataLength = ob_get_length();<br />
ob_end_clean();<br />
header("Content-Length: ".$ImageDataLength);<br />
echo $ImageData;<br />
break;<br />
}<br />
die;</code></p>
<p>This script returns the file with the size value as well as the correct headers to cache the file. If you don&#8217;t want to cache the image then you should change the approach slightly, i can&#8217;t see many times where you would require thumbnails to not be cached. But for other dynamically created images refer to my other post about creating non cached images. <a href="http://www.breathteching.com/2007/11/10/firefox-caches-images-when-it-shouldnt/">Firefox Caches Images when it Shouldn&#8217;t</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>If anyone has any points to make please do make them, i haven&#8217;t had a chance to test this well on IE or Safari. As they don&#8217;t have an easy to use plugin like firebug, which tells you when something is being returned from cache or not.</p>
<p>As always good luck with your programming, hopefully this saves someone some of the hassle, or at least saves someone more time then it took me to write this</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2009/06/05/image-caching-specifically-for-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FireFox Caches Images When It Shouldn&#8217;t</title>
		<link>http://www.breathteching.com/2007/11/10/firefox-caches-images-when-it-shouldnt/</link>
		<comments>http://www.breathteching.com/2007/11/10/firefox-caches-images-when-it-shouldnt/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 04:42:33 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/2007/11/10/firefox-caches-images-when-it-shouldnt/</guid>
		<description><![CDATA[I&#8217;ve recently come across a small annoyance in the firefox browser. I was creating a website that allows you to modify images so they can be printed. I had a caching issue when users would press back then change a setting and go forward again. A refresh would fix the issue. So FireFox was using [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently come across a small annoyance in the firefox browser. I was creating a website that allows you to modify images so they can be printed. I had a caching issue when users would press back then change a setting and go forward again. A refresh would fix the issue. So FireFox was using the cache when I didn&#8217;t want to.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>As usual first attempt was use some php code to specifiy the caching paramaters.</p>
<p>header(&#8216;expires: Mon, 26 Jul 1997 05:00:00 GMT&#8217;);<br />
header(&#8216;cache-control: no-store, no-cache, must-revalidate&#8217;);<br />
header(&#8216;cache-control: post-check=0, pre-check=0&#8242;, FALSE);<br />
header(&#8216;pragma: no-cache&#8217;);</p>
<p>But to no avail, although IE responds extremely well Firefox didn&#8217;t. But i found that if the filename is the same as something in cache FireFox looks at the binary code and determines if anything has changed if it has it will reload the same image changing the cache.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>This leads me to the solution, if you are writing PHP code then simply add this line to the end of the source attribute<br />
<code>&lt;img src="image.jpg?t=&lt;?php echo uniqid();?&gt;" /&gt;</code></p>
<p>You can also achieve a similar process using javascript by utilising Math.rand() .</p>
<p>This tells firefox that the image is different when in reality it isn&#8217;t.</p>
<p>Remember Image Caching is a good thing except in instances such as this. Don&#8217;t restrict caching too much or you will find your bandwidth usage could jump quite a bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2007/11/10/firefox-caches-images-when-it-shouldnt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FireFox and IE Ignore Hosts File</title>
		<link>http://www.breathteching.com/2007/11/05/firefox-and-ie-ignore-hosts-file/</link>
		<comments>http://www.breathteching.com/2007/11/05/firefox-and-ie-ignore-hosts-file/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 03:51:56 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/2007/11/05/firefox-and-ie-ignore-hosts-file/</guid>
		<description><![CDATA[Thought i&#8217;d share this with everyone, I recently ran into some trouble on my machine where my browsers began ignoring my Hosts file. After much annoying testing and what not I eventually found that the reason they were ignoring my hosts file was because it was going through a proxy. I&#8217;ve never set a proxy [...]]]></description>
			<content:encoded><![CDATA[<p>Thought i&#8217;d share this with everyone, I recently ran into some trouble on my machine where my browsers began ignoring my Hosts file.  After much annoying testing and what not I eventually found that the reason they were ignoring my hosts file was because it was going through a proxy.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>I&#8217;ve never set a proxy up on my computer, but recently I installed Google Web Accelerator. Bingo they set up a proxy to speed up the sites you view.</p>
<p>So uninstall that if you have it and Bob&#8217;s your uncle. A normal Add/Remove Programs on XP does the trick.</p>
<p>If it doesn&#8217;t help check if you are using a proxy to connect, if not check your spelling in your hosts file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2007/11/05/firefox-and-ie-ignore-hosts-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Solutions &#8211; A Framework</title>
		<link>http://www.breathteching.com/2007/11/02/debugging-solutions-a-framework/</link>
		<comments>http://www.breathteching.com/2007/11/02/debugging-solutions-a-framework/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 05:25:28 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/2007/11/02/debugging-solutions-a-framework/</guid>
		<description><![CDATA[Recently i&#8217;ve been running into numerous bugs occurring in my code, it mostly stems from the fact I am working with another companies poorly written code, planning on helping them out I decided to accept the job without a proper look at their current code, and database structure. Note To Self &#8211; Don&#8217;t ever accept [...]]]></description>
			<content:encoded><![CDATA[<p>Recently i&#8217;ve been running into numerous bugs occurring in my code, it mostly stems from the fact I am working with another companies poorly written code, planning on helping them out I decided to accept the job without a proper look at their current code, and database structure. <strong>Note To Self &#8211; </strong>Don&#8217;t ever accept a job that you don&#8217;t see first or create yourself.</p>
<p>Anyway, bugs galore is something that I&#8217;ve had to deal with. So I assumed other people would probably be in the same dilemma at some point in the programming lives where they had run out of ways to debug. So I am attempting to write a debuggers framework, particularly for dealing with code from other people. Although this list will apply to any code, your own, others, or a mixture.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Step 1 &#8211; Find the bug. This is normally the easiest step <img src='http://www.breathteching.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> . Many times someone else will do this for you. Take note of the location of the bug, any error messages it emits, and the variables in the URL. If an error is generated then you have struck a gold mine, this is normally due to a syntax error somewhere in the code, take note of any line numbers that it has given you and continue.</p>
<p>Step 2 &#8211; Open up the code and peruse the file. If the file you are working on calls on a number of other pages, or functions from other files open those up as well. As you are perusing look out for the obvious errors, if you have an error code or a line number in which the error has occured check that this line and the line before and after it are syntactically correct.</p>
<p>Step 3 &#8211;  Still no Luck? Check the logic. Logic errors account for most of my errors especially when dealing with date data types, the way my brain thought about the scenario was backwards or somethign unexpected came through.  Check that they are correct do some simple scenarios in your head. If this doesn&#8217;t solve the problem, change any changes make to the original.</p>
<p>Step 4 &#8211; Google. Need I say more,  not really but a couple of tips won&#8217;t go astray.</p>
<ul>
<li>Search Terms &#8211; Type in the box what you would say if you were asking a fellow programmer. My website is generating broken images when I do such and such.  Still no luck be less specific &#8211; Images are broken when my page loads.</li>
<li>Google Groups. Sometimes a quick search of google groups can give immediate results. Sometimes not.</li>
</ul>
<p>Step 5 &#8211; Take a break &#8211; take a 10 &#8211; 20 minute break, if you have been working on the bug for more then an hour. Play a game of solitaire or minesweeper to relieve some stress, go get a cup of tea/coffee. Whatever it takes to get your mind off the problem. Dwelling on something is normally the worst scenario to be in.</p>
<p>Step 6 &#8211; Feel better? Not for long&#8230; If you are at this point and it still needs to be fixed urgently then its time for some commenting of someone elses code, not the best scenario but a very good one.</p>
<ul>
<li>Write your own output function for debugging &#8211; See my post on &#8211; Spitting &#8211; Soothes the Soul and Eases the mind.</li>
<li>Use html comments to output some code in the background, this is especially important when you are fixing bugs on a live site. People are unaware anything has changed, but you can continue to debug freely. Well not as free as you would like but fairly unrestricted. If you have a Sandbox type area then use that and only upload changes when you have fixed it.</li>
<li>If you aren&#8217;t on a live server. You got it made &#8211; Die Statements to infinite and beyond. If you are debugging javascript Alert statements are your friend. Before each die statement place a print_r($_GLOBALS) or whichever custom function you made see Spitting Link two points up ^</li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Step 7 &#8211; This is never a good step to be at. Now is about the  2 &#8211; 5 hour mark. You are more then likely grumpy, irritated, snappying and any and every living thing and even some inanimate objects. But there is light at the end of the tunnel. Step 8  is go to sleep. But first you should find an appropriate forum that posts similar problems to what you are having. Try to find one that is still active. Put a few posts up on a number of forums then go to Step 8.</p>
<p>Step 8 &#8211; Sleep on it. You might toss and turn for 30 minutes while you attempt to break your brains vice like grip on the problem, but now is your subconscious&#8217;s time to shine. Ever noticed that your thoughts are clearer in the morning, or you have a solution to the problem you&#8217;d been having about how you would begin a project. Daybreak comes, you stir from your slumber, roll out of bed (insert personal wake up routine here), *Ding* Lightbulb, thats an idea! Run frantically to the computer or to a pen and paper and jot down any partial, possible, probable, plausible, portable, pottable, porsche (too many p words) solution that you think up. Driving to work and think up one, use your phone, most phones these days will have some sort of voice recording (not advising using your phone while driving &#8211; many phones with recorders have a quick use button.), or pull over and write it down. Forgetting it would be terrible at this point.</p>
<p>Step 9 &#8211; Try some of your ideas (if any).</p>
<p>Step 10 &#8211; Check your forum posts, any hits, and views, most of all any Replies???? If there are go check them out. If not start again from Step 2.</p>
<p>I know the feeling of desperation when it comes to debugging, mood swings, cussing (worse then a sailor, and if you are navy computer programmer, dear baron that would be some colourful language), all the side effects of a nagging coding issue.</p>
<p>Usually many people will solve their problems by Step 3 &#8211; 4. Simply stepping through the code in a calm manner can often prove to be the best approach. Try not to get too rialled up, it&#8217;s only code. :&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2007/11/02/debugging-solutions-a-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forms submitting twice in Firefox</title>
		<link>http://www.breathteching.com/2007/11/01/forms-submitting-twice-in-firefox/</link>
		<comments>http://www.breathteching.com/2007/11/01/forms-submitting-twice-in-firefox/#comments</comments>
		<pubDate>Thu, 01 Nov 2007 04:00:00 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[Coding Help]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/2007/11/01/forms-submitting-twice-in-firefox/</guid>
		<description><![CDATA[Recently I uncovered an extremely annoying and difficult to find bug in a website I&#8217;ve been modifying a client. There are two things I dislike, the first being debugging code where there exists some obscure error, the second and the one I dislike the most is debugging someone else&#8217;s code where there exists some obscure [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I uncovered an extremely annoying and difficult to find bug in a website I&#8217;ve been modifying a client. There are two things I dislike, the first being debugging code where there exists some obscure error, the second and the one I dislike the most is debugging <strong>someone else&#8217;s</strong> code where there exists some obscure error.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Poorly written, poorly commented (something I also do but should improve), poorly formatted, and all round poorly done, is is the state of the code I was faced with. The predicament you might ask or yell! I was adding an item to a shopping cart, but in FireFox it was being added twice, where as in IE 7 only once, so begins the bane of my existance (for the day).</p>
<p>Now first things first, check the SQL&#8230; &#8220;nup that&#8217;s perfect&#8221;, ok send me an email every time something gets added to the database. Received 2 emails. &#8230;.*Pulls some hair out*. Digging into my repertoire, I began utilising all my knowledge of debugging, in between extracting more chunks of hair from any place I could find, (at this stage there isn&#8217;t much left but on the bright side I have a nice Brazilian, and I could be in the Olympics in swimming.)</p>
<p>Then comes Google, the saviour of many, the enemy of few (except yahoo, ninemsn,  hotbot, altavista, etc).  Enter Search Terms : Form Submitting Twice in FireFox. Results &#8211; a Plethora of semi useful information.</p>
<p>From the rubble a solution was found &#8211; <a rel="nofollow" href="http://forum.powweb.com/showpost.php?p=422894&amp;postcount=1">from Sparhawk</a> &#8211; to sum up his post, any element in your html that contains an empty src attribute will, in FireFox, invoke a call to the same page. In IE it invokes a call to the current working directory.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1300158297655257";
/* 468x60, created 6/28/09 */
google_ad_slot = "9266821861";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Elements that generally have a src attribute are external cs, javascript scripts, and by far the most common, images. I&#8217;m yet to find the empty src attribute (as I didn&#8217;t write the code, the main file of the website is &gt;250kb, about 8 pages are included every page load, and I found a better solution &#8211; keep reading) but sometimes the removal of it is not needed, simply this, if you are getting duplicate entries into the database, change the form type to a POST instead of a GET. Simply the image loads the same page but with no variables, most form submit page checks that the submit button variable exists, if not it won&#8217;t continue to run. If you are getting duplicate entries and are still unsure about whether the entry is being added by your sql command, append the date (something that shows what second it is) to a title, many of my duplicate entries were at elast 2 &#8211; 4 seconds apart.</p>
<p>For optimal performance it would be better to remove the empty src if it can be found. I hope this helps someone as i spent easily 3 &#8211; 5 hours trying to get it to work, when all I needed to do was replace the POS in POST with GE. The slowest typist could achieve this in far less time then I took to debug. <img src='http://www.breathteching.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Nuff Said. Comment if it helped you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2007/11/01/forms-submitting-twice-in-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

