<?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>Mario Awad &#187; Web development</title>
	<atom:link href="http://www.marioawad.com/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marioawad.com</link>
	<description>On Software and Web Development</description>
	<lastBuildDate>Fri, 06 Nov 2009 07:32:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sending emails with Zend_Mail using Gmail or Google Apps</title>
		<link>http://www.marioawad.com/2009/10/17/sending-emails-with-zend_mail-using-gmail-or-google-apps/</link>
		<comments>http://www.marioawad.com/2009/10/17/sending-emails-with-zend_mail-using-gmail-or-google-apps/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 17:39:36 +0000</pubDate>
		<dc:creator>Mario Awad</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[google apps]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.marioawad.com/?p=214</guid>
		<description><![CDATA[Zend Framework is currently one of the best MVC-based frameworks in the PHP world. Zend_Mail is part of Zend Framework and it provides the ability to easily send email messages. If you&#8217;re like me, most web applications you have developed are setup to use Google Apps as their email provider. Here&#8217;s how to send email [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://framework.zend.com">Zend Framework</a> is currently one of the best MVC-based frameworks in the PHP world. <a href="http://framework.zend.com/manual/en/zend.mail.html">Zend_Mail</a> is part of Zend Framework and it provides the ability to easily send email messages. If you&#8217;re like me, most web applications you have developed are setup to use Google Apps as their email provider. Here&#8217;s how to send email messages via Gmail or Google Apps by using Zend_Mail.</p>
<pre class="brush: php;">
public function send() {

 //Initialize needed variables
 $your_name = 'Mario Awad';
 $your_email = 'your_email@your_domain.com'; //Or your_email@gmail.com for Gmail
 $your_password = 'your_password';
 $send_to_name = 'My Friend';
 $send_to_email = 'myfriend@tempinbox.com';

 //SMTP server configuration
 $smtpHost = 'smtp.gmail.com';
 $smtpConf = array(
  'auth' =&gt; 'login',
  'ssl' =&gt; 'ssl',
  'port' =&gt; '465',
  'username' =&gt; $your_email,
  'password' =&gt; $your_password
 );
 $transport = new Zend_Mail_Transport_Smtp($smtpHost, $smtpConf);

 //Create email
 $mail = new Zend_Mail();
 $mail-&gt;setFrom($your_email, $your_name);
 $mail-&gt;addTo($send_to_email, $send_to_name);
 $mail-&gt;setSubject('Hello World');
 $mail-&gt;setBodyText('This is the body text of the email.');

 //Send
 $sent = true;
 try {
  $mail-&gt;send($transport);
 }
 catch (Exception $e) {
  $sent = false;
 }

 //Return boolean indicating success or failure
 return $sent;

}
</pre>
<p>In addition to the above code, please note the following:</p>
<ul>
<li>You must enable the &#8220;php_openssl&#8221; extension to use the SSL transport protocol (Which is needed for Gmail and Google Apps). All you have to do is open your &#8220;php.ini&#8221; file and uncomment the line that includes the &#8220;php_openssl&#8221; extension (Search for &#8220;php_openssl&#8221; and you&#8217;ll find it).</li>
<li>I found many resources on the web stating that you should use the TLS transport protocol (They never mention how to use or setup the SSL transfer protocol). This didn&#8217;t work in my tests and always resulted in a timeout error.</li>
<li>Yes, you must use &#8220;smtp.gmail.com&#8221; as your SMTP host even if you&#8217;re configuring the application for Google Apps. In other words, don&#8217;t use &#8220;smtp.yourdomain.com&#8221;.</li>
</ul>
<p>I hope this small tutorial saves you some headaches. Cheers <img src='http://www.marioawad.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.marioawad.com/2009/10/17/sending-emails-with-zend_mail-using-gmail-or-google-apps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Capture the output of var_dump in a string</title>
		<link>http://www.marioawad.com/2009/07/11/capture-the-output-of-var_dump-in-a-string/</link>
		<comments>http://www.marioawad.com/2009/07/11/capture-the-output-of-var_dump-in-a-string/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 11:43:15 +0000</pubDate>
		<dc:creator>Mario Awad</dc:creator>
				<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.marioawad.com/?p=199</guid>
		<description><![CDATA[Introduction
You are programming in PHP and you have an array variable that you&#8217;d like to explore at different execution paths. Of course, the best way is to use a PHP debugger like xdebug or Zend Debugger, but, what happens when you&#8217;re too lazy to install a debugger? What happens when you don&#8217;t want or can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>You are programming in PHP and you have an array variable that you&#8217;d like to explore at different execution paths. Of course, the best way is to use a PHP debugger like <a href="http://xdebug.org">xdebug</a> or <a href="http://www.zend.com/en/community/pdt">Zend Debugger</a>, but, what happens when you&#8217;re too lazy to install a debugger? What happens when you don&#8217;t want or can&#8217;t install a debugger and you just need to check the content of that array by dumping it in your log file? Well, you might think you&#8217;re stuck, but, read on&#8230;</p>
<h2>What is var_dump?</h2>
<p>The <a href="http://www.php.net/var_dump">var_dump manual page</a> states that var_dump displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.</p>
<p>The problem is that var_dump outputs its result directly to the browser, how can you capture its output in a string variable? read on&#8230;</p>
<h2>Using output control functions for the solution</h2>
<p>Output control functions can be used to capture and redirect the standard output. For more details, read the <a href="http://www.php.net/manual/en/ref.outcontrol.php">PHP manual on output control functions</a>, of course.</p>
<p>Here&#8217;s the solution:</p>
<pre class="brush: php;">
function varDumpToString ($var)
{
    ob_start();
    var_dump($var);
    $result = ob_get_clean();
    return $result;
}
//
//Example usage:
//    $data = array('first', 'second', 'third');
//    $result = varDumpToString($data);
//
</pre>
<p>All you have to do now is call the varDumpToString function. Happy coding <img src='http://www.marioawad.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.marioawad.com/2009/07/11/capture-the-output-of-var_dump-in-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL Rewriting for CodeIgniter</title>
		<link>http://www.marioawad.com/2009/05/19/url-rewriting-for-codeigniter/</link>
		<comments>http://www.marioawad.com/2009/05/19/url-rewriting-for-codeigniter/#comments</comments>
		<pubDate>Tue, 19 May 2009 17:43:11 +0000</pubDate>
		<dc:creator>Mario Awad</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.marioawad.com/?p=99</guid>
		<description><![CDATA[What is URL Rewriting?
URL rewriting provides shorter and more relevant-looking links to web pages on your site. This improves the readability and the search rankings of your URLs. For example, URL &#8220;a&#8221; can be rewritten as URL &#8220;b&#8221;.
a) http://example.com/index.php?section=casting
b) http://example.com/casting
There are many articles on the web discussing the benefits of shorter and more relevant URLs. [...]]]></description>
			<content:encoded><![CDATA[<h2>What is URL Rewriting?</h2>
<p>URL rewriting provides shorter and more relevant-looking links to web pages on your site. This improves the readability and the search rankings of your URLs. For example, URL &#8220;a&#8221; can be rewritten as URL &#8220;b&#8221;.</p>
<p>a) http://example.com/index.php?section=casting<br />
b) http://example.com/casting</p>
<p>There are many articles on the web discussing the benefits of shorter and more relevant URLs. Let me add to them that you get to hide the used technology from both search engines and users. You&#8217;ll also have a better time migrating to a different platform in case you need to. For example, if you build your web application on top of ASP.NET and use URL Rewriting, you can easily migrate to PHP (Recommended, of course) without changing your links and hence without losing all the search-ranking score for those links.</p>
<h2>CodeIgniter Default URLs</h2>
<p>By default, CodeIgniter uses a segment-based approach to represent URLs. Unfortunately,  CodeIgniter includes the annoying &#8220;index.php&#8221; file name in the URL. For example:</p>
<p>http://example.com/index.php/products/view/shoes.</p>
<p>Now, the CodeIgniter manual mentions that it&#8217;s very simple to remove the &#8220;index.php&#8221; part from the URL using the following .htaccess file:</p>
<pre class="brush: plain;">
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</pre>
<p>Problem solved? Not really. This didn&#8217;t work on my local machine nor on my online hosting account (<a href="http://www.dreamhost.com/r.cgi?482521">Dreamhost</a>). Why? I don&#8217;t know. I don&#8217;t care. I don&#8217;t currently have the time to find out why.</p>
<p>Having already installed Wordpress, I remembered that their .htaccess file works offline and online (at least in my case). I started playing around with it, checked some online resources, and devised two solutions. The local solution works on my local machine with the XAMPP server installed on it and the online solution works on my Dreamhost account.</p>
<h2>The Local Solution</h2>
<pre class="brush: plain;">
RewriteEngine On
RewriteBase /ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
</pre>
<p>The only change you need to make is to &#8220;ci&#8221; (on lines 2 and 5) which is the folder where you have your CodeIgniter application installed. In brief, this rewrite file tells your web server to apply the rewrite rule whenever a file or a directory is not found on the server. For example, if you invoke URL &#8220;c&#8221;, the &#8220;contact&#8221; folder is not found on your server (Since CodeIgniter files are in the &#8220;system&#8221; folder), and accordingly the URL is rewritten to &#8220;d&#8221;. This rewrite allows CodeIgniter to execute successfully (By using URL &#8220;d&#8221;) while giving you the benefits of shorter URLs (URL &#8220;c&#8221;).</p>
<p>c) http://localhost/ci/contact<br />
d) http://localhost/ci/index.php/contact</p>
<h2>The Online Solution</h2>
<pre class="brush: plain;">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</pre>
<p>There are no changes that you need to make for this .htaccess file. However, there&#8217;s one important note to mention. The question mark after &#8220;index.php&#8221; on line 5 is needed on my online hosting account at Dreamhost. You might want to remove it if it doesn&#8217;t work on yours. Again, I didn&#8217;t have the time to investigate why this is the case. Please check the additional resources for more details.</p>
<h2>Conclusion</h2>
<p>I hope this post saves you a few headaches I had to go through to solve this problem. I would love to see such a solution coming out of the box with the next version of CodeIgniter. If you have any hints or additional information regarding URL rewriting in the context of CodeIgniter, please share them in the comments.</p>
<h2>Additional Resources</h2>
<p>CodeIgniter URLs<br />
<a href="http://codeigniter.com/user_guide/general/urls.html"> http://codeigniter.com/user_guide/general/urls.html</a></p>
<p>URL Rewriting for Beginners<br />
<a href="http://www.addedbytes.com/apache/url-rewriting-for-beginners/"> http://www.addedbytes.com/apache/url-rewriting-for-beginners/</a></p>
<p>An easy way to test your RewriteRules against different URLs<br />
<a href="http://civilolydnad.se/projects/rewriterule/"> http://civilolydnad.se/projects/rewriterule/</a></p>
<p>Dreamhost and CodeIgniter URLs<br />
<a href="http://codeigniter.com/forums/viewthread/55620/"> http://codeigniter.com/forums/viewthread/55620/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marioawad.com/2009/05/19/url-rewriting-for-codeigniter/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
