<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">

<channel>
<title>Hackszine: PHP</title>
<link>http://www.hackszine.com/blog/archive/php/</link>
<description>O&apos;Reilly&apos;s Hacks Series reclaims the term &apos;hacking&apos; for the good guys--innovators who explore and experiment, unearth shortcuts, create useful tools, and come up with fun things to try on their own</description>
<language>en-us</language>
<copyright>Copyright 2008, O'Reilly Media, Inc.</copyright>
<lastBuildDate>Tue, 09 Sep 2008 23:12:53 -0800</lastBuildDate>
<pubDate>Wed, 10 Sep 2008 22:12:47 -0800</pubDate>
<generator>http://www.movabletype.org/?v=4.1</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<itunes:author>O'Reilly Media, Inc.</itunes:author>
<itunes:subtitle>Clever solutions to interesting problems.</itunes:subtitle>
<itunes:summary>Hackszine Podcast</itunes:summary>
<itunes:owner>
<itunes:email>webmaster@makezine.com</itunes:email>
</itunes:owner>
<category>Technology</category>
<itunes:category text="Technology">
</itunes:category>
<itunes:category text="Technology">
  <itunes:category text="Gadgets" />
</itunes:category>
<itunes:category text="Games &amp; Hobbies" >
</itunes:category>
<itunes:category text="Science">
</itunes:category>
<itunes:image href="http://makezine.com/images/hackszine/rss_icon.jpg" />
<itunes:explicit>no</itunes:explicit>


