<?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>Webdesign-Tricks.Com &#187; PHP</title>
	<atom:link href="http://www.webdesign-tricks.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdesign-tricks.com</link>
	<description>Web Design Resources, CSS Tricks, Articles, Tutorials and more</description>
	<lastBuildDate>Tue, 23 Feb 2010 17:09:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP versus ASP: Worth the Argument?</title>
		<link>http://www.webdesign-tricks.com/php-versus-asp-worth-the-argument/</link>
		<comments>http://www.webdesign-tricks.com/php-versus-asp-worth-the-argument/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 15:03:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Asp]]></category>

		<guid isPermaLink="false">http://www.webdesign-tricks.com/?p=489</guid>
		<description><![CDATA[PHP: The Overview
PHP stands for Hypertext Preprocessor. Reading the title alone can alert you to the fact that this is a server-side processing language that reveals itself in the form of HTML. The most common use of this is web forms. Data is sent from the client to the web server. Information is processed and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>PHP: The Overview</strong></p>
<p>PHP stands for Hypertext Preprocessor. Reading the title alone can alert you to the fact that this is a server-side processing language that reveals itself in the form of HTML. The most common use of this is web forms. Data is sent from the client to the web server. Information is processed and returns results.</p>
<p> MARKETPLACE<br />
	Digital Prototyping Demo<br />
Go Beyond 3D To Digital Prototyping With Inventor®. Free Online Demo.<br />
Autodesk.com/Beyond-3d<br />
	Transportation Design &#8211; AutoCAD Civil 3D<br />
Design Road Projects 75% Faster with Automatic Documentation Updates!<br />
www.AutoDesk.com/AutoCAD-Civil-3D<br />
	Virtualization Solutions<br />
Optimize, Simplify, &#038; Save Today. Learn About Microsoft Solutions.<br />
www.microsoft.com<br />
	Microsoft SQL Server® 2008 &#8211; Free Trial<br />
Download the Free 180-day Trial of SQL Server® 2008 Enterprise Edition!<br />
www.Microsoft.com/SQLServer<br />
	Java Website Hosting<br />
Shared &#038; Private Tomcat Plans Avail Over 10yrs Of Java Web Hosting Exp!<br />
www.DailyRazor.com<br />
Advertise Here </p>
<p>This versatile language is not restricted to web access in the least. PHP also can be used in command-line processing and also installed as an extension to your own operating system. This will cause the PHP files to open with the PHP executable.</p>
<p>The use of databases is one of PHP&#8217;s strengths. MySQL, SQL, Microsoft Access, Oracle, and InterBase are just a few of the many possibilities to work with.</p>
<p><strong>ASP: The Overview</strong></p>
<p>ASP is short for Active Server Pages. This too is a server-side scripting language. Microsoft has incorporated this language into their servers for more dynamic built-in objects. These are known as Component Object Models (COM).</p>
<p>Although not restricted only to being run on an IIS (Internet Information Services) server, its only full functionality can come through IIS. This first came with Windows 2000 and the NT4 Option Pack. ASP was not restricted to IIS. PWS (Personal Web Server) also was able to interpret ASP code on Windows NT, 95, and 98. However, it was limited in its functionality.</p>
<p><strong>Cost issues</strong></p>
<p>Many people like to argue the cost of ASP versus PHP. I would agree that this can be a concern for some, but really is not a major concern. Most buy IIS for the Microsoft integration. This being the case, IIS is worth the extra money for those expenses.</p>
<p>PHP is free to the extent of the Apache Web Server. The Apache Software Foundation offers a rather secure—but best of all, free—web server. With this, PHP can be installed for free. The only true costs expended are the server to run it, and the time to install it.</p>
<p><strong>Speed questions</strong></p>
<p>Here is where the most arguing is spent for loyalists of both sides of the server-side scripting world. This has been a large debate since both languages came into existence. This is an area that I do believe is greatly significant.</p>
<p>When an Operating System (OS) delegates memory to applications, the application will usually give back the memory. Operating Systems do not ask for that memory back so long as the application is still in use. PHP has a unique way of using this memory usage to its advantage. PHP grabs a memory block and holds it. When it frees up, it is not returned, but held for whatever processing that might take place in the future. This can be edited in the configuration file.</p>
<p>ASP is a little slower due to its COM-based architecture. Because it is calling object models, the machine must load those. This is similar to a programming language referencing a control. The memory usage, however, is not all that different from a standard application.</p>
<p>Truly, the main distinguishing factor will always be the computer on which the web server is run. If the machines are not similar, the language on the faster machine will indeed be faster than the other no matter what the strengths of memory or processor usage.</p>
<p><strong>Compatibility Thoughts</strong></p>
<p>When referring to the &#8220;C&#8221; word, many questions are quickly raised. No two computers are the same and for this reason people want to be assured that what they have will operate with what they already have obtained.</p>
<p>I would say that PHP has the ball in this category. Its winning card is Open Source. This means that PHP has a potential of unlimited developers behind it, greater resources, and a larger library of documentation. Due to all of these factors, much more is developed in addition and more is able to be learned by the programmer.</p>
<p>ASP is commonly thought to only run on IIS. As I mentioned earlier, this is not exactly the case. ASP can, in fact, run on Apache. Apache ASP is a port that enables limited ASP functionality on any Apache web server. The only requirement is mod_perl being enabled.</p>
<p>Always remember that PHP can run on any platform. Mac OS X, Windows, Linux, and Solaris all are among its possible Operating Systems.</p>
<p><strong>Security Considerations</strong></p>
<p>Anything can be hacked, no matter how strong the security. The only thing lacking is the time and the resources of how to do it.</p>
<p>Apache&#8217;s security options make it more secure than Windows Server Operating Systems. IIS is known for many security holes and constant patching. However, I will not be one to say that Apache is security foolproof.</p>
<p><strong>Programming Heritage</strong></p>
<p>ASP has its roots in Microsoft&#8217;s most commonly known language, Visual Basic. For this reason, it is very simple to learn and incorporate. PHP has more of a C++ language base. I believe that this also contributes to its speed abilities.</p>
<p><strong>ASP&#8217;s Common Misconception</strong></p>
<p>ASP.NET and ASP are not the same. ASP.NET is a complete rewrite of the ASP programming language and, for this reason, most of it is not backwards compatible. .NET was written to fit more into the newer Microsoft architecture.</p>
<p><strong>Conclusions</strong></p>
<p>Personally, I would say that PHP is faster, easier, more compatible, more secure, and even cheaper to work with. This is not to say that ASP will never be part of my projects. I just prefer to use PHP because of its abilities over ASP; but it&#8217;s not really worth arguing over. Just use what is most compatible with what you have, and fits what you desire most.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdesign-tricks.com/php-versus-asp-worth-the-argument/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Graphing Data with PHP/SWF Charts</title>
		<link>http://www.webdesign-tricks.com/graphing-data-with-phpswf-charts/</link>
		<comments>http://www.webdesign-tricks.com/graphing-data-with-phpswf-charts/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 14:59:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webdesign-tricks.com/?p=484</guid>
		<description><![CDATA[Quarterly sales figures, industry contacts, profit margin trends&#8230; you name it. Data is the lifeblood of any company. All employees, from the intern preparing a Powerpoint presentation for the middle manager to the dogged sales representative trying to woo a major prospect, require easy and convenient access to all manner of corporate information. The first [...]]]></description>
			<content:encoded><![CDATA[<p>Quarterly sales figures, industry contacts, profit margin trends&#8230; you name it. Data is the lifeblood of any company. All employees, from the intern preparing a Powerpoint presentation for the middle manager to the dogged sales representative trying to woo a major prospect, require easy and convenient access to all manner of corporate information. The first requirement, ease, has long since been resolved by the Internet. These days, corporate data can be accessed from practically anywhere, be it the company intranet, a laptop using a hotel wireless network, or from the back of a taxicab using a cell phone. However, the second requirement, convenience, isn&#8217;t so straightforward.</p>
<p>Convenient data access is a tougher problem to solve because users are able to do little with raw data alone. Rather, it needs to be aggregated and massaged in a coherent fashion. Users need to be able to grasp its context easily, and understand how it all relates to the bigger picture. One of the most successful approaches to doing so is by providing users with a way to visualize the data, typically by using spreadsheets or charting (or a combination of both). But, what if you wanted to relieve your users of some of the tedium involved in formatting this data by doing it for them?</p>
<p>In this tutorial, I&#8217;ll introduce you to PHP/SWF Charts, a great solution for building PHP- and Flash-driven charts. PHP/SWF supports a wide variety of charting formats, including bar, candlestick, 3D columns, pie, 3D pie, and advanced charts such as scatter, polar, and composites. See the <a href="http://www.maani.us/charts/index.php?menu=Gallery">maani.us PHP/SWF gallery</a> for a great compilation of examples. I&#8217;ll base the examples found throughout this article on one particular charting format: the bar chart. Although simple, I think you&#8217;ll find PHP/SWF can produce particularly compelling bar charts nonetheless.</p>
<p>Although not technically open source, you&#8217;re nonetheless able to use and distribute a free version. Paid versions are also available; they grant you additional benefits, including support. See the official <a href="http://www.maani.us/charts/index.php?menu=License">PHP/SWF</a> site for more information about your licensing options.</p>
<p><strong>Installing PHP/SWF Charts</strong></p>
<p>Installing PHP/SWF Charts is easy. Just navigate to the official website and download the latest version: <a href="http://www.maani.us/charts/index.php?menu=Download">http://www.maani.us/charts/index.php?menu=Download.</a> Three formats are available (TAR, ZIP, and SIT), allowing you to choose the archive format most suitable to your operating system (Unix/Linux, Windows, and OS X, respectively).</p>
<p>Next, decompress the download to a directory located somewhere within your web server&#8217;s root directory, for instance /usr/local/apache/htdocs/charting/. That&#8217;s it! You&#8217;re ready to begin using PHP/SWF.</p>
<p><strong>Using PHP/SWF</strong></p>
<p>To create charts using PHP/SWF, you&#8217;ll need to create two scripts. The first script is entirely responsible for building the chart. The second is responsible for displaying that chart within the browser. Although seemingly tedious, and certainly a point of confusion among PHP/SWF beginners, this approach results in a clean separation of often complex logic and the display markup used to format the web page and any corresponding charts. How this is done will become clear as you create your first PHP/SWF bar chart.</p>
<p><strong>Building a Bar Chart</strong></p>
<p>Suppose your company was home to a competitive sales team, and a contest was put together to award the quarter&#8217;s top sales representative with a trip to Las Vegas. To further ratchet up the pressure, the sales manager wants to make a real-time graph available to the entire company via the corporate intranet. By using PHP/SWF, you easily can create a bar chart displaying the results.</p>
<p>Because PHP/SWF creates charts based on data passed in using arrays, you can create a multi-dimensional array containing each sales representative&#8217;s results. In the following script (barchart.php), you&#8217;ll also see two other requisite tasks: including the charts.php file, and calling the SendChartData() function, passing in the array you&#8217;ve created:</p>
<p><?php</p>
<p>   // Include the charts.php library<br />
   include "charts.php";</p>
<p>   // Create the array<br />
   $chart['chart_data'] = array (<br />
           array ( "", "January", "February", "March" ),<br />
           array ( "John Smith", 124198.42, 200088.34, 412128.99 ),<br />
           array ( "Michael Rodgers", 119099.56, 247998.99,<br />
                   476991.11 )<br />
   );</p>
<p>   // Build the chart<br />
   SendChartData($chart);</p>
<p>?></p>
<p>Next, you&#8217;ll create the script (barchart-output.php) that will display the graph:<br />
<?php</p>
<p>   // Include the charts.php library<br />
   include "charts.php";</p>
<p>   // Display the chart<br />
   echo InsertChart("charts.swf", "charts_library", "example1.php",<br />
                    400, 350);</p>
<p>?></p>
<p>Call barchart-output.php within your browser and you&#8217;ll see the following chart:</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2010/01/php.jpg" alt="php" title="php" width="400" height="350" class="aligncenter size-full wp-image-485" /></p>
<p>Want to turn the chart into a horizontal bar chart? Just add the following line to barchart.php following the array:<br />
$chart['chart_type'] = &#8220;bar&#8221;;</p>
<p>Execute barchart-output.php anew and you&#8217;ll see the following chart:</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2010/01/php1.jpg" alt="php1" title="php1" width="400" height="348" class="aligncenter size-full wp-image-486" /></p>
<p><strong>Building a 3D Column Chart</strong></p>
<p>Bar charts are nice, but are lacking in excitement. To really spruce up things, you can add some dimension to the graphs. Modify barchart.php to turn the chart into a three-dimensional version:<br />
<?php</p>
<p>   include "charts.php";</p>
<p>   $chart['chart_data'] = array ( array ( "", "January",<br />
                                          "February", "March" ),<br />
           array ( "John Smith", 124198.42, 200088.34,<br />
                   412128.99 ),<br />
           array ( "Michael Rodgers", 119099.56, 247998.99,<br />
                   476991.11 )<br />
   );</p>
<p>   // Set the chart type<br />
   $chart['chart_type'] = "3d column";</p>
<p>   // Determine how much the chart should be rotated both<br />
   // horizontally and vertically<br />
   $chart['chart_pref'] = array (<br />
          'rotation_x'=>25,<br />
          &#8216;rotation_y&#8217;=>15 );</p>
<p>   // Set the chart offset, width and height, and shading<br />
   $chart['chart_rect'] = array (<br />
          &#8216;x&#8217;=>50, &#8216;y&#8217;=>50,<br />
          &#8216;width&#8217;=>300, &#8216;height&#8217;=>250,<br />
          &#8216;positive_alpha&#8217;=>55, &#8216;negative_alpha&#8217;=>25 );</p>
<p>   SendChartData($chart);</p>
<p>?></p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2010/01/php2.jpg" alt="php2" title="php2" width="400" height="346" class="aligncenter size-full wp-image-487" /></p>
<p><strong>Automatically Refreshing the Chart</strong></p>
<p>The quarter is rapidly coming to a close, and the corporate staff&#8217;s eyes are glued to the chart. To avoid a slowdown due to employees&#8217; constant navigation to the chart, the sales manager has decided to project the chart onto the office wall. However, the chart won&#8217;t be updated unless somebody regularly refreshes the browser. To remedy this problem, you can use PHP/SWF&#8217;s &#8220;live update&#8221; feature, automatically updating the chart according to a specified time frame. For instance, to update barchart-output.php every 15 seconds, add the following array attribute to barchart.php:<br />
$chart['live_update'] = array ( &#8216;url&#8217;=>&#8221;barchart.php?time=&#8221;.time(),<br />
   &#8216;delay&#8217;=>15);</p>
<p>To prove this is working as expected, once the chart loads change one of the array values to something significantly different from its original value, and save the script. You&#8217;ll see that after 15 seconds the chart will reload with the new information.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdesign-tricks.com/graphing-data-with-phpswf-charts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a CAPTCHA Script with PHP</title>
		<link>http://www.webdesign-tricks.com/create-a-captcha-script-with-php/</link>
		<comments>http://www.webdesign-tricks.com/create-a-captcha-script-with-php/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 14:48:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Captcha]]></category>

		<guid isPermaLink="false">http://www.webdesign-tricks.com/?p=482</guid>
		<description><![CDATA[CAPTCHA is a very simple and common protection that helps prevent spam and the automatic submission of an operation by some kind of program or robot. CAPTCHA protection is used on web site forms and works by generating a random string, writing it to an image, then storing the string inside of a session. Then, [...]]]></description>
			<content:encoded><![CDATA[<p>CAPTCHA is a very simple and common protection that helps prevent spam and the automatic submission of an operation by some kind of program or robot. CAPTCHA protection is used on web site forms and works by generating a random string, writing it to an image, then storing the string inside of a session. Then, the site checks the CAPTCHA when the form is submitted. In her PHPBuilder.com article, Octavia Andreea Anghel provides step-by-step instructions for <a href="http://phpbuilder.com/columns/Octavia_Anghel010510.php3">making your own simple CAPTCHA image using PHP</a>.</p>
<p>The core of the <a href="http://phpbuilder.com/columns/PHP_captcha.rar">demo application</a> is a PHP class capable of generating random text and an image that will contain the text (the class is encapsulated in the GeneratedCaptcha.php script). This image will be your CAPTCHA. At a high level, to create your CAPTCHA image you take the following steps:</p>
<p>1. Generate random text.<br />
2. Generate the image containing the random text.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdesign-tricks.com/create-a-captcha-script-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Sending Email with PHP</title>
		<link>http://www.webdesign-tricks.com/how-to-sending-email-with-php/</link>
		<comments>http://www.webdesign-tricks.com/how-to-sending-email-with-php/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 14:46:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Email Using PHP]]></category>

		<guid isPermaLink="false">http://www.webdesign-tricks.com/?p=480</guid>
		<description><![CDATA[Email plays a crucial role in website development, whether you&#8217;d like to confirm a new registrant&#8217;s email address, recover a lost password, or provide prospective clients with a convenient means to contact you. But, although languages such as PHP come packaged with the ability to send email (in PHP&#8217;s case, using the aptly named mail() [...]]]></description>
			<content:encoded><![CDATA[<p>Email plays a crucial role in website development, whether you&#8217;d like to confirm a new registrant&#8217;s email address, recover a lost password, or provide prospective clients with a convenient means to contact you. But, although languages such as PHP come packaged with the ability to send email (in PHP&#8217;s case, using the aptly named mail() function), sending email successfully through a web page isn&#8217;t always as simple as it may seem. In this tutorial, I&#8217;ll introduce you to several solutions for sending email using PHP, including PHP&#8217;s native mail() function, PEAR&#8217;s Mail package, and the Zend Framework.</p>
<p><strong>Email and PHP: The Fundamentals</strong></p>
<p>Most newcomers to PHP were initially attracted to the language due to its low barrier of entry. After all, adding dynamic data to a web page by using PHP (the current date, for instance) can be done with as little as one line of code. Along these lines, one of PHP&#8217;s common selling points is in fact its mail() function. What&#8217;s not to like about a language that can send email via a single simple function? But, the reality is there&#8217;s a bit more involved when it comes to successfully sending email in this fashion, particularly when it comes to doing so on a platform-specific basis.</p>
<p>On the Linux- and Unix-based platforms, PHP&#8217;s mail() function will send email through Sendmail, the open source mail transfer software responsible for sending as much as 75% of the world&#8217;s email. Because Sendmail is typically installed by default on Linux- and Unix-based servers, chances are the mail() function is going to work out of the box.</p>
<p>On the Windows operating system, the process is a tad more involved. Because Windows doesn&#8217;t come with a mail transfer service installed, the mail() function must instead rely on a third-party email server, as defined by PHP&#8217;s SMTP configuration directive. When mail() is called, PHP will contact this SMTP server and attempt to transmit the email using it.</p>
<p><strong>PHP&#8217;s Mail-Specific Configuration Directives</strong></p>
<p>The aforementioned SMTP directive is just one of five supported by PHP:</p>
<p><strong>SMTP:</strong> Defines the SMTP server to use when sending email through PHP scripts running on the Windows operating system.<br />
<strong>smtp_port</strong>: Defines the SMTP port to use when connecting to the SMTP server defined by the SMTP directive. The default is 25.<br />
<strong>sendmail_from:</strong> Identifies the sender of email sent through PHP scripts running on the Windows operating system. If you want to use multiple originating addresses, you&#8217;ll soon learn how to override this directive from within the mail() function.<br />
<strong>sendmail_path</strong>: This Linux/Unix-specific directive allows you to define the path to your Sendmail program if does not reside within your system&#8217;s path.<br />
<strong>mail.force_extra_parameters</strong>: This Linux/Unix-specific directive allows you to send additional email parameters to Sendmail. For instance, you could use this function to override the originating address defined in the mail() function. Typically, this directive is only of concern to system administrators.</p>
<p>Those of you familiar with email configuration are probably wondering how to perform SMTP authentication when connecting to an SMTP server. The unfortunate answer is that you cannot; this eliminates your ability to use most security-conscious mail services in conjunction with PHP&#8217;s native email transmission capability. All is not lost, however, because later in this tutorial I&#8217;ll introduce you to PEAR&#8217;s Mail package that, among other features, offers SMTP authentication.</p>
<p><strong>Sending Email Using the mail() Function</strong></p>
<p>As aforementioned, if you&#8217;re running PHP on Linux or Unix, or are able to connect to an SMTP server without SMTP authentication, PHP&#8217;s mail() function offers by far the easiest solution for sending email. Its prototype follows:<br />
boolean mail(string $to, string $subject, string $message<br />
   [, string $addl_headers [, string $addl_params]])</p>
<p>The $to, $subject, and $message parameters are all self-explanatory, and are all required for the mail() function to operate as expected. The $addl_headers parameter is used to define email headers such as From and Cc. Finally, the $addl_params parameter allows you to modify Sendmail&#8217;s behavior by passing additional configuration parameters to the program at runtime. Typically, you won&#8217;t need to use $addl_params, although $addl_headers is often used to set commonplace headers. For instance:</p>
<p><?php<br />
   mail("jason@example.com", "Welcome to the website",<br />
        "Thank you for joining!",<br />
        "From:jason@example.org\r\nCc:admin@example.org");<br />
?></p>
<p>Take particular note of the \r\n escape sequence separating each header. Neglecting to include this can result in unexpected behavior or failure to transmit the message.</p>
<p><strong>Sending Email Using the PEAR Mail Package</strong></p>
<p>As you&#8217;ve seen, the mail() function offers a no-nonsense, no-frills means for transmitting email. However, Windows users likely are greatly limited by PHP&#8217;s native inability to perform SMTP authentication, not to mention reliance on settings defined within php.ini is going to make moving your website from one server to another somewhat of a chore. One convenient solution that solves both of these issues is PEAR&#8217;s Mail package, which provides a unified programmatic interface for both identifying the transmission backend (and any configuration-related data such as authentication) and sending the message.</p>
<p>To install Mail, execute the following two commands from your terminal:</p>
<p>%>pear install -o Mail<br />
%>pear install -o Net_SMTP</p>
<p>Once installed, you can configure Mail within your script to identify the SMTP server alongside any connection parameters. In the following example, I use Google&#8217;s Gmail service (which I use to manage email for the domain wjgilmore.com) to transmit a message:</p>
<p><?php</p>
<p>   // Include the Mail package<br />
   require "Mail.php";</p>
<p>   // Identify the sender, recipient, mail subject, and body<br />
   $sender    = "wj@wjgilmore.com";<br />
   $recipient = "jason@example.com";<br />
   $subject   = "Thank you for your email!";<br />
   $body      = "I'll get back to you as soon as I can!";</p>
<p>   // Identify the mail server, username, password, and port<br />
   $server   = "ssl://smtp.gmail.com";<br />
   $username = "wj@wjgilmore.com";<br />
   $password = "supersecret";<br />
   $port     = "465";</p>
<p>   // Set up the mail headers<br />
   $headers = array(<br />
      "From"    => $sender,<br />
      &#8220;To&#8221;      => $recipient,<br />
      &#8220;Subject&#8221; => $subject<br />
   );</p>
<p>   // Configure the mailer mechanism<br />
   $smtp = Mail::factory(&#8221;smtp&#8221;,<br />
      array(<br />
        &#8220;host&#8221;     => $server,<br />
        &#8220;username&#8221; => $username,<br />
        &#8220;password&#8221; => $password,<br />
        &#8220;auth&#8221;     => true,<br />
        &#8220;port&#8221;     => 465<br />
      )<br />
   );</p>
<p>   // Send the message<br />
   $mail = $smtp->send($recipient, $headers, $body);</p>
<p>   if (PEAR::isError($mail)) {<br />
      echo ($mail->getMessage());<br />
   }</p>
<p>?></p>
<p>The code found in this example should be fairly straightforward, so I won&#8217;t elaborate on its contents, although it&#8217;s worth noting that in this particular case PHP&#8217;s OpenSSL extension must be enabled, because Gmail requires an SSL connection in addition to SMTP authentication. If your server doesn&#8217;t require SSL, you should be able to authenticate without necessarily reconfiguring PHP to include this extension.</p>
<p><strong>Sending Email Using the Zend Framework</strong></p>
<p>The first two solutions provided in this tutorial progressively solve various obstacles you&#8217;ll encounter when sending email through a PHP script. However, many unresolved tasks remain. For instance, how can you send HTML-formatted email? Include attachments? If you&#8217;re looking for the total package when it comes to sending email, capable of doing everything you could possibly conceive in this regards, look no further than the Zend Framework.</p>
<p>The Zend Framework&#8217;s Zend_Mail component, when coupled with the Zend Framework&#8217;s approach to minimizing redundancy and maximizing portability, offers the ideal solution for configuring and transmitting email through PHP-driven webpages. In this concluding section, I&#8217;ll presume you&#8217;re familiar with the Zend Framework and therefore focus upon my particular approach to using the Zend_Mail component.</p>
<p>First, within the application&#8217;s config.ini file, I define various parameters used to configure the transmission solution:</p>
<p>; email</p>
<p>email.smtpserver = smtp.gmail.com<br />
email.username   = wj@wjgilmore.com<br />
email.password   = supersecret<br />
email.support    = support@wjgilmore.com<br />
Post a comment<br />
Email Article<br />
Print Article<br />
 Share Articles </p>
<p>Within the bootstrap.php file, I configure Zend_Mail&#8217;s transport mechanism, drawing upon the parameters defined in config.ini:</p>
<p>$mailConfigs = array(&#8217;auth&#8217; => &#8216;login&#8217;,</p>
<p> &#8216;username&#8217; => $config->email->username,<br />
                     &#8216;password&#8217; => $config->email->password,<br />
                     &#8217;ssl&#8217; => &#8216;tls&#8217;);</p>
<p>$tr = new Zend_Mail_Transport_Smtp($config->email->smtpserver,<br />
                                   $mailConfigs);<br />
Zend_Mail::setDefaultTransport($tr);</p>
<p>Although this executes with each request, the overhead required to do so is minimal and will not affect performance. Finally, I invoke code similar to the following from within the appropriate controllers:<br />
try {<br />
   // Create a new mail object<br />
   $mail = new Zend_Mail();</p>
<p>   $mail->setFrom($this->config->email->from_admin);<br />
   $mail->addTo(&#8221;jason@example.com&#8221;);<br />
   $mail->setSubject(&#8221;Your account has been created&#8221;);</p>
<p>   $email = &#8220;Thank you for registering!&#8221;;</p>
<p>   $mail->setBodyText($email);<br />
   $mail->send();</p>
<p>   $this->view->success = 1;<br />
} catch (Exception $e) {<br />
   $this->view->errors[] = &#8220;We were unable to send your<br />
      confirmation email. Please contact<br />
      {$this->config->email->support}.&#8221;;<br />
}</p>
<p>If you&#8217;d like to add an attachment, all you need to do is invoke the $mail object&#8217;s createAttachment() method:<br />
$mail->createAttachment(&#8221;brochure.pdf&#8221;);</p>
<p>If you want to send HTML-formatted email, just use the setBodyHtml() method instead of setBodyText():<br />
$mail->sendBodyHTML(&#8221;Thank <b>you</b> for registering!&#8221;);</p>
<p><strong>Where to From Here?</strong></p>
<p>Sending email from your PHP-powered websites is easy once you&#8217;ve been provided with the necessary background, so hopefully this tutorial helped alleviate any initial confusion you had in this regard</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdesign-tricks.com/how-to-sending-email-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Pass Variables between pages in PHP</title>
		<link>http://www.webdesign-tricks.com/make-a-nice-corporate-website-for-a-product/</link>
		<comments>http://www.webdesign-tricks.com/make-a-nice-corporate-website-for-a-product/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 02:11:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Php Variables]]></category>

		<guid isPermaLink="false">http://www.webdesign-tricks.com/?p=228</guid>
		<description><![CDATA[If you’re running a sizable website, chances are you’re going to have to pass information from page to page. Unfortunately with PHP, most data is confined to one page. However, there are ways around this, which I will go over in this tutorial.
The basics, forms
Forms are one of the most basic ways to get from [...]]]></description>
			<content:encoded><![CDATA[<p>If you’re running a sizable website, chances are you’re going to have to pass information from page to page. Unfortunately with PHP, most data is confined to one page. However, there are ways around this, which I will go over in this tutorial.</p>
<h2>The basics, forms</h2>
<p>Forms are one of the most basic ways to get from page 1 to page 2 with all the data you want being transmitted via the form. This is because forms can be directed at a certain page. Here’s an example of a form in HTML:</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php1.jpg" alt="php1" title="php1" width="500" height="54" class="aligncenter size-full wp-image-229" /></p>
<p>The action is where you want the person to go once they press the submit button. The method is the method you want the data to be transmitted as. Simply put, if the method is get, you’ll be able to manipulate it via the url. For instance, the name of the input is text. So when we press submit, it will appear in the url. Post however, won’t appear in the url. There is also a subtle difference when writing the PHP code. So lets go to page.php, the page we’re directing the form at.</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php2.jpg" alt="php2" title="php2" width="500" height="78" class="aligncenter size-full wp-image-230" /></p>
<p>If you were using GET as your method, you would change the $_POST to $_GET. $_POST and $_GET are global variables which will work anywhere in your PHP script. The writing in the brackets is the name of the input field you want to get.</p>
<p>The one downfall of GET is that it has a character limit of 255. Not only this, but you mightn’t want all the information of the form in the url. </p>
<p>Now that you have the form values in a variable, you can manipulate them as you want.</p>
<h2>Cookies</h2>
<p>Cookies are another easy way to get information around your site. Basically cookies are information that is stored on the user’s computer. This allows you to call them whenever you want, after they’re set. To set cookies, we use the setcookie() function. This has quite a lot of parameters, so I thought I’d explain them to you.</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php3.jpg" alt="php3" title="php3" width="500" height="66" class="aligncenter size-full wp-image-231" /></p>
<p>name – The first parameter is name, which is the name of the cookie.<br />
value – Then the value you want to put in it is next. If you want it to expire, you put that next. This is a unix timestamp.<br />
path – The path is basically all the places that the cookie will work, so you can set it to only work in a certain directory.<br />
domain – Domain is used if you have a subdomain name, like img.webtint.net. If you were, you’d put “img.webtint.net” in the domain parameter.<br />
secure – Secure determines whether or not the cookie will work on a secure domain. It can be either TRUE or FALSE. If it’s true the cookie will only work on a secure domain, i.e. HTTPS.<br />
httponly – httponly is almost the opposite of secure. If it’s TRUE, the cookie will only work when the server is an HTTP server.</p>
<p>In the most basic cookie, you only need the name. However usually you will be using the name, value and expire date. Here’s an example of a cookie:</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php4.jpg" alt="php4" title="php4" width="500" height="41" class="aligncenter size-full wp-image-232" /></p>
<p>This is a cookie called name, with a value of value, which will expire in 60 minutes. After you’ve defined the cookie, it’s pretty easy to get it. All you have to do is use the $_COOKIE global variable.</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php5.jpg" alt="php5" title="php5" width="500" height="55" class="aligncenter size-full wp-image-233" /></p>
<p>The bit inbetween the square brackets is the name of the cookie. Again, once you have it in a variable on another page you can manipulate it as you want.</p>
<h2>Sessions</h2>
<p>PHP Sessions are another way to pass information from page to page. To initiate a session, you do the following:</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php6.jpg" alt="php6" title="php6" width="500" height="39" class="aligncenter size-full wp-image-234" /></p>
<p>This initiates the session. You need to put this wherever you want a session to start. So if you have 2 files, where you want the sessions to start in, you have to put session_start() in them. </p>
<p>Then after that you define the session.</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php7.jpg" alt="php7" title="php7" width="500" height="80" class="aligncenter size-full wp-image-235" /></p>
<p>Again, we’re using global variables here. This will make a session called ‘name’, with a value of ‘value’. So here’s an example of how you might use this. Let’s suppose that you have a file called file.php, and a file called file2.php. </p>
<p>In file.php we define the session by doing this:</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php8.jpg" alt="php8" title="php8" width="500" height="118" class="aligncenter size-full wp-image-236" /></p>
<p>Then in file2.php, to display the session value, we do this:</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php9.jpg" alt="php9" title="php9" width="500" height="79" class="aligncenter size-full wp-image-237" /></p>
<p>This will echo the value of the session. Now remember, these sessions are only valid for that session. If the user closes the browser, the sessions will be wiped, so you might want to keep that in mind when defining sessions.</p>
<p>You can also destroy all sessions by running this:</p>
<p><img src="http://www.webdesign-tricks.com/wp-content/uploads/2009/12/php10.jpg" alt="php10" title="php10" width="500" height="65" class="aligncenter size-full wp-image-238" /></p>
<p>There are loads more functions which you can use with sessions, and all the other global variables mentioned in this tutorial, which you can check out at <a href="http://www.php.net/">php.net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdesign-tricks.com/make-a-nice-corporate-website-for-a-product/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
