<?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>Compdigitec Labs &#187; PHP</title>
	<atom:link href="http://www.compdigitec.com/labs/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.compdigitec.com/labs</link>
	<description>The place for interesting things</description>
	<lastBuildDate>Sun, 05 Feb 2012 03:44:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Adding custom profile fields in WordPress (fully automatic)</title>
		<link>http://www.compdigitec.com/labs/2011/10/17/adding-custom-profile-fields-in-wordpress-fully-automatic/</link>
		<comments>http://www.compdigitec.com/labs/2011/10/17/adding-custom-profile-fields-in-wordpress-fully-automatic/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 01:22:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[custom fields]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=241</guid>
		<description><![CDATA[Custom profile fields are additional custom-defined fields in the WordPress usermeta database that permit us to store additional information about a user. To add custom profile fields, add the following line to your functions.php in your theme folder: Now create a new file called customfields.php in the theme folder (the same folder as function.php) with [...]]]></description>
			<content:encoded><![CDATA[<p>Custom profile fields are additional custom-defined fields in the WordPress usermeta database that permit us to store additional information about a user. To add custom profile fields, add the following line to your functions.php in your theme folder:</p>
<pre class="brush: php; title: ; notranslate">include('customfields.php');</pre>
<p>Now create a new file called <strong>customfields.php</strong> in the theme folder (the same folder as function.php) with the following contents:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

function get_extra_profile_list() {
return Array(
/* Add your custom fields, here like follows:
'slug_of_the_field_here' =&gt; 'Field name for display',
 */
'address' =&gt; 'Address',
'favouritecolour' =&gt; 'Favourite Colour'
);
}

add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );

function extra_user_profile_fields( $user ) { ?&gt;
&lt;h3&gt;&lt;?php _e(&quot;Extra profile information&quot;, &quot;blank&quot;); ?&gt;&lt;/h3&gt;

&lt;table class=&quot;form-table&quot;&gt;
&lt;?php
foreach(get_extra_profile_list() as $key =&gt; $value) {
?&gt;
&lt;tr&gt;
&lt;th&gt;&lt;label for=&quot;&lt;?php echo $key; ?&gt;&quot;&gt;&lt;?php _e($value); ?&gt;&lt;/label&gt;&lt;/th&gt;
&lt;td&gt;
&lt;input type=&quot;text&quot; name=&quot;&lt;?php echo $key; ?&gt;&quot; id=&quot;&lt;?php echo $key; ?&gt;&quot; value=&quot;&lt;?php echo esc_attr( get_the_author_meta( $key, $user-&gt;ID ) ); ?&gt;&quot; class=&quot;regular-text&quot; /&gt;&lt;br /&gt;
&lt;span class=&quot;description&quot;&gt;&lt;?php _e(&quot;Please enter your $value.&quot;); ?&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;?php
}
?&gt;
&lt;/table&gt;
&lt;?php }

add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );

function save_extra_user_profile_fields( $user_id ) {

if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }

