<?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>Gabriel Jones &#187; php</title>
	<atom:link href="http://gabrieljones.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://gabrieljones.com</link>
	<description>Web Developer Weblog</description>
	<lastBuildDate>Fri, 29 Jul 2011 13:27:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Order Posts by Meta Value Numbers in Wordpress</title>
		<link>http://gabrieljones.com/order-posts-by-meta-value-numbers-in-wordpress/</link>
		<comments>http://gabrieljones.com/order-posts-by-meta-value-numbers-in-wordpress/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 01:13:09 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://gabrieljones.com/?p=31</guid>
		<description><![CDATA[The following changes work on Wordpress version 2.8.*, prior version will need a slightly different change.
A brief background first. I needed to have a page in which my posts were ordered by the meta_values to a particular meta_key. By default meta_value is LONGTEXT data in mysql, therefore we are unable to order posts by meta_value [...]]]></description>
			<content:encoded><![CDATA[<p>The following changes work on Wordpress version 2.8.*, prior version will need a slightly different change.</p>
<p>A brief background first. I needed to have a page in which my posts were ordered by the meta_values to a particular meta_key. By default meta_value is LONGTEXT data in mysql, therefore we are unable to order posts by meta_value NUMBERS. To force mysql to return the meta_value entry as a NUMBER, we must pass a query like this: &#8216;meta_value+0&#8242;.</p>
<p>I set my custom page up to run a query_posts.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'meta_key=views&amp;amp;orderby=meta_value_number&amp;amp;order=DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then use The Loop as normal.</p>
<p>Inside query.php I did the following:<br />
Goto line ~2035, add below</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$allowed_keys</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'meta_value_number'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Goto line ~2057, after case break, add below</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'meta_value_number'</span><span style="color: #339933;">:</span>
<span style="color: #000088;">$orderby</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$wpdb</span>-&amp;gt;postmeta.meta_value+0&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Thats it! You can now pull posts ordered by meta_value NUMBERS!!</p>
<p>Remember that this method only works in 2.8.*, if you have an earlier version and would like to figure it out, or have a solution, please feel free to comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://gabrieljones.com/order-posts-by-meta-value-numbers-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a PHP Verification Image</title>
		<link>http://gabrieljones.com/creating-a-php-verification-image/</link>
		<comments>http://gabrieljones.com/creating-a-php-verification-image/#comments</comments>
		<pubDate>Fri, 23 Mar 2007 02:26:14 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://gabrieljones.com/?p=13</guid>
		<description><![CDATA[You will need to have GD library loaded on your server, and you should be using PHP4+.  To check to see if you have either of these running, simply create a file, call it whatever you want, I call mine info.php. Place the following code in there:

1
&#38;lt;? phpinfo&#40;&#41;; ?&#38;gt;

If all checks out, then you [...]]]></description>
			<content:encoded><![CDATA[<p>You will need to have GD library loaded on your server, and you should be using PHP4+.  To check to see if you have either of these running, simply create a file, call it whatever you want, I call mine <em>info.php</em>. Place the following code in there:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>? <span style="color: #990000;">phpinfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> ?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If all checks out, then you are ready to move on.</p>
<p>Firstly, you will need to create a session, both in your image script, and the page that will be serving the image, you will see why later.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And for some, you will have to create a save path for your sessions.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">session_save_path</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'path/to/tmp'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Once you have set this up, you can now start creating your image. Lets start with the variables needed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">28</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$font</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;fonts/arial.ttf&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$font_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>These variables can be changed to your liking, I chose the basics to get you started. But, for example, you can change <strong>arial.ttf</strong> to whatever <strong>.ttf</strong> you like, as long as it is not wingdings, you should be all set.<br />
Next we create the image, and set its background color and text color.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$background_color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">215</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text_color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now we create our random string for which we set our text to the image for display, and set our SESSION variable.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9999</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">14</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'verify'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>With that complete, we move on to applying the random string to the blank image we created earlier.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">putenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GDFONTPATH='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>strlen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$ny</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">245</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$angle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">22</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">19</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagettftext</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font_size</span><span style="color: #339933;">,</span> <span style="color: #000088;">$angle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ny</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text_color</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$x</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">18</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Font file does not exist.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now our image has been created, and our SESSION variable has been set, we are almost finished.  All that is left is to set our headers, and send the image off.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Last-Modified: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: no-store, no-cache, must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: post-check=0, pre-check=0&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pragma: no-cache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: image/jpeg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We do not <strong>ever</strong> want to cache our images, and we <strong>always</strong> want to destroy them after we send them.</p>
<p>Now, in whatever page you choose to have this verification work, you simply need to add a <em>session_start();</em> and in an image tag, point the source to this php file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;image_verification.php&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Verify&quot;</span> <span style="color: #339933;">/&gt;</span></pre></td></tr></table></div>

<p>You should be able to figure out the rest when it comes to comparing the user input with the SESSION variable.</p>
]]></content:encoded>
			<wfw:commentRss>http://gabrieljones.com/creating-a-php-verification-image/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Optimizing PHP &amp; SQL</title>
		<link>http://gabrieljones.com/optimizing-php-sql/</link>
		<comments>http://gabrieljones.com/optimizing-php-sql/#comments</comments>
		<pubDate>Wed, 18 May 2005 01:24:44 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://gabrieljones.com/?p=3</guid>
		<description><![CDATA[Commonly we see php being used as an interface between the client and the database providing the information. Very few implementations utilize optimization, and thus, reduce performance.  Listed below are many techniques that should be used to optimize php to sql communication.

Do not use SELECT * unless you must
Use SELECT priorities for better control
SELECT [...]]]></description>
			<content:encoded><![CDATA[<p>Commonly we see php being used as an interface between the client and the database providing the information. Very few implementations utilize optimization, and thus, reduce performance.  Listed below are many techniques that should be used to optimize php to sql communication.</p>
<ol>
<li><span>Do not use SELECT * unless you must</span></li>
<li><span>Use SELECT priorities for better control</span></li>
<li><span>SELECT var IN ([constance,...]) is very fast</span></li>
<li><span>Use default values for INSERT when you can</span></li>
<li><span>Do not create indexes you are not going to use</span></li>
<li><span>Indexes are good for reads, but bad for writes</span></li>
<li><span>When joining tables, use numbers instead of strings if you can</span></li>
<li><span>Create your tables with a fixed-table format if possible</span></li>
<li><span>Use OPTIMIZE TABLE and ANALYZE TABLE regularly</span></li>
</ol>
<p>There are other techniques both in php design and database design that will optimize performance, but in terms of php and sql communication, this list will get you running more efficiently.</p>
]]></content:encoded>
			<wfw:commentRss>http://gabrieljones.com/optimizing-php-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

