<?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; PHP Scripts</title>
	<atom:link href="http://www.breathteching.com/category/php-scripts/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>Refreshing Map View (MKMapView) for iPhone development</title>
		<link>http://www.breathteching.com/2011/02/13/refreshing-map-view-mkmapview-for-iphone-development/</link>
		<comments>http://www.breathteching.com/2011/02/13/refreshing-map-view-mkmapview-for-iphone-development/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 12:14:56 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[Software Help]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/?p=90</guid>
		<description><![CDATA[Ok so i just spent a long time searching how to reload a map view. It&#8217;s quite simple [map setRegion:map.region animated:TRUE]; The problem i was having was when i was adding annotations i was adding them through a background thread. So if you want to reload a map after adding annotations make sure you are [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so i just spent a long time searching how to reload a map view. </p>
<p>It&#8217;s quite simple<br />
<code><br />
[map setRegion:map.region animated:TRUE];<br />
</code></p>
<p>The problem i was having was when i was adding annotations i was adding them through a background thread. So if you want to reload a map after adding annotations make sure you are calling it back in the main thread.</p>
<p><code><br />
//add to your threaded code<br />
[self performSelectorOnMainThread:@selector(reloadMap) withObject:nil waitUntilDone:FALSE];</p>
<p>//create function<br />
-(void) reloadMap<br />
{<br />
[map setRegion:map.region animated:TRUE];<br />
}<br />
</code></p>
<p>Hope this helps someone, if it does let me know so i can at least feel like 2.5 hours wasn&#8217;t a complete waste <img src='http://www.breathteching.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2011/02/13/refreshing-map-view-mkmapview-for-iphone-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Function for dealing with quotes in input fields in HTML/PHP</title>
		<link>http://www.breathteching.com/2008/03/24/function-for-dealing-with-quotes-in-input-fields-in-htmlphp/</link>
		<comments>http://www.breathteching.com/2008/03/24/function-for-dealing-with-quotes-in-input-fields-in-htmlphp/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 10:09:57 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://www.breathteching.com/2008/03/24/function-for-dealing-with-quotes-in-input-fields-in-htmlphp/</guid>
		<description><![CDATA[Anyone who has coded html has come across this issue, you have an input field in your form but oh no! someone has entered a single or double quote into the value and they are now trying to edit it, and all you see in the input box is John\ instead of John\&#8217;s. It is [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone who has coded html has come across this issue, you have an input field in your form but oh no! someone has entered a single or double quote into the value and they are now trying to edit it, and all you see in the input box is John\ instead of John\&#8217;s. It is one of those reoccuring issues which I face from time to time, but not anymore.</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>Every now and then i stumble across a new issue which my current method doesn&#8217;t solve. Talk about frustration, going through old code just to make sure you aren&#8217;t using that incorrect method. Heres something I whipped up tonight which I thought I should post asap.<br />
<code><br />
function form_encode($string)<br />
{<br />
/*make sure you remove the spaces in the first variable of the str_replace function, Word press doesn't seem to like to print out the htmlentity of the ampersand which is understandable*/<br />
<span style="font-size: 10px;">return str_replace("&amp; amp ;", "&amp;", (htmlentities(stripslashes($string), ENT_QUOTES)));</span><br />
}<br />
</code>I&#8217;m pleased with this solution, i&#8217;m hoping it&#8217;s not too computational intensive as it uses str_replace only once.</p>
<p>This function is especially effective when the data is being pulled from a database, but i found i needed a solution that can not only use data from a database and encode it properly but also if you are reusing $_POST variables, my forms if they fail reuse the same values, and i was getting alot of &#8220;John\ &#8221; errors but using the stripslashes then the htmlentities fixed it up really nice.</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>The reason for the str_replace is the htmlentities function will change the ampersand at the start of some special characters into the htmlentity &amp; amp ; which is what the function is supposed to do.. funny that. But a simple str_replace returns any double encoded htmlentites back into their original format, which means perfect display for us and easier forms from now on.</p>
<p>This has been tested on Firefox for Mac, Safara (Mac), will test on PC later. Thought I&#8217;d get this up asap for everyone. Will be interested to see if anyone finds it though.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2008/03/24/function-for-dealing-with-quotes-in-input-fields-in-htmlphp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP Redirect Code &#8211; with javascript</title>
		<link>http://www.breathteching.com/2007/10/27/php-redirect-code-with-javascript/</link>
		<comments>http://www.breathteching.com/2007/10/27/php-redirect-code-with-javascript/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 11:05:54 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://breathteching.com/?p=5</guid>
		<description><![CDATA[Ever needed a redirect function that would know when to use javascript of php. Well the wait is over *crowd goes wild*&#8230;. sorry here it is To use the function simply call it like so: &#60;?php $variables = array('firstvar' =&#62; $firstVar, 'secondvar' =&#62; "hello world"); REDIRECT("newPage.php?currentVar=123", $variables); ?&#62; and here it is again if you [...]]]></description>
			<content:encoded><![CDATA[<p>Ever needed a redirect function that would know when to use javascript of php. Well the wait is over *crowd goes wild*&#8230;. sorry <a href="http://breathteching.com/?attachment_id=6" rel="attachment wp-att-6" title="redirect function">here it is</a></p>
<p>To use the function simply call it like so:<br />
<code>&lt;?php<br />
$variables = array('firstvar' =&gt; $firstVar,<br />
'secondvar' =&gt; "hello world");<br />
REDIRECT("newPage.php?currentVar=123", $variables);<br />
?&gt;<br />
</code></p>
<p>and <a href="http://breathteching.com/?attachment_id=6" rel="attachment wp-att-6" title="redirect function">here it is</a> again if you missed it</p>
<p class="MsoNormal">and voila!</p>
<p>If you liked it let me know please.</p>
<p class="MsoNormal">I think there is still an issue with if the variable already exists in the target, i just haven&#8217;t had the time to work on it.<br />
Maybe i need to follow my tips in my other post &#8211; 4 Tips for working from home successfully</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2007/10/27/php-redirect-code-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>$_FILES Array and its Confusing Structure</title>
		<link>http://www.breathteching.com/2007/10/27/_files-array-and-its-confusing-structure/</link>
		<comments>http://www.breathteching.com/2007/10/27/_files-array-and-its-confusing-structure/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 10:53:57 +0000</pubDate>
		<dc:creator>bretto36</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>

		<guid isPermaLink="false">http://breathteching.com/?p=3</guid>
		<description><![CDATA[Have you ever noticed that the $_FILES array has an extremely odd structure that isn&#8217;t the usual type of array. The script i wrote helps to put it in an order so you can simply step through each one without having to write any sort of confusing loop. It&#8217;s implementation can be seen below: // [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever noticed that the $_FILES array has an extremely odd structure that isn&#8217;t the usual type of array. The script i wrote helps to put it in an order so you can simply step through each one without having to write any sort of confusing loop.</p>
<p>It&#8217;s implementation can be seen below:<br />
<code><br />
// a file field with the name image[] was passed<br />
//if it were a non array input it would simply be if (!empty($files['image']))...<br />
$files = change_file_array($_FILES);<br />
if (!empty($files))<br />
{<br />
foreach ($files['image'] as $key =&gt; $f)<br />
{<br />
if ($f['error'] == 0 &amp;&amp; $f['size'] &gt; 0)<br />
{<br />
//do somethign with file here<br />
}<br />
}<br />
}<br />
</code></p>
<p>I&#8217;m still getting used to wordpresses editor sorry about the indenting.</p>
<p>Click <a href="http://breathteching.com/wp-content/uploads/2007/10/change_file_array.zip" title="change_file_array.zip">here</a> download the script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.breathteching.com/2007/10/27/_files-array-and-its-confusing-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