<item>
<title>All AJAX image editor</title>
<itunes:summary> Nich sent us a link to his project, Dr. Pic, an all AJAX image editor. Without using any Flash, the application allows you to upload an image, do simple draw and filter operations, place text, crop, resize, and save...</itunes:summary>
<description>
<![CDATA[<p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="drpic_20080909.jpg" src="http://www.hackszine.com/drpic_20080909.jpg" width="600" height="376" class="mt-image-none" style="" /></span></p>

<p>Nich sent us a link to his project, Dr. Pic, an all AJAX image editor. Without using any Flash, the application allows you to upload an image, do simple draw and filter operations, place text, crop, resize, and save a finished copy. Javascript is used to draw preview material to the canvas, and then the user's commands are submitted back to a PHP backend which returns a new image to replace the previous version.</p>

<p>It doesn't pretend to be a Photoshop, but in a pinch it could come in handy as a quick tool for resizing or cropping an image. Aside from all that, it's a nice example of how you can leverage some server-side heavy lifting to support functionality that Javascript is lacking.</p>

<p><a href="http://www.drpic.com/">Dr. Pic - AJAX image editor</a></p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2008/09/all_ajax_image_editor.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2008/09/all_ajax_image_editor.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2008/09/all_ajax_image_editor.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2008/09/all_ajax_image_editor.html?CMP=OTC-7G2N43923558</guid>
<category>Ajax</category>
<pubDate>Tue, 09 Sep 2008 23:12:53 -0800</pubDate>

</item>

<item>
<title>Read Excel files in Perl and PHP</title>
<itunes:summary>Relational databases that speak SQL are the data-storage backbone for most developers. Unfortunately, but most of the data that&apos;s created outside the control of the technology caste at a typical workplace is in Excel format. Because of this, being able...</itunes:summary>
<description>
<![CDATA[<p>Relational databases that speak SQL are the data-storage backbone for most developers.  Unfortunately, but most of the data that's created outside the control of the technology caste at a typical workplace is in Excel format. Because of this, being able to procedurally read and write Excel documents with a familiar language can open up a whole world of possibilities for automation and data migration.</p>

<p>Assuming you're attempting to read and write standard text (Ie. not binary/graphic) data from Excel worksheets, this is actually fairly doable in PHP and Perl.</p>

<p>A recent article by Mike Diehl at Linux Journal peaked my interest in this. He shows off some of the features of the Spreadsheet::ParseExcel Perl module, which can be used to pull data and even formatting information from cells in an Excel worksheet.  Once you have your hands on the data, you can do what you want with it: output it to XML, toss it in a database for subsequent querying, or even convert it into other Excel documents (oh, the shame).</p>

<p><b>Perl Excel Libraries and Information</b><br />
<a href="http://search.cpan.org/~szabgab/Spreadsheet-ParseExcel-0.32/lib/Spreadsheet/ParseExcel.pm">Spreadsheet:ParseExcel - Read from Excel 95/97/2000 documents</a><br />
<a href="http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.24/lib/Spreadsheet/WriteExcel.pm">Spreadsheet:WriteExcel - Write to Excel 97/2000/2002/2003 documents</a><br />
<a href="http://www.linuxjournal.com/content/reading-native-excel-files-perl">Linux Journal - Reading Native Excel Files in Perl</a></p>

<p>There are libraries for dealing with native Excel files in PHP as well. The following two seem to be the only options for binary Excel documents.</p>

<p><b>PHP Excel Libraries</b><br />
<a href="http://sourceforge.net/projects/phpexcelreader/">PHP Excel_Reader - Read Excel 95 and 97 documents</a><br />
<a href="http://pear.php.net/package/Spreadsheet_Excel_Writer">Spreadsheet_Excel_Writer - Write Excel 5.0 documents</a><br />
<a href="http://devzone.zend.com/article/3336-Reading-and-Writing-Spreadsheets-with-php">Reading and Writing Spreadsheets with PHP</a></p>

<p>With the most recent version of Excel, there is an XML file format option that will allow you to read and write data in a worksheet by directly interacting with the saved file's DOM. IBM has a document that details doing this with PHP, and it would be straightforward to apply this technique to Perl as well.</p>

<p><a href="http://www.ibm.com/developerworks/xml/library/os-phpexcel/index.html">Read/Write XML Excel Data in PHP</a></p>

<p>Finally, if all you need to do is output a document that can be read in Excel, a standard CSV-format file will usually do the trick. Escaping can be a bit tricky, however, and my preferred format has become a plain-old HTML table. Just create a file that contains a TABLE element (no BODY or HTML tags necessary), with any number of TR rows and html-escaped data in the TDs, and save it out.  If you use the XLS file extension, it will open directly in Excel with a double-click and Excel never seems to mind reading in the data.</p>

<p>Do you have any other Excel programming hacks?  Give us a shout in the comments.</p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2008/09/read_excel_files_in_perl_and_p.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2008/09/read_excel_files_in_perl_and_p.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2008/09/read_excel_files_in_perl_and_p.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2008/09/read_excel_files_in_perl_and_p.html?CMP=OTC-7G2N43923558</guid>
<category>Excel</category>
<pubDate>Fri, 05 Sep 2008 20:23:43 -0800</pubDate>

</item>

<item>
<title>Asterisk File Transfer Protocol</title>
<itunes:summary>Cory Menscher writes: As part of the NYU ITP &quot;5in5&quot; event this week, I created the Asterisk File Transfer Protocol. Using the CSound audio programming language, I wrote a PHP script that converts a binary file into an audio WAV...</itunes:summary>
<description>
<![CDATA[<p><a href="http://www.crackblur.com/">Cory Menscher</a> writes:<br />
<blockquote><br />
As part of the <a href="http://www.5-in-5.com">NYU ITP "5in5" event</a> this week, I created the Asterisk File Transfer Protocol.  Using the CSound audio programming language, I wrote a PHP script that converts a binary file into an audio WAV file based on the "Kansas City standard", created in 1975, for transferring binary files via audio cassette.  However, instead of a cassette, a user can dial my extension on an Asterisk VoIP PBX server and "retrieve" a file (an 8kb jpeg image) at 300 baud over POTS.  You can access the file by dialing (212) 796-0729 ext. 160.</p>

<p><br />
In reality, the audio quality of the GSM codec I was limited to by the server probably precludes one from ACTUALLY downloading the file, but it's still fun!  If you want to hear a higher-fidelity version of the file you can access it at <a href="http://www.menscher.com/itp/blogmedia/aftp.mp3">http://www.menscher.com/itp/blogmedia/aftp.mp3</a>.<br />
</blockquote></p>

<p>Corey posted the source he used to generate the encoded WAV from an image, so you can see the nuts and bolts of using CSound to generate audio data in PHP. It'd be neat to see the decoder half of this, but it's been left as an exercise for the reader.</p>

<p>I have fond memories of saving and loading files from a C64 datasette drive like this, so it's pretty cool to see this sort of thing done in PHP.  </p>

<p><a href="http://5-in-5.com/2008/07/30/the-asterisk-file-transfer-protocol/">The Asterisk File Transfer Protocol</a></p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2008/07/asterisk_file_transfer_protoco.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2008/07/asterisk_file_transfer_protoco.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2008/07/asterisk_file_transfer_protoco.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2008/07/asterisk_file_transfer_protoco.html?CMP=OTC-7G2N43923558</guid>
<category>PHP</category>
<pubDate>Wed, 30 Jul 2008 23:25:03 -0800</pubDate>
<enclosure url="http://www.menscher.com/itp/blogmedia/aftp.mp3" length="2516762" type="audio/mpeg" />
</item>

<item>
<title>Server-side Google Analytics</title>
<itunes:summary>Peter van der Graaf did a little analysis of the URLs that are generated by the Google Analytics Javascript API and put together a very useful tutorial for building Analytics-enabled applications without the use of Javascript. When you look at...</itunes:summary>
<description>
<![CDATA[<p>Peter van der Graaf did a little analysis of the URLs that are generated by the Google Analytics Javascript API and put together a very useful tutorial for building Analytics-enabled applications without the use of Javascript.</p>

<blockquote>When you look at the analytics javascript code you see that it combines several sets of data into an image request. This image request sends the right data to Google (not the javascript). When you know what url you should use for the image, you can call the image directly and send the same data. Of course you need to be able to request the image url and that isn't easy from another image, rss feed or pdf. This is why we request it "server side".</blockquote>

<p>You can add the code to the PHP that drives a blog site, for instance, and generate page views when your RSS feed is hit.  You can even write a very simple script to proxy images and downloads, which will let you track hit data for all files on your site, not just the html pages viewed by a javascript enabled browser.</p>

<p>Taken a step further, you could even use this on the client side, triggering analytics views from standalone Flash apps or even desktop applications.</p>

<p>The one thing you need to keep in mind is that server-side analytics requests will appear to come from your server, not the client's machine. So while you can track page views and download events this way, you'll loose a lot of the information about your user base.  Because of this, it would probably make sense to use a separate tracking ID for the server side events.</p>

<p><a href="http://www.vdgraaf.info/google-analytics-without-javascript.html">Google Analytics Without Javascript</a> </p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2008/05/serverside_google_analytics.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2008/05/serverside_google_analytics.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2008/05/serverside_google_analytics.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2008/05/serverside_google_analytics.html?CMP=OTC-7G2N43923558</guid>
<category>Google</category>
<pubDate>Thu, 01 May 2008 20:27:10 -0800</pubDate>

</item>

<item>
<title>Stop XSS attacks with SafeHTML</title>
<itunes:summary>If you allow user-contributed content in your site, you run into the problem of dealing with user supplied HTML in a safe manner. The most secure way of dealing with things, of course, is to strip or escape all HTML...</itunes:summary>
<description>
<![CDATA[<p>If you allow user-contributed content in your site, you run into the problem of dealing with user supplied HTML in a safe manner.  The most secure way of dealing with things, of course, is to strip or escape all HTML from user input fields. Unfortunately, there are many situations where it would be nice to allow a large subset of HTML input, but block out anything potentially dangerous.</p>

<p>SafeHTML is a lightweight PHP user input sanitizer that does just that. Just run any input field through the SafeHTML filter and any javascript, object tags, or layout breaking tags will be stripped from the supplied text. It also does a reasonable job of correcting any gnarly, malformed code, which is also a common problem with user-contributed data.</p>

<p>Using it is easy. Just instantiate the SafeHTML object and call its parse method:</p>

<blockquote><code>
require_once('classes/safehtml.php');

<p>$safehtml =& new SafeHTML();</p>

<p>if ( isset( $_POST["inputfield"] ) ) <br />
{<br />
&nbsp;&nbsp;$inputfield=$_POST["inputfield"];<br />
&nbsp;&nbsp;$cleaninput = $safehtml-&gt;parse($inputfield);<br />
}<br />
</code></blockquote></p>

<p>This will take the posted "inputfield" parameter, strip any baddies, XHTMLify what's left, and the result will be stored in the $cleaninput variable. It's a simple addition to your code, and a lot more straightforward than trying to roll your own.</p>

<p>My only beef with the package is that it's written with a default allow policy, stripping out tags that are in its deleteTags array, but essentially allowing anything else through.  If you'd rather only let through tags that you specifically want to allow, I'd recommend adding an allowTags array and adjusting the _openHandler method, adding the following after the deleteTags check:</p>

<blockquote><code>

<p>if ( ! in_array($name, $this-&gt;allowTags)) {<br />
&nbsp;&nbsp;return true;<br />
}</p>

<p></code></blockquote></p>

<p>You'll need to fill allowTags with everything you know to be safe and welcome, and you may miss a few that people will end up wanting to legitimately use, but this is easily corrected and the default deny policy is much safer in the long run.</p>

<p><a href="http://pixel-apes.com/safehtml/">SafeHTML - an anti-XSS HTML parser, written in PHP</a></p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2008/04/stop_xss_attacks_with_safehtml.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2008/04/stop_xss_attacks_with_safehtml.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2008/04/stop_xss_attacks_with_safehtml.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2008/04/stop_xss_attacks_with_safehtml.html?CMP=OTC-7G2N43923558</guid>
<category>Network Security</category>
<pubDate>Tue, 29 Apr 2008 20:49:15 -0800</pubDate>

</item>

<item>
<title>Telekinesis - remote control your Mac with an iPhone</title>
<itunes:summary> Telekinesis is a bundle of small web apps that you can run on your Mac to give the iPhone remote control. You can use it to stream media files to your iPhone, run scripts remotely, and capture images with...</itunes:summary>
<description>
<![CDATA[<p><img alt="telekinesis_20070706.jpg" src="http://hackszine.com/telekinesis_20070706.jpg" width="500" height="350" /></p>

<p>Telekinesis is a bundle of small web apps that you can run on your Mac to give the iPhone remote control.  You can use it to stream media files to your iPhone, run scripts remotely, and capture images with the iSight.</p>

<p>You can also add your own features by dropping custom PHP applications beneath the Application Support library folder.</p>

<p>Telekinesis Project - <a href="http://code.google.com/p/telekinesis/">Link</a><br />
Create apps for Telekinesis - <a href="http://code.google.com/p/telekinesis/wiki/CreatingApplications">Link</a></p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2007/07/telekinesis_remote_control_you.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2007/07/telekinesis_remote_control_you.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2007/07/telekinesis_remote_control_you.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2007/07/telekinesis_remote_control_you.html?CMP=OTC-7G2N43923558</guid>
<category>iPhone</category>
<pubDate>Fri, 06 Jul 2007 20:19:55 -0800</pubDate>

</item>

<item>
<title>Update Facebook status with PHP and cURL</title>
<itunes:summary>Christian Flickinger wanted to be able to sync status updates between his Twitter and Facebook accounts, so that when his status is updated on Twitter, his Facebook status is automatically updated at the same time. Unfortunately, Facebook didn&apos;t have an...</itunes:summary>
<description>
<![CDATA[<p>Christian Flickinger wanted to be able to sync status updates between his Twitter and Facebook accounts, so that when his status is updated on Twitter, his Facebook status is automatically updated at the same time.  Unfortunately, Facebook didn't have an API for setting status, so Christian decided to hack his own using PHP and cURL.</p>

<p>With a few lines of code, his script will authenticate with Facebook account and update its status.  It's a simple script you can incorporate into your own project to sync your status to anything - <a href="http://www.nexdot.net/blog/2007/04/20/updating-facebook-status-using-php/">Link.</a></p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2007/06/update_facebook_status_with_ph.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2007/06/update_facebook_status_with_ph.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2007/06/update_facebook_status_with_ph.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2007/06/update_facebook_status_with_ph.html?CMP=OTC-7G2N43923558</guid>
<category>PHP</category>
<pubDate>Sat, 02 Jun 2007 22:55:49 -0800</pubDate>

</item>

<item>
<title>Faster PHP: Profile Your Scripts With Xdebug</title>
<itunes:summary> Xdebug is a powerful PHP extension that can help you track down bottlenecks in your PHP code. From the Xdebug profiling howto: The profiler in Xdebug 2 outputs profiling information in the form of a cachegrind compatible file. This...</itunes:summary>
<description>
<![CDATA[<p><img alt="kcachegrind_20070423.jpg" src="http://hackszine.com/kcachegrind_20070423.jpg" width="500" height="539" /><br />
Xdebug is a powerful PHP extension that can help you track down bottlenecks in your PHP code.  From the <a href="http://xdebug.org/docs-profiling2.php">Xdebug profiling howto</a>:</p>

<blockquote>The profiler in Xdebug 2 outputs profiling information in the form of a cachegrind compatible file. This allows you to use the excellent KCacheGrind tool (Linux, KDE) to analyse your profiling data. Users of the Windows operating system can use WinCacheGrind.</blockquote>

<p>Shown above is a screenshot of KCacheGrind, which is showing that the particular script is devoting a lot of its time to mysql_query calls.  Once you know where your code is chewing up cycles, you'll have a better idea of where to focus any optimization efforts, either by cleaning up ineffecient code and database queries, or by employing a suitable caching strategy.</p>

<p>Faster PHP Apps--Profile Your Code with Xdebug - <a href="http://www.sitepoint.com/blogs/2007/04/23/faster-php-apps-profile-your-code-with-xdebug/">Link.</a></p>

<p><b>Resources:</b><br />
<ul><li><a href="http://xdebug.org/">Xdebug</a></li><li><a href="http://kcachegrind.sourceforge.net/">KCacheGrind</a> - analysis tool for KDE</li><li><a href="http://sourceforge.net/projects/wincachegrind/">WinCacheGrind</a> analysis tool for Windows</li><li><a href="http://xdebug.org/docs-profiling2.php">How to use Xdebug's profiling tools with KCacheGrind</a></li></ul></p>]]>
[&lt;a href="http://www.hackszine.com/blog/archive/2007/04/faster_php_profile_your_script.html?CMP=OTC-7G2N43923558" /&gt;Read More&lt;/a&gt;]  
[&lt;a href="http://www.hackszine.com/blog/archive/2007/04/faster_php_profile_your_script.html?CMP=OTC-7G2N43923558#comments" /&gt;Comments&lt;/a&gt;]
</description>
<link>http://www.hackszine.com/blog/archive/2007/04/faster_php_profile_your_script.html?CMP=OTC-7G2N43923558</link>
<guid>http://www.hackszine.com/blog/archive/2007/04/faster_php_profile_your_script.html?CMP=OTC-7G2N43923558</guid>
<category>PHP</category>
<pubDate>Mon, 23 Apr 2007 20:04:20 -0800</pubDate>

</item>


</channel>
</rss>