foreach(get_extra_profile_list() as $key =&gt; $value) {
update_usermeta( $user_id, $key, $_POST[$key] );
}
}
?&gt;
</pre>
<p>Now if you go to &#8220;Users&#8221; under your administration and edit a user, the additional profile fields will show up at the bottom of the edit page.</p>
<p><a href="http://www.compdigitec.com/labs/wp-content/uploads/2011/10/extraprofile.png"><img class="aligncenter size-full wp-image-242" title="Extra Profile Fields in WordPress" src="http://www.compdigitec.com/labs/wp-content/uploads/2011/10/extraprofile.png" alt="" width="619" height="102" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2011/10/17/adding-custom-profile-fields-in-wordpress-fully-automatic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WP No-bot Question plugin for WordPress</title>
		<link>http://www.compdigitec.com/labs/2011/10/09/wp-no-bot-question-plugin-for-wordpress/</link>
		<comments>http://www.compdigitec.com/labs/2011/10/09/wp-no-bot-question-plugin-for-wordpress/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 01:46:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=238</guid>
		<description><![CDATA[Most spam on your WordPress blog is caused by automated robots (spambots) which keep submitting to your comment form to inflate some shady website&#8217;s rank. Short of completely disabling or turning on blog moderation and wasting your time filtering through the mess, you can now use the new WP No-bot Question plugin developed by Compdigitec [...]]]></description>
			<content:encoded><![CDATA[<p>Most spam on your WordPress blog is caused by automated robots (spambots) which keep submitting to your comment form to inflate some shady website&#8217;s rank. Short of completely disabling or turning on blog moderation and wasting your time filtering through the mess, you can now use the new <strong><a href="http://www.compdigitec.com/apps/wpnobot/">WP No-bot Question plugin</a></strong> developed by Compdigitec for WordPress - simply activate, set your question and answers and block all the spam bots! Best used in conjunction with other spam and server protection plugins such as <a href="http://www.svenkubiak.de/nospamnx-en">NoSpamNX</a> and <a href="http://www.bad-behavior.ioerror.us/">Bad Behaviour</a>. This plugin was inspired by the <a href="http://www.phpbb.com/community/viewtopic.php?f=70&amp;t=568673">Anti-Bot Question Mod for phpBB</a>, which is very effective against spambot user registration on phpBB.</p>
<p>See the <a href="http://www.compdigitec.com/apps/wpnobot/">plugin page</a> on Compdigitec for more details and screenshots/downloads.</p>
<p><a href="http://www.compdigitec.com/apps/wpnobot/screenshot1.png"><img class="alignnone" title="WP No-Bot Question" src="http://www.compdigitec.com/apps/wpnobot/screenshot1.png" alt="" width="680" height="272" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2011/10/09/wp-no-bot-question-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging comments on old posts in WordPress</title>
		<link>http://www.compdigitec.com/labs/2011/03/07/debugging-comments-on-old-posts-in-wordpress/</link>
		<comments>http://www.compdigitec.com/labs/2011/03/07/debugging-comments-on-old-posts-in-wordpress/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 01:00:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[old posts]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=215</guid>
		<description><![CDATA[Sometimes on a WordPress blog all comment entry points on old blog posts will stop working. This can be caused by a number of problems: Posts are set to expire. If you select the option &#8220;Automatically close comments on articles older than x days&#8221; under Settings-&#62;Discussion, then posts will automatically close comments after x days. [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes on a WordPress blog all comment entry points on old blog posts will stop working. This can be caused by a number of problems:</p>
<ol>
<li><strong>Posts are set to expire.</strong> If you select the option &#8220;Automatically close comments on articles older than x days&#8221; under<strong> Settings-&gt;Discussion</strong>, then posts will automatically close comments after x days.</li>
<li><strong>Your blog is not set to enable commenting.</strong> Enable &#8220;Allow people to post comments on new articles&#8221; under <strong>Settings-&gt;Discussion</strong>.</li>
<li><strong>The specific post is not allowing comments.</strong> Edit the post in question and under the &#8220;Discussion&#8221; section ensure both &#8220;Allow comments&#8221; and &#8220;Allow trackbacks and pingbacks on this page&#8221; are both selected.</li>
</ol>
<p>If the above three steps still do not help, then you can run the following database queries to enable comments globally:</p>
<pre class="brush: sql; title: ; notranslate">UPDATE wp_posts SET comment_status = REPLACE (comment_status, 'closed', 'open') WHERE post_status = 'publish' AND post_type = 'post';</pre>
<pre class="brush: sql; title: ; notranslate">UPDATE wp_options SET option_value = 0 WHERE option_name = 'close_comments_for_old_posts'</pre>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2011/03/07/debugging-comments-on-old-posts-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting the direct link of a SkyDrive file transparently using PHP</title>
		<link>http://www.compdigitec.com/labs/2011/01/31/getting-the-direct-link-of-a-skydrive-file-transparently-using-php/</link>
		<comments>http://www.compdigitec.com/labs/2011/01/31/getting-the-direct-link-of-a-skydrive-file-transparently-using-php/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 02:02:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[direct link]]></category>
		<category><![CDATA[skydrive]]></category>
		<category><![CDATA[windows live]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=208</guid>
		<description><![CDATA[Windows Live SkyDrive is one of the best online storage/file hosting solutions available online. It provides you with 25 GBs of free storage associated with your Windows Live ID, and allows you to upload as many files as you want to it. However, Windows Live SkyDrive&#8217;s direct links are not stable for more than a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://skydrive.live.com/">Windows Live SkyDrive</a> is one of the best online storage/file hosting solutions available online. It provides you with 25 GBs of free storage associated with your Windows Live ID, and allows you to upload as many files as you want to it. However, Windows Live SkyDrive&#8217;s direct links are not stable for more than a day, unlike Google Docs where the direct link is stable and permanent. Here is a PHP function that can be used to obtain the direct link of a SkyDrive file using the public URL of the file.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/*
 *      (C) Copyright 2011 Compdigitec. All rights reserved.
 *      Redistribution and use in source and binary forms, with or without
 *      modification, are permitted provided that the following conditions are
 *      met:
 *
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with the
 *        distribution.
 *      * Neither the name of the Compdigitec nor the names of its
 *        contributors may be used to endorse or promote products derived from
 *        this software without specific prior written permission.
 *
 *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *      &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *      LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *      A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *      OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *      SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *      LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *      DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *      THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *      OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * Gets the direct link of a URL with a given public Skydrive URL
 * @param string $liveurl The public SkyDrive URL
 * @return string|false The direct URL of the skydrive or false if error
 */
function get_skydrive_direct_link($liveurl) {
	$file = file_get_contents($liveurl);

	// find file loc
	$pos = strpos($file,'&lt;a id=&quot;spPreviewLink&quot; href=&quot;');
	if($pos === false) return false;
	$pos += strlen('&lt;a id=&quot;spPreviewLink&quot; href=&quot;');

	$buffer = &quot;&quot;;
	while(substr($file,$pos,1) != '&quot;') {
		$buffer .= substr($file,$pos,1);
		$pos++;
	}

	$buffer = html_entity_decode($buffer);

	$directlink = substr($buffer,0,strlen($buffer)-7);

	$host = parse_url($directlink,PHP_URL_HOST);
	if(strpos($host,&quot;livefilestore.com&quot;) === false) {
		return false;
	}
	return $directlink;
}
?&gt;
</pre>
<p>To use this function, feed it the public URL and it will return the direct link of the file:</p>
<pre class="brush: php; title: ; notranslate">
$direct = get_skydrive_direct_link(&quot;http://cid-abcdef1234567890.office.live.com/self.aspx/FolderName/FileName.exe&quot;);
// Returns something like http://public.bay.livefilestore.com/y1pZwjyu-qfXUWjM-si2IeNs-juO0PjZE-Sk5EVvZxgeenjCxxv9vHiUy8q1RGafKnbaGSC2alqAoIbDvAYegznaZ/FileName.exe
$not_direct = get_skydrive_direct_link(&quot;http://not.skydrive.example.com/not/a/skydrive/FileName.exe&quot;);
// Returns FALSE (if it is not a SkyDrive upload)
</pre>
<p>You can use this script as part of an independent web service or as part of your existing PHP application under the BSD license. There is a <a href="http://test.compdigitec.com/skydrive/">link generator on this website</a> available that you can use to try it out or use with your application without needing the script to be installed.</p>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2011/01/31/getting-the-direct-link-of-a-skydrive-file-transparently-using-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Reverse proxy (X-Forwarded-For) patches for WordPress comments and Bad Behaviour</title>
		<link>http://www.compdigitec.com/labs/2010/10/30/reverse-proxy-x-forwarded-for-patches-for-wordpress-comments-and-bad-behaviour/</link>
		<comments>http://www.compdigitec.com/labs/2010/10/30/reverse-proxy-x-forwarded-for-patches-for-wordpress-comments-and-bad-behaviour/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 18:49:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTTP (Internet)]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[bad behaviour]]></category>
		<category><![CDATA[forwarding]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[php reverse proxy]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[x-forwarded-for]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=192</guid>
		<description><![CDATA[Update: Reverse proxy support is now built into Bad Behaviour as of 2.1.x. Therefore the following patch is obsolete and should only be applied to Bad Behaviour 2.0.x. You can configure the built-in reverse proxy either through your settings.ini or in WordPress administration. Normally, when PHP scripts access the remote IP of a client through [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: </strong>Reverse proxy support is now built into Bad Behaviour as of 2.1.x. Therefore the following patch is obsolete and should only be applied to Bad Behaviour 2.0.x. You can configure the built-in reverse proxy either through your settings.ini or in WordPress administration.</p>
<p>Normally, when PHP scripts access the remote IP of a client through <strong>REMOTE_ADDR</strong>, it can only access the IP of the last client. Under most web hosting conditions this is perfectly normal, but in some corporate networks there is a reverse name-based proxy used to serve multiple servers through one IP. However, this messes up many scripts because to them it appears that all traffic is coming through one Intranet address, and this also messes up many spam protection filters because it appears to be an internal address.</p>
<p>Most proxy servers send the <strong>X-Forwarded-For</strong> header when contains the real IP that it is forwarding, but this cannot always be trusted, especially if your server is open both inside and outside the intranet. This means that when getting the real IP address, one must be careful that the request is coming from a trusted proxy server and not from a rouge spammer.</p>
<p>Since most scripts are not programmed by default to provide this kind of functionality, we have written a patch for <a href="http://wordpress.org/">WordPress</a> 2.9 and <a href="http://www.bad-behavior.ioerror.us/">Bad Behvaiour</a> 2.0.38. However, this is not an efficient or elegant way to perform this kind of functionality, and instead recommend that Apache (or whatever your web server is) automatically rewrite REMOTE_ADDR instead. This way no unofficial patching is required, and it is compatible with more scripts.</p>
<p><strong>For WordPress 2.9:</strong></p>
<p>Open &lt;blog path&gt;/wp-includes/comment.php and scroll to line 1199, which reads &#8220;<strong>$commentdata['comment_author_IP'] = preg_replace( &#8216;/[^0-9a-fA-F:., ]/&#8217;, &#8221;,$_SERVER['REMOTE_ADDR'] );</strong>&#8220;.</p>
<p>Now add the following code to it (replacing 111.222.233.144 with your trusted proxy server IP):</p>
<pre class="brush: php; title: ; notranslate">
/** Begin X-Forwarded-For Patch **/
$headers = getallheaders();
if(isset($headers[&quot;X-Forwarded-For&quot;])) {
	// forwarded proxy
	if($_SERVER['REMOTE_ADDR'] == &quot;111.222.233.144&quot;) {
		// this is a trusted gateway
		$xff = $headers[&quot;X-Forwarded-For&quot;];
		$xff_array = explode(&quot;,&quot;,$xff);
		$last_forwarded_host = trim($xff_array[count($xff_array)-1]);
		// remove port number, if needed
		if(strpos($last_forwarded_host,&quot;:&quot;) !== false) {
			$lfh_array = explode(&quot;:&quot;,$last_forwarded_host);
			unset($lfh_array[count($lfh_array)-1]);
			$last_forwarded_host = implode(&quot;:&quot;,$lfh_array);
		}
		// set real client IP as IP
		$commentdata['comment_author_IP'] = $last_forwarded_host;
	}
}
/** End X-Forwarded For Patch **/
</pre>
<p>Now comments should be attributed to their source IPs in the Comment administration panel.</p>
<p><strong>For Bad Behaviour 2.0.38:</strong></p>
<p>Open &lt;bad behaviour path&gt;/bad-behavior/core.inc.php to line 116 (<strong>$ip = $_SERVER['REMOTE_ADDR']</strong>).</p>
<p>Now add the following lines after a newline (replace 111.222.233.144 with your gateway IP):</p>
<pre class="brush: php; title: ; notranslate">
/** Begin X-Forwarded-For Patch **/
if(isset($headers[&quot;X-Forwarded-For&quot;])) {
	// forwarded proxy
	if($ip == &quot;111.222.233.144&quot;) {
		// this is a trusted gateway
		$xff = $headers[&quot;X-Forwarded-For&quot;];
		$xff_array = explode(&quot;,&quot;,$xff);
		$last_forwarded_host = trim($xff_array[count($xff_array)-1]);
		// remove port number, if needed
		if(strpos($last_forwarded_host,&quot;:&quot;) !== false) {
			$lfh_array = explode(&quot;:&quot;,$last_forwarded_host);
			unset($lfh_array[count($lfh_array)-1]);
			$last_forwarded_host = implode(&quot;:&quot;,$lfh_array);
		}
		// set real client IP as IP
		$ip = $last_forwarded_host;
		unset($headers[&quot;X-Forwarded-For&quot;]);
		unset($headers_mixed[&quot;X-Forwarded-For&quot;]);
	}
}
/** End X-Forwarded For Patch **/
</pre>
<p>Now Bad Behaviour will start functioning again, as by default any Intranet address is whitelisted by default.</p>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2010/10/30/reverse-proxy-x-forwarded-for-patches-for-wordpress-comments-and-bad-behaviour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated Roadsend PHP Compiler 2.9.8 packages</title>
		<link>http://www.compdigitec.com/labs/2010/07/21/updated-roadsend-php-compiler-packages/</link>
		<comments>http://www.compdigitec.com/labs/2010/07/21/updated-roadsend-php-compiler-packages/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 00:48:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[.deb]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[roadsend]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=179</guid>
		<description><![CDATA[Due to the vast interest in our previous binary package of Roadsend PHP, we have decided to compile a newer, updated version of the Roadsend PHP compiler (v2.9.8). However, due to previous flaws in the way that we compiled the previous PHP compile, many of our readers struggled or were entirely unable to get the [...]]]></description>
			<content:encoded><![CDATA[<p>Due to the vast interest in our previous <a href="/labs/2008/07/24/install-roadsend-php-compiler-on-ubuntu-without-compiling-anything/">binary package of Roadsend PHP</a>, we have decided to compile a newer, updated version of the Roadsend PHP compiler (v2.9.8). However, due to previous flaws in the way that we compiled the previous PHP compile, many of our readers struggled or were entirely unable to get the compiler installed. As a result, Compdigitec is compiling new, fresh packages to target Ubuntu 9.10 and will make it easier to run Roadsend PHP on your Ubuntu Linux computer.</p>
<p><strong>Prerequisites</strong></p>
<ul>
<li>Uninstall any old versions of Roadsend PHP and bigloo on your computer.</li>
<li>Install the packages libgtk2.0-0, libpcre3, libfcgi, libmysqlclient15off and libsqlite3-0 like such:
<pre class="brush: bash; title: ; notranslate">sudo apt-get install libgtk2.0-0 libpcre3 libfcgi libmysqlclient15off libsqlite3-0
</pre>
</li>
<li>Install <a href="/labs/files/bigloo-compdigitec-unoffical.deb">unofficial bigloo</a> and set up the bigloo symlink like such:
<pre class="brush: bash; title: ; notranslate">sudo ln -s / /z</pre>
</li>
</ul>
<p><strong>Procedure</strong></p>
<ol>
<li>Download and install the Roadsend PHP binary package:
<ul>
<li><a title="roadsend-php-unofficial.deb" href="/labs/files/roadsend-php-unofficial.deb">roadsend-php-unofficial.deb</a> (4.8 MB)</li>
</ul>
<p>Note that the Roadsend PHP debugger (pdb) has been renamed to (roadsend-pdb) due to naming conflict with python.</li>
<li>Create a test PHP file with the following content, and save it as <strong>hello.php</strong>:
<pre class="brush: php; title: ; notranslate">
&lt;?php

// Roadsend PHP testing program
$words = Array(&quot;Hello&quot;, &quot;World&quot;, &quot;from&quot;, &quot;Roadsend PHP!&quot;);
$sentence = implode(&quot; &quot;,$words);
echo $sentence . &quot;\n&quot;;
exit(0);

?&gt;</pre>
</li>
<li>Run:
<pre class="brush: bash; title: ; notranslate">pcc hello.php</pre>
<p>to generate a <em>hello</em> executable. Test this executable by running:</p>
<pre class="brush: bash; title: ; notranslate">./hello</pre>
<p>The output of the program should read:</p>
<pre class="brush: plain; title: ; notranslate">Hello World from Roadsend PHP!</pre>
</li>
<li>Now we will test the MicroServer backend, which is a small embedded webserver that allows you to turn your PHP application into a stand-alone webserver:
<pre class="brush: bash; title: ; notranslate">pcc -s hello-server --port 44444 hello.php</pre>
<p>to generate the <em>hello-server</em> webserver. Now, we will try to visit the MicroServer:</p>
<pre class="brush: bash; title: ; notranslate">./hello-server</pre>
<p>The server should be up and running by this point. Now point your browser at <a href="http://127.0.0.1:44444/hello.php">http://127.0.0.1:44444/hello.php</a> and watch your PHP turn itself into a webserver without Apache.</li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2010/07/21/updated-roadsend-php-compiler-packages/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Solving &#8220;Fatal error: Exception thrown without a stack frame in Unknown on line 0&#8243;</title>
		<link>http://www.compdigitec.com/labs/2009/08/02/solving-fatal-error-exception-thrown-without-a-stack-frame-in-unknown-on-line-0/</link>
		<comments>http://www.compdigitec.com/labs/2009/08/02/solving-fatal-error-exception-thrown-without-a-stack-frame-in-unknown-on-line-0/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 19:54:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[destructor]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[no stack frame]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php error]]></category>
		<category><![CDATA[php oop]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[without stack frame]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=119</guid>
		<description><![CDATA[If you attempt to throw an exception from a PHP destructor or an PHP exception handler, your script will execute fine for the most part and then crash with the rather cryptic error message, &#8220;Fatal error: Exception thrown without a stack frame in Unknown on line 0&#8220;. This message is unfortunately very cryptic if you [...]]]></description>
			<content:encoded><![CDATA[<p>If you attempt to throw an exception from a PHP destructor or an PHP exception handler, your script will execute fine for the most part and then crash with the rather cryptic error message, &#8220;<strong>Fatal error: Exception thrown without a stack frame in Unknown on line 0</strong>&#8220;. This message is unfortunately very cryptic if you are trying to debug your code. This effect is further amplified due to a lack of PHP debuggers and you must instead resort to using various print_r()s and var_dump()s in order to debug the program. The error message in basic form means that you&#8217;ve thrown an exception where an exception cannot be thrown (leading to &#8220;no stack frame&#8221; - exception handlers and destructors <em>do not have a stack frame</em>. This instead results in this rather cryptic error message that does not include script locations or detailed error information).</p>
<p>Most often, the error will appear if you use an exception handler combined with an error reporting to exception handler by converting it to an <a href="http://us3.php.net/manual/en/errorexception.construct.php">ErrorException</a>, then there a suddenly a whole new magnitude of ways to throw errors within the exception handle, especially if E_NOTICE, E_STRICT and/or E_WARNING errors are converted. This form most often occurs when you use variables without first initializing them. This error may be preventable by wrapping the exception handler within a try/catch block.</p>
<p>A second form of this error occurs when you attempt to throw an exception in a destructor. This is well documented in the <a href="http://php.net/__destruct">PHP manual</a>, but this can still be triggered if you accidentally throw an exception:</p>
<ul>
<li><strong>Manually</strong> - calling &#8220;throw new Exception(&#8216;hello world&#8217;)&#8217; in a destructor</li>
<li><strong>Implicitly</strong> - calling a function that throws an exception (e.g. calling function foo() which throws an exception)</li>
<li><strong>Error handler (ErrorException)</strong> - instating a user-defined function as an error handler which throws an ErrorException (which is still an error)</li>
</ul>
<p>There is no exactly solid way to identify this type of error as you may not know exactly what your functions do. If you are throwing exceptions manually in your destructor, you need to go back to the PHP manually and read that it is not possible to throw exceptions within the destructor (as it lacks a stack frame). For the other two, you may need to comment out your destructors and manually uncomment parts until you reach the point where you find the error line as the error message produced by PHP is not too informative.</p>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2009/08/02/solving-fatal-error-exception-thrown-without-a-stack-frame-in-unknown-on-line-0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple Template Engine - your lightweight templating engine in PHP</title>
		<link>http://www.compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/</link>
		<comments>http://www.compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 01:30:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[simple template engine]]></category>
		<category><![CDATA[stl]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[templating]]></category>
		<category><![CDATA[tpl]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=69</guid>
		<description><![CDATA[The Simple Template Engine is a very lightweight template engine to use in PHP if your webhost does not allow you to run something like Smarty. It is simple, lightweight and fast. To parse a file: example.tpl is: &#60;html&#62;&#60;head&#62;&#60;title&#62;{content}&#60;/title&#62;&#60;/head&#62;&#60;body&#62;&#60;h1&#62;{content}&#60;/h1&#62;&#60;/body&#62;&#60;/html&#62; If you found this article useful or helpful, please help Compdigitec spread the word. Don&#8217;t forget [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.phpclasses.org/browse/package/3171.html">Simple Template Engine</a> is a very lightweight template engine to use in PHP if your webhost does not allow you to run something like <a rel="nofollow" href="http://smarty.php.net/">Smarty</a>. It is simple, lightweight and fast.</p>
<p>To parse a file:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

// include simple template engine
include(&quot;tpl.class.php&quot;);

$tpl = new template();

$tpl-&gt;assign(Array('content'=&gt;&quot;Hello World from Simple Template Engine!&quot;));

// If you want to display it directly
$tpl-&gt;display('example.tpl');

// If you want to send it to another function/class for more processing
some_function($tpl-&gt;parse('example.tpl'));

?&gt;</pre>
<p>example.tpl is:</p>
<p>&lt;html&gt;&lt;head&gt;&lt;title&gt;{content}&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;{content}&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;</p>
<p>If you found this article useful or helpful, please help Compdigitec spread the word. Don&#8217;t forget to <a title="Subscribe to Compdigitec Labs" href="/labs/feed/">subscribe to Compdigitec Labs</a> for more useful and interesting articles!</p>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Set of patches to allow PHP-GTK2 to compile with PHP6 (incomplete)</title>
		<link>http://www.compdigitec.com/labs/2009/01/24/set-of-patches-to-allow-php-gtk2-to-compile-with-php6/</link>
		<comments>http://www.compdigitec.com/labs/2009/01/24/set-of-patches-to-allow-php-gtk2-to-compile-with-php6/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 14:27:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[incomplete]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[patches]]></category>
		<category><![CDATA[php gkt]]></category>
		<category><![CDATA[php-gtk]]></category>
		<category><![CDATA[php-gtk2]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=65</guid>
		<description><![CDATA[If you try to compile PHP-GTK 2.0.1 with PHP 6 (available at the Compdigitec Packaging Department), you will need a series of patches to allow it to compile with PHP 6 because the PHP-GTK generator does not like PHP 6. Here are a set of (incomplete, missing main/phpg_support.c) patches for the PHP-GTK2 generator: ext/gtk/gen_atk.c - [...]]]></description>
			<content:encoded><![CDATA[<p>If you try to compile PHP-GTK 2.0.1 with PHP 6 (<a href="http://www.compdigitec.com/packaging/pack/php6.0-200901240130.deb">available at the Compdigitec Packaging Department</a>), you will need a series of patches to allow it to compile with PHP 6 because the PHP-GTK generator does not like PHP 6. Here are a set of (incomplete, missing <em>main/phpg_support.c</em>) patches for the PHP-GTK2 generator:</p>
<ul>
<li>ext/gtk/gen_atk.c - <a href="/labs/files/phpgtk.patches/gen_atk.patch">patch</a>, <a href="/labs/files/phpgtk.patches/gen_atk.c">patched</a></li>
<li>ext/gtk/gen_pango.c - <a href="/labs/files/phpgtk.patches/gen_pango.patch">patch</a>, <a href="/labs/files/phpgtk.patches/gen_pango.c">patched</a></li>
<li>ext/gtk/gen_gdk.c - <a href="/labs/files/phpgtk.patches/gen_gdk.patch">patch</a>, <a href="/labs/files/phpgtk.patches/gen_gdk.c">patched</a></li>
<li>ext/gtk/gen_gtk.c - <a href="/labs/files/phpgtk.patches/gen_gtk.patch">patch</a>, <a href="/labs/files/phpgtk.patches/gen_gtk.c">patched</a></li>
<li>ext/scintilla/gen_scintilla.c - <a href="/labs/files/phpgtk.patches/gen_scintilla.patch">patch</a>, <a href="/labs/files/phpgtk.patches/gen_scintilla.c">patched</a></li>
<li>main/php_gtk.c - <a href="/labs/files/phpgtk.patches/php_gtk.patch">patch</a>, <a href="/labs/files/phpgtk.patches/php_gtk.c">patched</a></li>
</ul>
<p>This set of patches is incomplete because the build process will fail on</p>
<blockquote><p>gcc -I/usr/dev/php-gtk-2.0.1/main -I. -I/usr/dev/php-gtk-2.0.1 -DPHP_ATOM_INC -I/usr/dev/php-gtk-2.0.1/include -I/usr/dev/php-gtk-2.0.1/main -I/usr/dev/php-gtk-2.0.1 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/php -DHAVE_CONFIG_H -g -O0 -Wall -c /usr/dev/php-gtk-2.0.1/main/phpg_support.c  -fPIC -DPIC -o main/.libs/phpg_support.o</p></blockquote>
<p>which it fails with the following output:</p>
<blockquote><p>/usr/dev/php-gtk-2.0.1/main/phpg_support.c: In function &#8216;phpg_init_object&#8217;:<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c:275: error: incompatible type for argument 2 of &#8216;zend_hash_find&#8217;<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c: In function &#8216;phpg_register_class&#8217;:<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c:300: error: incompatible types in assignment<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c:328: error: incompatible type for argument 2 of &#8216;zend_hash_find&#8217;<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c:331: error: incompatible type for argument 2 of &#8216;_zend_hash_add_or_update&#8217;<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c: In function &#8216;phpg_register_interface&#8217;:<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c:353: error: incompatible types in assignment<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c: In function &#8216;unset_abstract_flag&#8217;:<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c:486: error: incompatible type for argument 2 of &#8216;zend_hash_quick_exists&#8217;<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c: In function &#8216;phpg_handler_marshal&#8217;:<br />
/usr/dev/php-gtk-2.0.1/main/phpg_support.c:565: warning: passing argument 3 of &#8216;zend_is_callable&#8217; from incompatible pointer type</p></blockquote>
<p>If you found this article useful or helpful, please help Compdigitec spread the word. Don&#8217;t forget to <a title="Subscribe to Compdigitec Labs" href="http://www.compdigitec.com/labs/feed/">subscribe to Compdigitec Labs</a> for more useful or interesting articles!</p>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2009/01/24/set-of-patches-to-allow-php-gtk2-to-compile-with-php6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to build a CLI interpreter of PHP in Linux</title>
		<link>http://www.compdigitec.com/labs/2009/01/23/how-to-build-a-cli-interpreter-of-php-in-linux/</link>
		<comments>http://www.compdigitec.com/labs/2009/01/23/how-to-build-a-cli-interpreter-of-php-in-linux/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 22:47:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[--prefix=/usr --enable-debug --with-openssl --with-zlib]]></category>
		<category><![CDATA[build php cli]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[php cli linux]]></category>

		<guid isPermaLink="false">http://www.compdigitec.com/labs/?p=64</guid>
		<description><![CDATA[After you have installed the related development packages (eg libmysqlclient15-dev for MySQL support), configure PHP with the following options: &#8208;&#8208;prefix=/usr &#8208;&#8208;enable-debug &#8208;&#8208;with-openssl &#8208;&#8208;with-zlib &#8208;&#8208;with-curl &#8208;&#8208;enable-ftp &#8208;&#8208;with-gettext &#8208;&#8208;with-mhash &#8208;&#8208;with-mysql &#8208;&#8208;enable-sockets &#8208;&#8208;enable-soap &#8208;&#8208;with-tidy &#8208;&#8208;enable-zip &#8208;&#8208;with-xsl &#8208;&#8208;disable-cgi If you found this article helpful or useful, please help Compdigitec spread the word. Don&#8217;t forget to subscribe to Compdigitec Labs [...]]]></description>
			<content:encoded><![CDATA[<p>After you have installed the related development packages (eg libmysqlclient15-dev for MySQL support), configure PHP with the following options:</p>
<blockquote><p><strong>&#8208;&#8208;prefix=/usr &#8208;&#8208;enable-debug &#8208;&#8208;with-openssl &#8208;&#8208;with-zlib &#8208;&#8208;with-curl &#8208;&#8208;enable-ftp &#8208;&#8208;with-gettext &#8208;&#8208;with-mhash &#8208;&#8208;with-mysql &#8208;&#8208;enable-sockets &#8208;&#8208;enable-soap &#8208;&#8208;with-tidy &#8208;&#8208;enable-zip &#8208;&#8208;with-xsl &#8208;&#8208;disable-cgi</strong></p></blockquote>
<p>If you found this article helpful or useful, please help Compdigitec spread the word. Don&#8217;t forget to <a title="Subscribe to Compdigitec Labs" href="http://www.compdigitec.com/labs/feed/">subscribe to Compdigitec Labs</a> for more useful or interesting articles!</p>]]></content:encoded>
			<wfw:commentRss>http://www.compdigitec.com/labs/2009/01/23/how-to-build-a-cli-interpreter-of-php-in-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

