<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Adam Palmer, Linux, PHP Programmer, MySQL Developer, Embedded Hardware, Security Consultant</title>
	
	<link>http://www.adamsinfo.com</link>
	<description>Adam Palmer MBCS CITP, Linux, PHP Programmer, MySQL Developer, Embedded Hardware, Security Consultant</description>
	<lastBuildDate>Mon, 08 Feb 2010 13:46:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AdamsTechTalkLinuxHowtosDiscussion" /><feedburner:info uri="adamstechtalklinuxhowtosdiscussion" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Linux LUKS Crypt HOWTO</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/HENz_f7-6x4/</link>
		<comments>http://www.adamsinfo.com/linux-luks-crypt-howto/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 23:07:32 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[cryptsetup]]></category>
		<category><![CDATA[luks]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[umount]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=935</guid>
		<description><![CDATA[Linux kernels now support encrypted filesystems. Setting one up should take 5 minutes, or 3 hours if you&#8217;re like me and can&#8217;t read.
Firstly, install the right tools: apt-get install cryptsetup 
Make a new partition, and initialize it with: cryptsetup luksFormat /dev/sda3 mycrypto
Where /dev/sda3 is your newly created partition and &#8216;mycrypto&#8217; is your name for the [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/UUUeOs58kGtBoultltk5wjgxlOc/0/da"><img src="http://feedads.g.doubleclick.net/~a/UUUeOs58kGtBoultltk5wjgxlOc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/UUUeOs58kGtBoultltk5wjgxlOc/1/da"><img src="http://feedads.g.doubleclick.net/~a/UUUeOs58kGtBoultltk5wjgxlOc/1/di" border="0" ismap="true"></img></a></p><p>Linux kernels now support encrypted filesystems. Setting one up should take 5 minutes, or 3 hours if you&#8217;re like me and can&#8217;t read.</p>
<p>Firstly, install the right tools: <strong>apt-get install cryptsetup </strong></p>
<p>Make a new partition, and initialize it with: <strong>cryptsetup luksFormat /dev/sda3 mycrypto</strong></p>
<p>Where /dev/sda3 is your newly created partition and &#8216;mycrypto&#8217; is your name for the container.</p>
<p>You will be prompted to type YES in uppercase to confirm your understanding that your partition is about to be wiped. If, like me, you type &#8216;yes&#8217; in lowercase, it will fail with &#8220;Command Failed.&#8221;. You&#8217;ll then spend hours checking for loaded kernel modules, log files, and trawling google for more information. The answer is to type &#8216;YES&#8217; in uppercase as you&#8217;re told <img src='http://www.adamsinfo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Enter a passphrase, and you&#8217;re ready to go.</p>
<p>Next, &#8216;open&#8217; the container. <strong>cryptsetup luksOpen /dev/sdb3</strong> enter the passphrase, and you should at this point end up with a /dev/mapper/mycrypto</p>
<p>Format with your desired partition <strong>mkfs.ext3 /dev/mapper/mycrypto</strong></p>
<p>Then, you can mount /dev/mapper/mycrypto as you would any other block device: <strong>mount /dev/mapper/mycrypto /mnt/my_mount_point</strong></p>
<p>To close the container:<br />
<strong>umount /dev/mapper/mycrypto<br />
cryptsetup luksClose mycrypto</strong></p>
<p>Easy <img src='http://www.adamsinfo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=HENz_f7-6x4:fXlQd9DUBGI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=HENz_f7-6x4:fXlQd9DUBGI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=HENz_f7-6x4:fXlQd9DUBGI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=HENz_f7-6x4:fXlQd9DUBGI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/HENz_f7-6x4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/linux-luks-crypt-howto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/linux-luks-crypt-howto/</feedburner:origLink></item>
		<item>
		<title>Linux Controlled Door Entry</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/Ld4gxl93z4M/</link>
		<comments>http://www.adamsinfo.com/linux-controlled-door-entry/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 16:08:29 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[alix]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[embedded linux]]></category>
		<category><![CDATA[phidgets]]></category>
		<category><![CDATA[rc transmitter]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[velleman]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=928</guid>
		<description><![CDATA[Having recently moved to a new apartment, one of the first things that I decided to do was build an RC entry system   
Here&#8217;s some pictures:








The black box at the top is a simple Velleman RC control kit and the black box below is a 240VAC-&#62;12VDC regulated converter.  The Velleman RC receiver has [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/aaaYD-Ava-k6SrMND-f_pFMWn_w/0/da"><img src="http://feedads.g.doubleclick.net/~a/aaaYD-Ava-k6SrMND-f_pFMWn_w/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/aaaYD-Ava-k6SrMND-f_pFMWn_w/1/da"><img src="http://feedads.g.doubleclick.net/~a/aaaYD-Ava-k6SrMND-f_pFMWn_w/1/di" border="0" ismap="true"></img></a></p><p>Having recently moved to a new apartment, one of the first things that I decided to do was build an RC entry system  <img src='http://www.adamsinfo.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Here&#8217;s some pictures:</p>
<table style="width: 557px; height: 261px;" border="0">
<tbody>
<tr>
<td><img class="alignleft size-thumbnail wp-image-930" title="Door" src="http://www.adamsinfo.com/wp-content/uploads/2010/01/CIMG2048-150x150.jpg" alt="Door" width="260" height="248" /></td>
<td><img class="alignleft size-thumbnail wp-image-929" title="Door" src="http://www.adamsinfo.com/wp-content/uploads/2010/01/CIMG2047-150x150.jpg" alt="Door" width="271" height="251" /></td>
</tr>
</tbody>
</table>
<p>The black box at the top is a simple Velleman RC control kit and the black box below is a 240VAC-&gt;12VDC regulated converter.  The Velleman RC receiver has two relays, one connected to an electric strike lock and the other connected over the button input in the entryphone which unlocks the main door.</p>
<p>On the RC transmitter there are two buttons, and as they are currently connected, one opens the main door and one unlocks the electric strike on the apartment door, with a 5 second timer on each.</p>
<p>This works well so far and I have paired the transmitters with the receiver so that default unpaired transmitters will not activate the relays. A few weeks on, having already locked myself out once, the next step is to extend this project.</p>
<p>I intend to have the RC transmitter connected separately to some embedded linux board, probably the spare Alix and Phidgets boards I have from the robot I built a while ago. The linux board will signal over a separate frequency to this door entry system. The linux board will perform a variety of functions from logging entries to automated surveillance.  Additionally the linux board will have net access and possibly run asterisk. I can either SMS my way in or alternatively call in to asterisk and do some voice authentication. More to follow when I actually have time to get this done..</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=Ld4gxl93z4M:zssP8GFIcLI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=Ld4gxl93z4M:zssP8GFIcLI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=Ld4gxl93z4M:zssP8GFIcLI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=Ld4gxl93z4M:zssP8GFIcLI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/Ld4gxl93z4M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/linux-controlled-door-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/linux-controlled-door-entry/</feedburner:origLink></item>
		<item>
		<title>Website Security Scan</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/WlIs2N_4hDc/</link>
		<comments>http://www.adamsinfo.com/website-security-scan/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 00:54:13 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security Consultant]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cross site scripting]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[mod_security]]></category>
		<category><![CDATA[php security]]></category>
		<category><![CDATA[rate limit]]></category>
		<category><![CDATA[restrict limit]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[sniffing]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[website security scan]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=912</guid>
		<description><![CDATA[Websites get hacked every day, customers details taken, and it&#8217;s usually REALLY EASY to do. As a security consultant,  I often get a call after a Google search turns up with my details as the guy to contact when this happens.
Shameless plug: Why not contact me BEFORE this happens for a FREE basic web scan.
Shameless [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/2f-q77UAZp0xOXILJvFjhI4mAG8/0/da"><img src="http://feedads.g.doubleclick.net/~a/2f-q77UAZp0xOXILJvFjhI4mAG8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/2f-q77UAZp0xOXILJvFjhI4mAG8/1/da"><img src="http://feedads.g.doubleclick.net/~a/2f-q77UAZp0xOXILJvFjhI4mAG8/1/di" border="0" ismap="true"></img></a></p><p>Websites get hacked every day, customers details taken, and it&#8217;s usually REALLY EASY to do. As a <a href="http://www.adamsinfo.com/security-consultant/">security consultant</a>,  I often get a call after a Google search turns up with my details as the guy to contact when this happens.</p>
<p><strong>Shameless plug: </strong>Why not <a href="http://www.adamsinfo.com/contact-me/">contact me</a> BEFORE this happens for a FREE basic web scan.</p>
<p>Shameless plug over, why not consider some of the things that can be done to help prevent a website breach..<br />
<span id="more-912"></span></p>
<p>First, concentrate on the box and LAMP environment as a whole. Here&#8217;s a top 10:</p>
<ol></ol>
<ul>
<li>Restrict or disable .htaccess type files. A lot of sites these days allow uploading of files, in whatever form that may come. Often, the code can be tricked into allowing an attacker to upload htaccess files to certain directories which could allow for scripts to be executed, or visitors to be redirected.</li>
</ul>
<ol></ol>
<ul>
<li>Check your apache config, after tightening up/disabling htaccess, disabling cgi directories you might not need, and modifying limits.</li>
</ul>
<ol></ol>
<ul>
<li>Consider mod_security</li>
</ul>
<ol></ol>
<ul>
<li>Check your apache, php, mysql and related modules are up to date</li>
</ul>
<ol></ol>
<ul>
<li>Firewall mysql externally and any other services that should not be accessed directly from the outside or are not necessary.</li>
</ul>
<ol></ol>
<ul>
<li>Check your list of mysql users and make sure you only have the necessary privileges assigned to the various users.</li>
</ul>
<ol></ol>
<ul>
<li>It&#8217;s common to find users on their own webservers connecting to mysql from their web code as the root user. Don&#8217;t do it. Create a user account for that particular site/database and assign it the tightest privileges. Do not connect to mysql as root unless necessary.</li>
</ul>
<ol></ol>
<ul>
<li>Take multi day backups of database, code AND logs.</li>
</ul>
<ol></ol>
<ul>
<li>Check the machine for word readable/writable directories.</li>
</ul>
<ol></ol>
<ul>
<li>Restrict limits on hits/sec from IPs</li>
</ul>
<ol></ol>
<p>Next, look to your web code, here&#8217;s a top 5:</p>
<ol></ol>
<ul>
<li>Look for <a href="http://www.adamsinfo.com/security-consultant-php-developer-sql-injection-attacks/">SQL Injection</a> opportunities. SQL Injection is NOT just prevented with escaping incoming strings..</li>
</ul>
<ol></ol>
<ul>
<li>Check all input areas for XSS (Cross Site Scripting)</li>
</ul>
<ol></ol>
<ul>
<li>See my <a href="../php-security/">PHP Security</a> post</li>
</ul>
<ol></ol>
<ul>
<li>Session ID Protection &#8211; can users overwrite cookie/session variables that you have set and taken for granted the fact that they shouldn&#8217;t be changed by the user? This is easy to do overwrite/exploit with &#8216;curl&#8217; or &#8216;wget&#8217;</li>
</ul>
<ol></ol>
<ul>
<li>How are you handling user data input? <a href="some-simple-filtering-and-sniffing-with-tcpdump/">Sniffing</a> plaintext HTTP or plaintext anything for that matter is very simple. All sensitive data should be sent over HTTPS. On that matter, are you storing the data safely afterwards?</li>
</ul>
<ol></ol>
<p>Anything to add to this list? Please let me know!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=WlIs2N_4hDc:Q_UQBJ_J3A8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=WlIs2N_4hDc:Q_UQBJ_J3A8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=WlIs2N_4hDc:Q_UQBJ_J3A8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=WlIs2N_4hDc:Q_UQBJ_J3A8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/WlIs2N_4hDc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/website-security-scan/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/website-security-scan/</feedburner:origLink></item>
		<item>
		<title>Embedded Linux Programmer</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/h5RcFUUn43M/</link>
		<comments>http://www.adamsinfo.com/embedded-linux-programmer/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 20:13:13 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[assembler]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[mips]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=799</guid>
		<description><![CDATA[As an embedded linux programmer, I&#8217;ve had the opportunity to work on a number of different platforms, MIPS being one of my favorites.
There are a few general limitations that you&#8217;ll find. You have limited CPU power available, you have very little RAM available, and for more advanced operations and optimizations, your CPU will generally have [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/0FwXoSG9HrYLf16Zmbkv5uuTbZ8/0/da"><img src="http://feedads.g.doubleclick.net/~a/0FwXoSG9HrYLf16Zmbkv5uuTbZ8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/0FwXoSG9HrYLf16Zmbkv5uuTbZ8/1/da"><img src="http://feedads.g.doubleclick.net/~a/0FwXoSG9HrYLf16Zmbkv5uuTbZ8/1/di" border="0" ismap="true"></img></a></p><p>As an embedded linux programmer, I&#8217;ve had the opportunity to work on a number of different platforms, MIPS being one of my favorites.</p>
<p>There are a few general limitations that you&#8217;ll find. You have limited CPU power available, you have very little RAM available, and for more advanced operations and optimizations, your CPU will generally have a limited function set.</p>
<p>The usual good programming practices apply, but are of much greater importance. Specifically, don&#8217;t allocate memory that you don&#8217;t need, and dont put the CPU under undue stress with unnecessary or badly optimized loops. Taking C syntax and some pseudo code;<br />
<span id="more-799"></span><br />
char *myvar = malloc(10240);<br />
strcpy(myvar, somevar);<br />
&#8230;</p>
<p>Where somevar has previously been limited to say 16 bytes of data, why just allocate an arbitrary large number (10KB) to myval?</p>
<p>Here&#8217;s another:</p>
<p>int ctr = 0;<br />
int maxlen = 0;<br />
for (ctr = 0; ctr &lt; get_count(data); ctr++) { &#8230; }</p>
<p>Although this looks nice and tidy, why are we calling get_count to get the number of records each time the loop runs when it will never change?</p>
<p>int data_count = get_count(data);<br />
for (ctr = 0; ctr &lt; data_count; ctr++) { &#8230; }</p>
<p>makes much more sense.</p>
<p>Years ago, there was also a lot of manual assembler optimization that you could do before compiling. A popular one was replacing &#8220;movl %eaX, 0&#8243; with &#8220;xorl %eax %eax&#8221; as the exclusive or result of two of the same value will be 0 and requires less processor time than the movl operation. Now, not only can most of this be done for you by passing the -OX flag to gcc, but a loop of 1 million movl&#8217;s took no more time than 1 million xorl&#8217;s on my processor, and I&#8217;m guessing the processor deals with this for you now anyway. Today, if you&#8217;re on a nonstandard platform and you&#8217;ve got the information that certain instructions are favored over others on your target, you&#8217;d be able to better optimize the assembler code before compile time.</p>
<p>The main thing to remember, is that sloppy programming that would have gone unnoticed on your super powerful CPU will bring your embedded application to a halt.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=h5RcFUUn43M:RLhs8-jGxbA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=h5RcFUUn43M:RLhs8-jGxbA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=h5RcFUUn43M:RLhs8-jGxbA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=h5RcFUUn43M:RLhs8-jGxbA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/h5RcFUUn43M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/embedded-linux-programmer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/embedded-linux-programmer/</feedburner:origLink></item>
		<item>
		<title>PHP Security</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/wGRHFeAPZpw/</link>
		<comments>http://www.adamsinfo.com/php-security/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 20:43:35 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[cross site scripting]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[error reporting]]></category>
		<category><![CDATA[magic quotes]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql_real_escape_string]]></category>
		<category><![CDATA[php security]]></category>
		<category><![CDATA[safe mode]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=914</guid>
		<description><![CDATA[As a PHP programmer, there are a couple of things you can do quickly and easily to increase the security of your PHP code installation.
Look into PHP&#8217;s &#8220;safe mode&#8221; feature, ESPECIALLY if you&#8217;re running a webserver that takes the general public can upload scripts to. Here you&#8217;ll find a list of the functions disabled or [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/16E8f7IgWZd_YxYIz2HsoeZxiOc/0/da"><img src="http://feedads.g.doubleclick.net/~a/16E8f7IgWZd_YxYIz2HsoeZxiOc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/16E8f7IgWZd_YxYIz2HsoeZxiOc/1/da"><img src="http://feedads.g.doubleclick.net/~a/16E8f7IgWZd_YxYIz2HsoeZxiOc/1/di" border="0" ismap="true"></img></a></p><p>As a PHP programmer, there are a couple of things you can do quickly and easily to increase the security of your PHP code installation.</p>
<p>Look into PHP&#8217;s &#8220;safe mode&#8221; feature, ESPECIALLY if you&#8217;re running a webserver that takes the general public can upload scripts to. <a href="http://www.php.net/manual/en/features.safe-mode.functions.php" target="_blank">Here</a> you&#8217;ll find a list of the functions disabled or restricted by safe mode. It is not strictly PHP&#8217;s job to restrict these types of functions, however unless you really know what you&#8217;re doing, the list of functions restricted by safemode is a good starting point for building secure applications. These are generally functions that allow file and directory manipulation, and socket manipulation. If it&#8217;s not possible within your environment to disable them all, disable as many of these functions as possible.</p>
<p>Although not that common, if I&#8217;m writing an application that heavily relies on functions that manipulate directories or sockets, I&#8217;ll prefer to create a C daemon or similar to handle this side of things and simply use PHP to communicate with it.<span id="more-914"></span><br />
Within your code, do not ever assume any type of input given by a user or with the possibility of being manipulated by a user is safe. Take the following example:</p>
<p>readfile.php?file=&#8230;<br />
&lt;?php<br />
$fh = fopen($_GET['file'], &#8220;r&#8221;);<br />
&#8230;<br />
?&gt;</p>
<p>The attacker can specify ?file=/etc/passwd or anything else for that matter readable by the web user. Instead:</p>
<p>readfile.php?file_id=1<br />
&lt;?php<br />
switch($_GET['file_id'])<br />
{<br />
case &#8220;1&#8243;:<br />
$filename=&#8221;/tmp/myfile&#8221;;<br />
&#8230;<br />
}</p>
<p>Next, make sure register_globals is turned OFF in PHP&#8217;s config file. In all newer versions of PHP this is already done. register_globals automatically creates a variable called $username from a page called with page.php?username=adam. With register_globals off, this is only accessible via $_GET['username'] or $_REQUEST['username'].</p>
<p>This means that I could call page.php?user_id=1&amp;username=admin. Your code should accomodate register_globals being turned on, and automatically check for this kind of variable poisoning however this is often overlooked.</p>
<p>Magic Quotes is a depreciated feature of PHP helping beginners write more secure code. All incoming input would automatically have the quotes escaped thus preventing <a href="http://www.adamsinfo.com/security-consultant-php-developer-sql-injection-attacks/">SQL Injection</a>. More advanced users that know what they&#8217;re doing can find this annoying, as it is not strictly PHP&#8217;s job to interfere with the input variables like this. Instead you should escape all input yourself with addslashes() or mysql_real_escape_string()</p>
<p>PHP error reporting is another important issue to consider. By default, any warnings and errors are printed out to the user. This often gives away directory paths, filenames, variables and all sorts of other information about the server and the script that should not be printed out to an anonymous user. <a href="http://uk2.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting" target="_blank">Turn off error reporting</a> to the screen and instead dump any errors to a log file an perhaps trigger an email to an admin.</p>
<p>These are just a few basic things to keep in mind to get started. User input can come in a variety of formats, and not just via the variables $_GET, $_SESSION, etc, etc. XSS (Cross Site Scripting) is another common attack method and something that will be covered in future articles.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=wGRHFeAPZpw:z3ZbfaodREY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=wGRHFeAPZpw:z3ZbfaodREY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=wGRHFeAPZpw:z3ZbfaodREY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=wGRHFeAPZpw:z3ZbfaodREY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/wGRHFeAPZpw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/php-security/</feedburner:origLink></item>
		<item>
		<title>Linux Consultant – Server Management, Basic Housekeeping</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/mLckG5xr62A/</link>
		<comments>http://www.adamsinfo.com/linux-consultant-server-management-basic-housekeeping/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 18:03:54 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[housekeeping]]></category>
		<category><![CDATA[server management]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=909</guid>
		<description><![CDATA[Server management is one of the most basic requirements in maintaining a healthy server/cluster, however, is often overlooked until something goes wrong.  In it&#8217;s most basic form, server management involves:

Checking log files for size and suspicious entries
Checking disk space usage
Checking memory usage
Checking for new packages (apt-get update; apt-get upgrade)
Check load and process list
Checking backups

If everything&#8217;s [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/-0tgIUxJhZccomi_2OAkISkaLmQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/-0tgIUxJhZccomi_2OAkISkaLmQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-0tgIUxJhZccomi_2OAkISkaLmQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/-0tgIUxJhZccomi_2OAkISkaLmQ/1/di" border="0" ismap="true"></img></a></p><p>Server management is one of the most basic requirements in maintaining a healthy server/cluster, however, is often overlooked until something goes wrong.  In it&#8217;s most basic form, server management involves:</p>
<ol>
<li>Checking log files for size and suspicious entries</li>
<li>Checking disk space usage</li>
<li>Checking memory usage</li>
<li>Checking for new packages (apt-get update; apt-get upgrade)</li>
<li>Check load and process list</li>
<li>Checking backups</li>
</ol>
<p><span id="more-909"></span>If everything&#8217;s working fine, why bother? Well, packages are often upgraded because they contain security holes or other bugs. Often though, the upgrades just contain improvements or new features.</p>
<p>This process doesn&#8217;t generally take more than 30 minutes every so often, and not only keeps your server running well, but also keeps you up to date with the condition of and running software on your server.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=mLckG5xr62A:wF2V4DSzqb4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=mLckG5xr62A:wF2V4DSzqb4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=mLckG5xr62A:wF2V4DSzqb4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=mLckG5xr62A:wF2V4DSzqb4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/mLckG5xr62A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/linux-consultant-server-management-basic-housekeeping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/linux-consultant-server-management-basic-housekeeping/</feedburner:origLink></item>
		<item>
		<title>SSHing from a compromised machine</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/by2gpIhx6qg/</link>
		<comments>http://www.adamsinfo.com/sshing-from-a-compromised-machine/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 13:06:12 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[attacker]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[hacker]]></category>
		<category><![CDATA[libc]]></category>
		<category><![CDATA[malicious]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[Security Consultant]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=906</guid>
		<description><![CDATA[Often, when working with compromised machines, as a security consultant, I find a malicious SSH binary. The malicious SSH binary generally logs all usernames, passwords and hosts connected to from the compromised machine, and usually in /tmp/. The attacker can then log back into the machine and collect this file at a later date.

The compromised [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/auH54GCVPu7zScqJdMW_SsWecWg/0/da"><img src="http://feedads.g.doubleclick.net/~a/auH54GCVPu7zScqJdMW_SsWecWg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/auH54GCVPu7zScqJdMW_SsWecWg/1/da"><img src="http://feedads.g.doubleclick.net/~a/auH54GCVPu7zScqJdMW_SsWecWg/1/di" border="0" ismap="true"></img></a></p><p>Often, when working with compromised machines, as a security consultant, I find a malicious SSH binary. The malicious SSH binary generally logs all usernames, passwords and hosts connected to from the compromised machine, and usually in /tmp/. The attacker can then log back into the machine and collect this file at a later date.<br />
<span id="more-906"></span><br />
The compromised SSH binary is <em>usually</em> over 10 times the size of the normal binary. This is because the attacker compiles it as statically linked in the first place, meaning that all libraries that it depends on are compiled in to the application. This means that as long as the system architecture is the same, e.g. x86, the binary will work regardless of distro or libc version. The attacker could compile the compromised SSH specifically for that libc/distro however this is usually not the case. Either way, the binary will always be of differing size, and will always have a different MD5 checksum compared to the legitimate binary.  You could also run the strings utility against the SSH binary, and attempt to find out more about its contents. Usually you&#8217;ll find custom error messages and the path to the password log shown up by &#8217;strings&#8217;.</p>
<p>This is a popular attack, as users regularly ssh from machine to machine, and additionally, often ssh as root, without any idea as to the ssh binary that they are using. Not only should you only initiate outbound SSH connections from your own trusted machine, and never from machine to machine, but you should also disable root login, and use su or sudo to get root access when required on the remote machine.</p>
<p>Merry Xmas <img src='http://www.adamsinfo.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=by2gpIhx6qg:ASaDHoOGy0I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=by2gpIhx6qg:ASaDHoOGy0I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=by2gpIhx6qg:ASaDHoOGy0I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=by2gpIhx6qg:ASaDHoOGy0I:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/by2gpIhx6qg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/sshing-from-a-compromised-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/sshing-from-a-compromised-machine/</feedburner:origLink></item>
		<item>
		<title>PHP Programmer – Logical Operators</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/BgnkMKgQQog/</link>
		<comments>http://www.adamsinfo.com/php-programmer-logical-operators/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 17:09:34 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[and]]></category>
		<category><![CDATA[bool]]></category>
		<category><![CDATA[boolean]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[logical operators]]></category>
		<category><![CDATA[nand]]></category>
		<category><![CDATA[nor]]></category>
		<category><![CDATA[or]]></category>
		<category><![CDATA[php programmer]]></category>
		<category><![CDATA[xor]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=900</guid>
		<description><![CDATA[PHP allows the use of boolean operators.
AND, OR, XOR and NOT. We can combine NOT with AND and OR to form the NAND and NOR operators respectively.
$a = ($b and $c); will return TRUE if both $b AND $c are TRUE, otherwise, it will return FALSE. This can also be specified as $a = ($b [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/01IyhZpRkfYN0UH30Eiz_jwrEp0/0/da"><img src="http://feedads.g.doubleclick.net/~a/01IyhZpRkfYN0UH30Eiz_jwrEp0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/01IyhZpRkfYN0UH30Eiz_jwrEp0/1/da"><img src="http://feedads.g.doubleclick.net/~a/01IyhZpRkfYN0UH30Eiz_jwrEp0/1/di" border="0" ismap="true"></img></a></p><p>PHP allows the use of boolean operators.</p>
<p>AND, OR, XOR and NOT. We can combine NOT with AND and OR to form the NAND and NOR operators respectively.</p>
<p>$a = ($b and $c); will return TRUE if both $b AND $c are TRUE, otherwise, it will return FALSE. This can also be specified as $a = ($b &amp;&amp; $c)</p>
<p>$a = ($b or $c); will return TRUE if $b OR $c are TRUE, otherwise, it will return FALSE. This can also be specified as $a = ($b || $c);</p>
<p>$a = ($b xor $c); will return TRUE if $b OR $c are TRUE, but not if they are both TRUE, otherwise, it will return FALSE.</p>
<p>$a = (! $b); will return TRUE if $b is NOT TRUE.</p>
<p>$a = (!($b &amp;&amp; $c)); will form NAND (NOT + AND)<br />
$a = (!$b || $c)); will form NOR (NOT+AND);<br />
<span id="more-900"></span><br />
What use is this to us? Here&#8217;s some [hopefully] self explainatory examples:</p>
<p>if ($user_option1 xor $user_option2)<br />
{<br />
//good, do some processing<br />
} else {<br />
echo &#8220;You need to select at least one but not both options&#8221;;<br />
}</p>
<p>if ($logged_in and $verified_email)<br />
{<br />
//good, do some processing<br />
} else {<br />
echo &#8220;You need to log in AND verify your email address before continuing&#8221;;<br />
}</p>
<p>if ( ($usertype == &#8220;paying&#8221;) or ($usertype = &#8220;expired&#8221;) )<br />
{<br />
//good, do some processing<br />
} else {<br />
echo &#8220;You need to be a paying or previously paying user to continue, not a free user.&#8221;;<br />
}</p>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=BgnkMKgQQog:fHxFa6vpnJo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=BgnkMKgQQog:fHxFa6vpnJo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=BgnkMKgQQog:fHxFa6vpnJo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=BgnkMKgQQog:fHxFa6vpnJo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/BgnkMKgQQog" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-programmer-logical-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/php-programmer-logical-operators/</feedburner:origLink></item>
		<item>
		<title>PHP Programmer – Numeric Shorthand</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/rbt-jecSIIU/</link>
		<comments>http://www.adamsinfo.com/php-programmer-numeric-shorthand/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 23:31:27 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[php programmer]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=894</guid>
		<description><![CDATA[PHP 4 and 5 offer a few shorthand methods for basic numeric operations:
$n = $n + 1; can be specified as $n++;
$n = $n &#8211; 1; can be specified as $n&#8211;;
$n = $n + 10; can be specified as $n += 10;
$n = $n &#8211; 10; can be specified as $n -= 10;
On the subject [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/54GhZFNZz7eoxVE07P_JUuo9ql8/0/da"><img src="http://feedads.g.doubleclick.net/~a/54GhZFNZz7eoxVE07P_JUuo9ql8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/54GhZFNZz7eoxVE07P_JUuo9ql8/1/da"><img src="http://feedads.g.doubleclick.net/~a/54GhZFNZz7eoxVE07P_JUuo9ql8/1/di" border="0" ismap="true"></img></a></p><p>PHP 4 and 5 offer a few shorthand methods for basic numeric operations:</p>
<p>$n = $n + 1; can be specified as $n++;<br />
$n = $n &#8211; 1; can be specified as $n&#8211;;<br />
$n = $n + 10; can be specified as $n += 10;<br />
$n = $n &#8211; 10; can be specified as $n -= 10;</p>
<p>On the subject of shorthand, also check out the <a href="/php-ternary-operator/">PHP Ternary Operator</a></p>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=rbt-jecSIIU:slfiF7KQB3Q:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=rbt-jecSIIU:slfiF7KQB3Q:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=rbt-jecSIIU:slfiF7KQB3Q:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=rbt-jecSIIU:slfiF7KQB3Q:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/rbt-jecSIIU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-programmer-numeric-shorthand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/php-programmer-numeric-shorthand/</feedburner:origLink></item>
		<item>
		<title>PHP Programmer – Reading from files</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/CYGpuQi1ouc/</link>
		<comments>http://www.adamsinfo.com/php-programmer-reading-from-files/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 16:21:50 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fclose]]></category>
		<category><![CDATA[filesize]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[fopen]]></category>
		<category><![CDATA[fread]]></category>
		<category><![CDATA[php programmer]]></category>
		<category><![CDATA[strpos]]></category>
		<category><![CDATA[substr]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=889</guid>
		<description><![CDATA[Here I&#8217;ll give some file reading examples. There&#8217;s a few different ways to do this. I&#8217;m going to focus on plain text files only, as opposed to binary files.
If you just want to read the contents of a file into a string variable, then the easiest thing to do is use $mystring = file_get_contents(&#8221;/home/adam/myfile&#8221;);
For more [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/e4ywPXDFCFg2Jaa7Bm-gqDtqdGo/0/da"><img src="http://feedads.g.doubleclick.net/~a/e4ywPXDFCFg2Jaa7Bm-gqDtqdGo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/e4ywPXDFCFg2Jaa7Bm-gqDtqdGo/1/da"><img src="http://feedads.g.doubleclick.net/~a/e4ywPXDFCFg2Jaa7Bm-gqDtqdGo/1/di" border="0" ismap="true"></img></a></p><p>Here I&#8217;ll give some file reading examples. There&#8217;s a few different ways to do this. I&#8217;m going to focus on plain text files only, as opposed to binary files.</p>
<p>If you just want to read the contents of a file into a string variable, then the easiest thing to do is use <strong>$mystring = file_get_contents(&#8221;/home/adam/myfile&#8221;);</strong></p>
<p>For more control over what you&#8217;re doing, or if you want to do anything more than reading a file into a string, you&#8217;ll need to use the fopen, fread and fclose functions.</p>
<p>To read everything in one go:<br />
<span id="more-889"></span><br />
&lt;?php<br />
$myfile = &#8220;/home/adam/myfile&#8221;;<br />
$file_handle = fopen($myfile, &#8220;r&#8221;);  //Open /home/adam/myfile for READING<br />
$data = fread($file_handle, filesize($myfile));<br />
echo &#8220;File contains:  &#8221; . $data . &#8220;\n&#8221;;<br />
fclose($file_handle);<br />
?&gt;</p>
<p>In this case, we use the filesize() function to get size in bytes of $myfile, and we pass that value to fread() as the number of bytes to read from the file, i.e. the entire file.</p>
<p>You could replace filesize() with a fixed figure, or alternatively, if you want to keep reading until you find a certain character or string;</p>
<p>&lt;?php<br />
$myfile = &#8220;/home/adam/myfile&#8221;;<br />
$mysize = filesize($myfile);<br />
$file_handle = fopen($myfile, &#8220;r&#8221;);<br />
while (strpos($tmpdata, &#8220;FINDME&#8221;) === false)<br />
{<br />
$tmpdata = fread($file_handle, 128);<br />
$data .= $tmpdata;<br />
}<br />
fclose($file_handle);<br />
&#8230;.</p>
<p>Now at this point, we&#8217;re reading 128 bytes of the file at a time until we find &#8220;FINDME&#8221;. Depending on the size of the file, pick a reasonable figure. The lower the figure, the more times the loop has to run, which is inefficient in itself, the larger figure  Chances are though, we&#8217;ll end up with additional data after &#8220;FINDME&#8221; anywhere between 0 and 122 characters. If we don&#8217;t want that, to remove &#8220;FINDME&#8221; and anything after it:</p>
<p>&#8230;.<br />
$data = substr  ($data, 0, strpos($data, &#8220;FINDME&#8221;) );<br />
?&gt;</p>
<p>You should also be checking the return code of fopen to ensure that it has actually returned a valid file handle as opposed to blindly reading from what may be an invalid handle.</p>
<p><strong>Edit:</strong></p>
<p>Reader Brian makes a valid point, that the fread(&#8230;, 128) could cut off &#8220;FINDME&#8221; in which case, it will never match, we should perform our test against the data just read as well as the data in the previous read:</p>
<p>while (strpos($tmpdata_last . $tmpdata, &#8220;FINDME&#8221;) === false)<br />
{<br />
$tmpdata_last = $tmpdata;<br />
$tmpdata = fread($file_handle, 128);<br />
$data .= $tmpdata;<br />
}</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=CYGpuQi1ouc:kHfbqpcsB-M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=CYGpuQi1ouc:kHfbqpcsB-M:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=CYGpuQi1ouc:kHfbqpcsB-M:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=CYGpuQi1ouc:kHfbqpcsB-M:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/CYGpuQi1ouc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-programmer-reading-from-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/php-programmer-reading-from-files/</feedburner:origLink></item>
		<item>
		<title>PHP Programmer – strlen, count and substr</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/bWi_Y3nyvmk/</link>
		<comments>http://www.adamsinfo.com/php-programmer-strlen-count-and-substr/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 14:16:17 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[php programmer]]></category>
		<category><![CDATA[strlen]]></category>
		<category><![CDATA[substr]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=883</guid>
		<description><![CDATA[PHP Developer &#8211; strlen, count, and substr
The strlen function retuns the length, i.e. number of characters in a string:  int strlen(string s)
count will get the number of elements in an array:  int count(array a)
substr will return a &#8220;subset&#8221; of a string, string substr(string s, int start, [int len]);
&#60;?php
$s = &#8220;test string&#8221;;
echo &#8220;String length is: &#8221; [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/WuPLUgtOwYCXkPi8H697j1UdaWY/0/da"><img src="http://feedads.g.doubleclick.net/~a/WuPLUgtOwYCXkPi8H697j1UdaWY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/WuPLUgtOwYCXkPi8H697j1UdaWY/1/da"><img src="http://feedads.g.doubleclick.net/~a/WuPLUgtOwYCXkPi8H697j1UdaWY/1/di" border="0" ismap="true"></img></a></p><p>PHP Developer &#8211; strlen, count, and substr</p>
<p>The strlen function retuns the length, i.e. number of characters in a string:  int strlen(string s)</p>
<p>count will get the number of elements in an array:  int count(array a)</p>
<p>substr will return a &#8220;subset&#8221; of a string, string substr(string s, int start, [int len]);<br />
&lt;?php<br />
$s = &#8220;test string&#8221;;<br />
echo &#8220;String length is: &#8221; . strlen($s);<br />
?&gt;</p>
<p>Will return:  String length is: 11</p>
<p>Why would you care how long a string is? Well, for many reasons, one being that you might wish to iterate through each character of a string to perform a certain conditional check or operation on each character. Alternatively, you might want to check that a certain string is not over a given size, and if so, shorten it. Here&#8217;s a common example that shows these three common functions together:</p>
<pre>&lt;?php
$myarray = Array("This is a very long string", "short string", "some text", "some more text to be shortened");
define(MAXLEN, 20); //maximum permitted string length
$num = count($myarray); //Get the number of elements in the array
for ($ctr = 0; $ctr &lt; $num; $ctr++)
{
    if (strlen($myarray[$ctr]) &gt; MAXLEN)
    {
        echo substr($myarray[$ctr], 0, (MAXLEN - 3)) . "...\n";
    } else {
        echo $myarray[$ctr] . "\n";
    }
}
?&gt;</pre>
<p>The above will output:<br />
This is a very lo&#8230;<br />
short string<br />
some text<br />
some more text to&#8230;</p>
<p>This could be used in an instance where we only want to show a predefined &#8220;taster&#8221;, i.e. replacing &#8230; with &#8220;(more)&#8221; or similar. Alternatively, ensuring that text does not overflow a &#8220;&lt;div&gt;&#8221; element in a particular instance</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=bWi_Y3nyvmk:6EEdiR2YZok:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=bWi_Y3nyvmk:6EEdiR2YZok:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=bWi_Y3nyvmk:6EEdiR2YZok:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=bWi_Y3nyvmk:6EEdiR2YZok:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/bWi_Y3nyvmk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-programmer-strlen-count-and-substr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/php-programmer-strlen-count-and-substr/</feedburner:origLink></item>
		<item>
		<title>PHP Programmer – strpos, finding the position of a word in a string</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/3RDRKDmKCnA/</link>
		<comments>http://www.adamsinfo.com/php-programmer-strpos-finding-the-position-of-a-word-in-a-string/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 19:15:33 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php programmer]]></category>
		<category><![CDATA[strpos]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=880</guid>
		<description><![CDATA[In PHP, we can use strpos to find the position of a character or string within another string:
int strpos  ( string $haystack  , mixed $needle  [, int $offset = 0  ] )
For example:
&#60;?php
$mystr = &#8220;this is a test string&#8221;;
$pos = strpos($mystr, &#8220;test&#8221;);
echo &#8220;Position: &#8221; . $pos;
?&#62;
Returns:  Position: 10
We can just as easily use strpos to [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/aZcKRcetiqNLfiKRP57zwBuCR_s/0/da"><img src="http://feedads.g.doubleclick.net/~a/aZcKRcetiqNLfiKRP57zwBuCR_s/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/aZcKRcetiqNLfiKRP57zwBuCR_s/1/da"><img src="http://feedads.g.doubleclick.net/~a/aZcKRcetiqNLfiKRP57zwBuCR_s/1/di" border="0" ismap="true"></img></a></p><p>In PHP, we can use strpos to find the position of a character or string within another string:</p>
<p><strong>int strpos  ( string $haystack  , mixed $needle  [, int $offset = 0  ] )</strong></p>
<p>For example:</p>
<p>&lt;?php<br />
$mystr = &#8220;this is a test string&#8221;;<br />
$pos = strpos($mystr, &#8220;test&#8221;);<br />
echo &#8220;Position: &#8221; . $pos;<br />
?&gt;</p>
<p>Returns:  Position: 10</p>
<p>We can just as easily use strpos to test for whether or not a given string is found in a larger string:</p>
<p>if (strpos($mystr, &#8220;test&#8221;))<br />
{ &#8230; }</p>
<p>However, that may in some cases unexpectedly fail:</p>
<p>if (strpos($mystr, &#8220;this&#8221;))<br />
{ &#8230; }</p>
<p>This will return 0, as &#8220;this&#8221; is at the beginning of the string and therefore at position 0, causing the condition to fail. The correct usage is:</p>
<p>if (strpos($mystr, &#8220;this&#8221;) === false) { &#8230; } OR  if (strpos($mystr, &#8220;this&#8221;) !== false) { &#8230; } noting the usage of &#8220;===&#8221; or &#8220;!==&#8221; meaning an absolute evaluation. As of PHP 4, &#8220;==&#8221; means &#8220;equal to&#8221; and &#8220;===&#8221; means &#8220;identical to&#8221;.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=3RDRKDmKCnA:SE7SPTq3ROI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=3RDRKDmKCnA:SE7SPTq3ROI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=3RDRKDmKCnA:SE7SPTq3ROI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=3RDRKDmKCnA:SE7SPTq3ROI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/3RDRKDmKCnA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-programmer-strpos-finding-the-position-of-a-word-in-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/php-programmer-strpos-finding-the-position-of-a-word-in-a-string/</feedburner:origLink></item>
		<item>
		<title>PHP Developer – Serialize</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/5sWhoWxK2oQ/</link>
		<comments>http://www.adamsinfo.com/php-developer-serialize/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 23:29:22 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[PHP Developer]]></category>
		<category><![CDATA[serialize]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=877</guid>
		<description><![CDATA[PHP has two ver useful functions, serialize and unserialize.
serialize() generates a string based storable representation of any variable type that you like. Take a complex variable:

&#60;?php
a = "test";
$obj-&#62;b = "string";
$obj-&#62;c = Array("this", "is", "a", "test", "array");
$obj-&#62;d = new stdClass();
$obj-&#62;d-&#62;var1 = "some text";
$obj-&#62;d-&#62;var2 = Array("this", "is", "another", "array");

print_r($obj);
?&#62;

wwwtest:~# php ./test.php
stdClass Object
(
    [a] =&#62; [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/FmER2QXS934wruc4vlmHuAfKtDk/0/da"><img src="http://feedads.g.doubleclick.net/~a/FmER2QXS934wruc4vlmHuAfKtDk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/FmER2QXS934wruc4vlmHuAfKtDk/1/da"><img src="http://feedads.g.doubleclick.net/~a/FmER2QXS934wruc4vlmHuAfKtDk/1/di" border="0" ismap="true"></img></a></p><p>PHP has two ver useful functions, serialize and unserialize.</p>
<p>serialize() generates a string based storable representation of any variable type that you like. Take a complex variable:<br />
<span id="more-877"></span></p>
<pre>&lt;?php
a = "test";
$obj-&gt;b = "string";
$obj-&gt;c = Array("this", "is", "a", "test", "array");
$obj-&gt;d = new stdClass();
$obj-&gt;d-&gt;var1 = "some text";
$obj-&gt;d-&gt;var2 = Array("this", "is", "another", "array");

print_r($obj);
?&gt;

wwwtest:~# php ./test.php
stdClass Object
(
    [a] =&gt; test
    [b] =&gt; string
    [c] =&gt; Array
        (
            [0] =&gt; this
            [1] =&gt; is
            [2] =&gt; a
            [3] =&gt; test
            [4] =&gt; array
        )

    [d] =&gt; stdClass Object
        (
            [var1] =&gt; some text
            [var2] =&gt; Array
                (
                    [0] =&gt; this
                    [1] =&gt; is
                    [2] =&gt; another
                    [3] =&gt; array
                )

        )

)</pre>
<p>Now, changing the last line of the script to:</p>
<pre>$mystring = serialize($obj);
echo "Serialized data is: " . $mystring;</pre>
<p>We now get:</p>
<pre>Serialized data is: O:8:"stdClass":4:{s:1:"a";s:4:"test";s:1:"b";s:6:"string";s:1:"c";a:5:{i:0;s:4:"this";i:1;s:2:"is";i:2;s:1:"a";i:3;s:4:"test";i:4;s:5:"array";}s:1:"d";O:8:"stdClass":2:{s:4:"var1";s:9:"some text";s:4:"var2";a:4:{i:0;s:4:"this";i:1;s:2:"is";i:2;s:7:"another";i:3;s:5:"array";}}}</pre>
<p>We can just as easily return this to it&#8217;s original form with unserialize(). This is useful because this flat string can be stored in a database or perhaps even passed through a site and associated with the current user for his usage preferences.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=5sWhoWxK2oQ:C--8N_rpS7o:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=5sWhoWxK2oQ:C--8N_rpS7o:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=5sWhoWxK2oQ:C--8N_rpS7o:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=5sWhoWxK2oQ:C--8N_rpS7o:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/5sWhoWxK2oQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-developer-serialize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/php-developer-serialize/</feedburner:origLink></item>
		<item>
		<title>PHP Developer – Loops in General</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/8YgBgZzKaFY/</link>
		<comments>http://www.adamsinfo.com/php-developer-loops-in-general/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 14:50:38 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[do]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP Developer]]></category>
		<category><![CDATA[PHP MySQL Developer]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=872</guid>
		<description><![CDATA[There are 3 types of loop in PHP:
while (condition)
{ code_goes_here; }
do
{ code_goes_here; }
while (condition);
for(expr1, expr2, expr3)
{ code_goes_here; }
In terms of the &#8216;for&#8217; loop above, &#8216;expr1&#8242; being the starting expression, i.e. $i=0. expr2 being the condition that must be satisfied to keep the loop running, i.e. $i &#60; 100. expr3 being the expression evaluated each time [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/LmgNGypaSQsfE5RKb2al4fbLdpc/0/da"><img src="http://feedads.g.doubleclick.net/~a/LmgNGypaSQsfE5RKb2al4fbLdpc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/LmgNGypaSQsfE5RKb2al4fbLdpc/1/da"><img src="http://feedads.g.doubleclick.net/~a/LmgNGypaSQsfE5RKb2al4fbLdpc/1/di" border="0" ismap="true"></img></a></p><p>There are 3 types of loop in PHP:</p>
<p>while (<em>condition)<br />
</em>{ code_goes_here; }</p>
<p>do<br />
{ code_goes_here; }<br />
while (<em>condition</em>);</p>
<p>for(<em>expr1, expr2, expr3</em>)<br />
{ code_goes_here; }</p>
<p>In terms of the &#8216;for&#8217; loop above, &#8216;expr1&#8242; being the starting expression, i.e. $i=0. expr2 being the condition that must be satisfied to keep the loop running, i.e. $i &lt; 100. expr3 being the expression evaluated each time the loop runs, i.e. $i++. Each loop type has it&#8217;s uses.<br />
<span id="more-872"></span><br />
The two while loops are mostly identical, the only difference being that in the first loop, the condition is checked before running that iteration of the loop whereas in the second loop, the condition is checked after running the loop iteration. The while loop will exit as soon as any negative condition such as a 0, FALSE, etc is hit. That makes it useful for fetching mysql result sets for example:</p>
<p><em>while ($result = mysql_fetch_assoc($resource))<br />
{ //execute code using $result variable }</em></p>
<p>As opposed to:</p>
<p><em>$num = mysql_numrows($resource);<br />
for ($ctr = 0; $ctr &lt; $num; $ctr++)<br />
{<br />
$result = mysql_fetch_assoc($resource));<br />
}</em></p>
<p>Additionally, the for loop does have advantages in cases, such as:</p>
<p><em>for ($ctr = 0; $ctr &lt; 10; $ctr++)<br />
{<br />
echo &#8220;Counter is: &#8221; . $ctr;<br />
}</em></p>
<p>As opposed to:</p>
<p><em>while ($ctr &lt; 10)<br />
{<br />
echo &#8220;Counter is: &#8221; . $ctr;<br />
$ctr++;<br />
}</em></p>
<p>Although in this case there isn&#8217;t a great deal of difference. Just remember when <a href="http://www.adamsinfo.com/php-developer-looping-through-database-results/">looping through database results</a> for example not to call functions or otherwise incur overhead in the loop such as calling <em>mysql_numrows($result) </em>unnecessarily.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=8YgBgZzKaFY:w_NeyFncJOU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=8YgBgZzKaFY:w_NeyFncJOU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=8YgBgZzKaFY:w_NeyFncJOU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=8YgBgZzKaFY:w_NeyFncJOU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/8YgBgZzKaFY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-developer-loops-in-general/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/php-developer-loops-in-general/</feedburner:origLink></item>
		<item>
		<title>UK VPN Hosting</title>
		<link>http://feedproxy.google.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~3/fbXSH5hlvbk/</link>
		<comments>http://www.adamsinfo.com/uk-vpn-hosting/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 15:20:11 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[openvpn]]></category>
		<category><![CDATA[poptop]]></category>
		<category><![CDATA[pptp]]></category>
		<category><![CDATA[uk vpn]]></category>
		<category><![CDATA[uk vpn hosting]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=867</guid>
		<description><![CDATA[I&#8217;m going to be offering some VERY high end UK VPN hosting accounts in the next few weeks once I can get a site and signup form up and running. The VPN servers will run from within the same cluster as this site, and so you can test your ping time with ping www.adamsinfo.com which [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/7oPay-n94GW82k6_syc69EwsKfQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/7oPay-n94GW82k6_syc69EwsKfQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/7oPay-n94GW82k6_syc69EwsKfQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/7oPay-n94GW82k6_syc69EwsKfQ/1/di" border="0" ismap="true"></img></a></p><p>I&#8217;m going to be offering some VERY high end UK VPN hosting accounts in the next few weeks once I can get a site and signup form up and running. The VPN servers will run from within the same cluster as this site, and so you can test your ping time with <strong>ping www.adamsinfo.com </strong>which in my case from my London based BETHERE DSL connection gives a 16-17ms ping time. You can also grab <strong>http://www.adamsinfo.com/wp-content/10mb.test </strong>and <strong>http://www.adamsinfo.com/wp-content/100mb.test</strong> for speed tests. I&#8217;m planning on running <a href="http://www.adamsinfo.com/quick-linux-and-windows-openvpn-howto-and-tutorial-including-vpn-routing/">OpenVPN</a> as the server software but will additionally offer <a href="http://www.adamsinfo.com/linux-pptp-poptop-vpn-setup-with-mppe-and-mppc/">PoPToP</a> if anyone really wants it. Compared to other VPN providers, this will be a reasonably expensive offering. This is on the promise that:</p>
<ul>
<li>The service will be thoroughly undersubscribed</li>
<li>The connectivity will be very fast</li>
<li>You can select as much bandwidth as you want from 512kbit up to 80mbit &#8211; assuming your ISP supports it.</li>
<li>Your service can be configured to use compression and encryption if you wish, meaning even faster access for you. This can use a lot of CPU and RAM on our end</li>
<li>Custom set up as you wish as well as NAT 1:1 dedicated public IP and reverse DNS</li>
<li>Squid Caching Proxy if desired</li>
<li>99.9% uptime guaranteed or your month&#8217;s money back</li>
</ul>
<p>Addition I will be running the <a href="http://www.adamsinfo.com/multithreaded-multi-connection-tcp-proxy-tunnel-update/ ">multithreaded tcp tunnel server software</a> for anyone who wishes to use it, which means that with the right settings/config at your end, you can balance your VPN access over multiple connections at your local end.</p>
<p>Contact me (adam [AT] adamsinfo [DOT] com) to register interest!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=fbXSH5hlvbk:IUjrR3yjh88:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=fbXSH5hlvbk:IUjrR3yjh88:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?i=fbXSH5hlvbk:IUjrR3yjh88:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?a=fbXSH5hlvbk:IUjrR3yjh88:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/AdamsTechTalkLinuxHowtosDiscussion?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdamsTechTalkLinuxHowtosDiscussion/~4/fbXSH5hlvbk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/uk-vpn-hosting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.adamsinfo.com/uk-vpn-hosting/</feedburner:origLink></item>
	</channel>
</rss>
