<?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>techrageo.us &#187; PHP</title>
	<atom:link href="http://techrageo.us/taxonomy/categories/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://techrageo.us</link>
	<description>insight on technology</description>
	<lastBuildDate>Sat, 22 Oct 2011 12:18:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>PHP and WordPress SVG Basics</title>
		<link>http://techrageo.us/2007/04/07/php-and-wordpress-svg-basics/</link>
		<comments>http://techrageo.us/2007/04/07/php-and-wordpress-svg-basics/#comments</comments>
		<pubDate>Sun, 08 Apr 2007 01:54:58 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://techrageo.us/2007/04/07/php-and-wordpress-svg-basics/</guid>
		<description><![CDATA[Scalable Vector Graphics, or SVG, is an XML standard for vector graphics (of course). That means that it contains descriptions of shapes, such as rectangles, lines, circles, and text, in an XML format. SVG provides a robust definition language for drawings. The drawing at the right was a sample SVG drawing included in Jasc&#8217;s WebDraw. [...]]]></description>
			<content:encoded><![CDATA[<p><img align="right" src="/wp-content/code/svgbutterfly.jpg"/>Scalable Vector Graphics, or SVG, is an XML standard for vector graphics (of course). That means that it contains descriptions of shapes, such as rectangles, lines, circles, and text, in an XML format.</p>
<p>SVG provides a robust definition language for drawings. The drawing at the right was a sample SVG drawing included in Jasc&#8217;s WebDraw. There are many other examples on the web of complex SVG drawings.</p>
<p>I&#8217;ve been playing around with SVG just a bit and thought I&#8217;d record the basics of getting simple shapes embedded in a page and how to do it with PHP and in WordPress.</p>
<p>Grant posted an article here a couple years ago on creating <a href="http://techrageo.us/2005/06/22/svg-graphs-with-php/">SVG Graphs With PHP</a>, so check that out too if you want a more complicated example.</p>
<h3>SVG in HTML</h3>
<p>The simplest way to get SVG vector drawings in an HTML file is to embed an .svg file. The HTML and SVG source will look something like the following</p>
<p><strong>HTML Code</strong><br />
<code><br />
&lt;html&gt;<br />
&lt;body&gt;<br />
Circle In A Square&lt;br/&gt;<br />
&lt;embed width="100" height="100" src="/wp-content/code/phpsvg1.svg"/&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p><strong>SVG Code</strong><br />
<code><br />
&lt;?xml version="1.0"?&gt;<br />
&lt;svg width="100px" height="100px" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"&gt;<br />
	&lt;rect x="10" y="10" width="50" height="50"<br />
		fill="#777" stroke="red" stroke-width="3"  /&gt;<br />
	&lt;circle cx="16" cy="16" r="8" fill="black" stroke="yellow" stroke-width="3"/&gt;<br />
&lt;/svg&gt;<br />
</code></p>
<p><strong>Output</strong></p>
<p>Circle In A Square<br />
<embed width="100" height="100" src="/wp-content/code/phpsvg1.svg"/></p>
<h3>WordPress and SVG</h3>
<p>To include an SVG drawing in a WordPress post, simply create and upload an SVG file then put the HTML EMBED tag in your WordPress post.<br />
<code><br />
&lt;embed width="100" height="100" src="/wp-content/code/phpsvg1.svg"/&gt;<br />
</code></p>
<h3>Basic SVG Tags</h3>
<p>There are plenty of exhaustive SVG references on the web, so let&#8217;s look at just the tags used above.</p>
<div style="padding-left:10px">
<p><strong>svg</strong> &#8211; This tag indicates the beginning of an SVG drawing. The attibutes used above are width and height, both self-<br />
describing, viewBox which describes a clipping rectangle for the drawing, and xmlns which simply defines the default namespace for<br />
the XML tags used in the drawing.</p>
<p><strong>rect</strong> &#8211; Here we define the rectangle, with x and y being the upper-left corner, width and height again are obvious, fill<br />
is the rectangle&#8217;s color in hex digits, stroke is the color of the line used to draw the outside boundary of the rectangle, and<br />
stroke-width is the width of that line.</p>
<p><strong>circle</strong> &#8211; This defines the circle. cx and cy determine the center point of the circle, while r is the radius; fill,<br />
stroke, and stroke-width have the same meanings as was used for the rectangle.</p>
</div>
<h3>PHP SVG</h3>
<p>Of course, outputting SVG from PHP requires that you output the SVG source back to the browser. However, PHP output will normally be marked as being of <em>Content-Type: text/html</em>, so you have to do two things to send back SVG:
<ol>
<li>First, set the Content-Type header to <em>image/svg+xml</em></li>
<li>Second, make sure your php file does not contain any text outside the script tags.</li>
</ol>
<p>So, the following PHP generates the above SVG drawing.<br />
<code><br />
&lt;?php<br />
$svg = &lt;&lt;&lt;END<br />
&lt;?xml version="1.0" standalone="no"?&gt;<br />
&lt;svg width="100px" height="100px" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"&gt;<br />
	&lt;rect x="10" y="10" width="50" height="50"<br />
		fill="navy" stroke="red" stroke-width="3"  /&gt;<br />
	&lt;circle cx="16" cy="16" r="8" fill="black" stroke="yellow" stroke-width="3"/&gt;<br />
&lt;/svg&gt;<br />
END;<br />
header("Content-Type: image/svg+xml");<br />
echo $svg;<br />
?&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2007/04/07/php-and-wordpress-svg-basics/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Security and Google Code Search</title>
		<link>http://techrageo.us/2006/10/09/security-and-google-code-search/</link>
		<comments>http://techrageo.us/2006/10/09/security-and-google-code-search/#comments</comments>
		<pubDate>Mon, 09 Oct 2006 09:05:50 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Searching]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://techrageo.us/2006/10/09/security-and-google-code-search/</guid>
		<description><![CDATA[If you use WordPress be careful. An example Google Code Search search going around is &#8220;username file:wp-config.php&#8221; which happily displays username and passwords in WordPress config files&#8230; if they&#8217;re in compressed archives or a publicly accessible directory. Same goes for other configuration or settings files. For instance, connection strings in web.config files (connection string file:web.config), [...]]]></description>
			<content:encoded><![CDATA[<p>If you use WordPress be careful. An example Google Code Search search going around is &#8220;<a href="http://google.com/codesearch?as_q=username&amp;as_filename=wp-config.php">username file:wp-config.php</a>&#8221; which happily displays username and passwords in WordPress config files&#8230; if they&#8217;re in compressed archives or a publicly accessible directory.</p>
<p>Same goes for other configuration or settings files. For instance, connection strings in web.config files (<a href="http://google.com/codesearch?q=connectionstring+file%3Aweb.config">connection string file:web.config</a>), Movable Type passwords (<a href="http://google.com/codesearch?q=file%3Amt-db-pass.cgi">file:mt-db-pass.cgi</a>), keygen name serial, backdoor passwords (<a href="http://google.com/codesearch?q=backdoor.*password">backdoor.*password</a>), MySQL root passwords (<a href="http://google.com/codesearch?q=file%3Aconfig.inc.php+%22MySQL+password%22+root">file:config.inc.php &#8220;MySQL password&#8221; root</a>, etc.</p>
<p>Of course, one could search for code vulerable to cross-site scripting, SQL Injection (<a href="http://google.com/codesearch?q=lang%3Aphp+mysql_query%5C%28.*%5C%24_%28GET%7CPOST%7CCOOKIE%7CREQUEST%29.*%5C%29">lang:php mysql_query\(.*\$_(GET|POST|COOKIE|REQUEST).*\)</a>), remote code execution <a href="http://google.com/codesearch?q=lang:php (include|require)\s*(\(|\s).*\$_(GET|POST)">(lang:php (include|require)\s*(\(|\s).*\$_(GET|POST))</a>, header injection, and on and on.</p>
<p>Spammers can cull email addresses from code with a simple code search as well (<a href="http://google.com/codesearch?q=%5Ba-z%5D*%40%5Ba-z%5D*.com">[a-z]*@[a-z]*.com</a>)</p>
<p>So what have we learned?</p>
<ul>
<li>Do not put passwords in public code, including zipped code archives.</li>
<li>Be more diligent to protect against SQL Injection and similar exploits. I.e. do not trust user input of any sort.</li>
<li>Do not put email addresses in public code.</li>
<li>In general, keep your eyes and ears open for security exploits and protect against them.</li>
</ul>
<p>We can&#8217;t be perfect, but we ought to try.</p>
<p>Seen <a href="http://deathbycomet.com/2006/10/05/some-of-your-db-passwords-are-belong-to-us/">here</a>, <a href="http://illyana.com/2006/10/05/googles-code-search/">here</a>, and <a href="http://ilia.ws/archives/133-Google-Code-Search-Hackers-best-friend.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2006/10/09/security-and-google-code-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hack Google Earth KML Files</title>
		<link>http://techrageo.us/2005/07/06/hack-google-earth-kml-files/</link>
		<comments>http://techrageo.us/2005/07/06/hack-google-earth-kml-files/#comments</comments>
		<pubDate>Wed, 06 Jul 2005 04:02:10 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Mapping]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://techrageo.us/2005/07/06/hack-google-earth-kml-files/</guid>
		<description><![CDATA[RuiCarmo of Tao of Mac has a great tutorial on hacking Google Earth KML (Keyhole Markup Language) files in PHP. Fun stuff. Seen here. Google Earth / Keyhole is a downloadable mapping application that&#8217;s free for the downloading. Google Earth Plus is a $20 upgraded version that includes GPS integration, high-res printing, email support, annotation, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://the.taoofmac.com.nyud.net:8090/space/RuiCarmo">RuiCarmo</a> of <a href="http://the.taoofmac.com.nyud.net:8090/space">Tao of Mac</a> has <a href="http://the.taoofmac.com.nyud.net:8090/space/blog/2005-07-04">a great tutorial</a> on hacking <a href="http://earth.google.com/">Google Earth</a> <a href="http://www.keyhole.com/kml/kml_doc.html">KML</a> (Keyhole  Markup Language) files in PHP. Fun stuff. Seen <a href="http://www.makezine.com/blog/archive/2005/07/how_to_make_kml.html">here</a>.</p>
<p>Google Earth / Keyhole is a downloadable mapping application that&#8217;s <a href="http://desktop.google.com/download/earth/index.html">free for the downloading</a>. <a href="http://earth.google.com/earth_plus.html">Google Earth Plus</a> is a $20 upgraded version that includes GPS integration, high-res printing, email support, annotation, and .csv importing.</p>
<p><strong>Background &#8211; Google Earth in action</strong><br />
<img src='http://techrageo.us/wp-content/gearth01.jpg' alt='Google Earth - Austin, TX' /><br />
Google Earth</p>
<hr />
<img src='http://techrageo.us/wp-content/gearth02.jpg' alt='Google Earth - Downtown Austin, TX' /><br />
Google Earth &#8211; Downtown Austin, TX</p>
<hr />
<img src='http://techrageo.us/wp-content/gearth03.jpg' alt='Google Earth - IBM Austin' /><br />
Google Earth &#8211; IBM Austin</p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2005/07/06/hack-google-earth-kml-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVG Graphs with PHP</title>
		<link>http://techrageo.us/2005/06/22/svg-graphs-with-php/</link>
		<comments>http://techrageo.us/2005/06/22/svg-graphs-with-php/#comments</comments>
		<pubDate>Wed, 22 Jun 2005 23:46:36 +0000</pubDate>
		<dc:creator>grant</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://techrageo.us/?p=17</guid>
		<description><![CDATA[SVG images are here, soon they will pretty standard on the web. The Adobe SVG plugin allows users to view the images and soon Mozilla Firefox will have SVG support built in so that no external plugin will be necessary. Why use SVG images instead of standards like JPG or PNG? In most instances they [...]]]></description>
			<content:encoded><![CDATA[<p>SVG images are here, soon they will pretty standard on the web.  The Adobe SVG plugin allows users to view the images and soon Mozilla Firefox will have SVG support built in so that no external plugin will be necessary.</p>
<p>Why use SVG images instead of standards like JPG or PNG?</p>
<ul>
<li>In <em>most</em> instances they are smaller.</li>
<li>They do not lose quality when they are magnified in size.</li>
<li>They are easier to use and manipulate than standard image formats.</li>
<li>You can generate them from your application without needing a special library (like the gd library).</li>
</ul>
<p>Why not use SVG images?</p>
<ul>
<li>They do require a browser plugin to view.</li>
<li>Easy manipulation is not always a good thing.</li>
</ul>
<p>This document is directed towards generating graphs with PHP, but you could just as easily generate any other type of image.  It is <em>almost</em> as simple as generating simple HTML.  Consider this as a small example of what can be done.</p>
<h2>Your first SVG graph</h2>
<p>First we&#8217;ll take a look at the SVG code needed to create simple bargraph.<br />
<code><br />
&lt;svg width="12cm" height="9cm" viewBox="0 0 1200 900" xmlns="http://www.w3.org/2000/svg" version="1.1"&gt;<br />
&lt;g>&lt;text x="150" y="1" font-size="75" fill="black" >Sales (in millions)&lt;/text&gt;&lt;/g&gt;<br />
&lt;rect x="95" y="405.56" width="122.22" height="494.44" fill="#ffbbbb" stroke="black" stroke-width="1" rx="2" /&gt;<br />
&lt;rect x="217.22" y="455" width="122.22" height="445" fill="#bbffbb" stroke="black" stroke-width="1" rx="2"  /&gt;<br />
&lt;/svg&gt;<br />
</code><br />
This is only a partial bargraph (2 bars), so don&#8217;t get too excited yet.  The syntax should look very familiar to anyone who has used HTML or XML (which SVG is).</p>
<p>The first and last lines are defining the document as an SVG document.<br />
<code><br />
&lt;svg width="12cm" height="9cm" viewBox="0 0 1200 900" xmlns="http://www.w3.org/2000/svg" version="1.1"&gt;<br />
&lt;/svg&gt;<br />
</code></p>
<p>The second line draws the title &#8220;Sales (in millions)&#8221; at the top of the image in a large font.<br />
<code><br />
&lt;g&gt;&lt;text x="150" y="1" font-size="75" fill="black" >Sales (in millions)&lt;/text&gt;&lt;/g&gt;<br />
</code></p>
<p>The remaining two lines are where the two boxes are drawn, one for each data point.<br />
<code><br />
&lt;rect x="95" y="405.56" width="122.22" height="494.44" fill="#ffbbbb" stroke="black" stroke-width="1" rx="2"  /&gt;<br />
&lt;rect x="217.22" y="455" width="122.22" height="445" fill="#bbffbb" stroke="black" stroke-width="1" rx="2"  /&gt;<br />
</code></p>
<p>Piece of cake, right?  Well, if you look at the svg that code creates you&#8217;ll notice that it isn&#8217;t much to brag about.  There are no gridlines, titles on the axis&#8217; and no labels.</p>
<p>Well, you already know how to make text, so the titles and labels shouldn&#8217;t be a problem.  You do need to know how to make lines though:</p>
<p><code><br />
&lt;line x1="90" y1="1" x2="90" y2="900" stroke-width="5"  /&gt;<br />
</code><br />
The above code creates a line from point x<sub>1</sub>,y<sub>1</sub> to point x<sub>2</sub>,y<sub>2</sub> with a width of 5 points.  Now you know everything you need<br />
to know to create a good SVG graph.</p>
<h2>Your first PHP-generated SVG graph</h2>
<p><em>Well, now I know how to create an SVG image, but how do I create a dynamic image from PHP?</em></p>
<p>I&#8217;m glad you asked.  Well it is mostly just echoing the above information to the browser, but instead of outputing those 2 stagnant rectangles you should use a loop.  By looping through your data and generating a bar for every data point you can easily generate the graph you came here looking for.</p>
<p><code><br />
//These are our data points:<br />
$data = array( &quot;2003&quot; =&gt; 54, &quot;2004&quot; =&gt; 55, &quot;2005&quot; =&gt; 60);<br />
<span id="more-17"></span><br />
//Take the maximum value divided by the graph height:<br />
$divisor = 60 / 900;<br />
<!--more--><br />
//here we find the max size each bar should be to fit nicely<br />
//on the page:<br />
$bar_width = round( 1200 / count( $data ), 2 );<br />
<!--more--><br />
$x_loc = 1;<br />
<!--more--><br />
foreach( $data as $key =&gt; $value )<br />
{</p>
<p>&nbsp;&nbsp;  //The height for this data point's bar:<br />
&nbsp;&nbsp;  $bar_height = round( $value / $divisor, 2 );<br />
  <!--more--><br />
&nbsp;&nbsp;  //The starting point for this bar (the y-coordinate):<br />
&nbsp;&nbsp;  $y = ( 900 ) - $bar_height;<br />
  <!--more--><br />
&nbsp;&nbsp;  //The x,y coordinates for the vertical text on each bar:<br />
&nbsp;&nbsp;  $text_x = $x_loc + $bar_width - 10;<br />
&nbsp;&nbsp;  $text_y = 890;<br />
  <!--more--><br />
<!--more--><br />
&nbsp;&nbsp;  //This is the bar:<br />
&nbsp;&nbsp;  $svg .= &quot;&lt;rect x=\&quot;&quot;.$x_loc.&quot;\&quot; &nbsp;&nbsp;y=\&quot;&quot;.$y.&quot;\&quot; width=\&quot;&quot;.$bar_width.&quot;\&quot; &nbsp;&nbsp;height=\&quot;&quot;.$bar_height.&quot;\&quot; fill=\&quot;#eeffee\&quot; &nbsp;&nbsp;stroke=\&quot;black\&quot; stroke-width=\&quot;1\&quot; rx=\&quot;2\&quot;  &nbsp;&nbsp;/&gt;\n&quot;;<br />
  <!--more--><br />
&nbsp;&nbsp;  //Then the text on top of the bar.  We are rotating it -90 degrees which<br />
&nbsp;&nbsp;  //is really the same as 270 degrees, but with less numbers.  We are putting the<br />
&nbsp;&nbsp;  //x-axis label in normal text then putting the actual value next to it in<br />
&nbsp;&nbsp;  //a small blue font:<br />
&nbsp;&nbsp;  $svg .= &quot;&lt;g&gt;&lt;text x=\&quot;&quot;.($text_x).&quot;\&quot; &nbsp;&nbsp;y=\&quot;&quot;.($text_y).&quot;\&quot; font-size=\&quot;55\&quot; &nbsp;&nbsp;transform=\&quot;rotate(-90,$text_x,$text_y)\&quot; fill=\&quot;black\&quot; &nbsp;&nbsp;&gt;$key &lt;tspan font-size=\&quot;30\&quot; &nbsp;&nbsp;fill=\&quot;blue\&quot;&gt;($value)&lt;/tspan&gt;&lt;/text&gt;&lt;/g&gt;\n&quot;;<br />
 <!--more--><br />
&nbsp;&nbsp;  //Start the next bar at the end of this one:<br />
&nbsp;&nbsp;  $x_loc += $bar_width;<br />
<!--more--><br />
}<br />
    <!--more--><br />
echo $svg;<br />
</code></p>
<p>Now we are getting somewhere.  Just by changing the datapoints we can now have a completely different graph each time.  And there was much rejoicing.  <em>yeah.</em></p>
<h2>That&#8217;s great, but what about other graphs?</h2>
<p>Bar graphs aren&#8217;t going to work for you everytime, so you&#8217;ll probably need to expand your horizons to include line graphs and the dreaded pie graphs.  <em>*shudder*</em></p>
<p>They are done mostly the same way, only with more math and less sanity.  The sample page has examples of all three and the library has everything you need to do these on your own (and without having to write it yourself!).</p>
<p><em>&#8220;Just give me the dang code already!&#8221;</em>&#8230;.Okay fine.  Have it your way:<br />
<a href="http://techrageo.us/wp-content/code/20050622_php_svg/test_svg.php">Sample Generated Graphs (svg browsers only)</a><br />
<a href="http://techrageo.us/wp-content/code/php_svg.zip">Download the library and the sample code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2005/06/22/svg-graphs-with-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

