<?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>iTechLog &#187; PHP</title>
	<atom:link href="http://itechlog.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://itechlog.com</link>
	<description>Your source to IT solutions, interesting technology news and code snipets.</description>
	<lastBuildDate>Tue, 10 Jan 2012 17:06:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Cardsave error &#8220;transaction date/time expired&#8221;</title>
		<link>http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/</link>
		<comments>http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 23:08:53 +0000</pubDate>
		<dc:creator>Alex Costa</dc:creator>
				<category><![CDATA[Code Snipets]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[cardsave]]></category>
		<category><![CDATA[date_default_timezone_set()]]></category>
		<category><![CDATA[opencart]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[payment gateway]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://itechlog.com/?p=1071</guid>
		<description><![CDATA[<a href="http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/" title="Cardsave error &quot;transaction date/time expired&quot;"></a>If you are using CardSave (UK Version) and you come across the following error: &#8220;This transaction cannot be processed. It was rejected because the passed transaction date/time has expired. Please press &#8220;Back&#8221; in your browser and resubmit the transaction.&#8221; It&#8217;s &#8230;<p class="read-more"><a href="http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/" title="Cardsave error &quot;transaction date/time expired&quot;"></a><p style="text-align: left;"><span style="font-size: small;"><img class="alignleft size-full wp-image-977" style="margin-left: 10px; margin-right: 10px;" title="php_logo" src="http://itechlog.com/wp-content/uploads/2011/01/php_logo.png" alt="" width="150" height="80" />If you are using CardSave (UK Version) and you come across the following error:</span></p>
<p style="text-align: left;"><span style="font-size: small;">&#8220;<strong>This transaction cannot be processed. It was rejected because the passed transaction date/time has expired. Please press &#8220;Back&#8221; in your browser and resubmit the transaction</strong>.&#8221;</span></p>
<p style="text-align: left;"><span style="font-size: small;">It&#8217;s caused by your server providing a different timezone to your CardSave Gateway. You need to setup your server/script time zone to UTC.  In PHP you can do this by simply adding this line to your script:  <strong>date_default_timezone_set(&#8216;UTC&#8217;);</strong></span></p>
<p style="text-align: left;"><span style="font-size: small;">For example, I was having a problem with the <a title="Cardsave for Opencart" href="http://www.opencart.com/index.php?route=extension/extension/info&amp;extension_id=449&amp;filter_search=cardsave&amp;sort=e.date_modified&amp;order=DESC" target="_blank">Cardsave(hosted) payment extension for OpenCart</a>.  If you are having the same problem do this:</span></p>
<ol style="text-align: left;">
<li><span style="font-size: small;">Open the file /catalog/controler/payment/cardsave_hosted.php</span></li>
<li><span style="font-size: small;">Find this line  <strong>$this-&gt;data['fields']['TransactionDateTime'] = (date(&#8220;Y-m-d H:i:s&#8221;).  &#8216; +00:00&#8242;);</strong>  (line 305 I think)</span></li>
<li><span style="font-size: small;">Just before that line add this : <strong> date_default_timezone_set(&#8216;UTC&#8217;); </strong></span></li>
<li><span style="font-size: small;">Upload file to server and you are sorted.</span></li>
</ol>
<p style="text-align: left;">
<p style="text-align: left;">

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/cardsave' rel='tag' target='_self'>cardsave</a>, <a class='technorati-link' href='http://technorati.com/tag/date_default_timezone_set%28%29' rel='tag' target='_self'>date_default_timezone_set()</a>, <a class='technorati-link' href='http://technorati.com/tag/e-commerce' rel='tag' target='_self'>e-commerce</a>, <a class='technorati-link' href='http://technorati.com/tag/opencart' rel='tag' target='_self'>opencart</a>, <a class='technorati-link' href='http://technorati.com/tag/OpenSource' rel='tag' target='_self'>OpenSource</a>, <a class='technorati-link' href='http://technorati.com/tag/payment+gateway' rel='tag' target='_self'>payment gateway</a>, <a class='technorati-link' href='http://technorati.com/tag/PHP' rel='tag' target='_self'>PHP</a></p>

<!-- end wp-tags-to-technorati -->
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>August 5, 2010 -- <a href="http://itechlog.com/open-source/2010/08/05/opencart-simple-and-great-e-commerce-system/" title="Opencart simple and great e-commerce system">Opencart simple and great e-commerce system</a></li><li>January 31, 2011 -- <a href="http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/" title="It is not safe to rely on the system’s timezone settings">It is not safe to rely on the system’s timezone settings</a></li><li>May 20, 2009 -- <a href="http://itechlog.com/web-design/2009/05/20/gimp-tutorial-and-book/" title="GIMP Tutorial and book">GIMP Tutorial and book</a></li><li>May 13, 2009 -- <a href="http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/" title="Automatically display form data with PHP">Automatically display form data with PHP</a></li><li>April 14, 2009 -- <a href="http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/" title="PDF to Email with registration">PDF to Email with registration</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It is not safe to rely on the system’s timezone settings</title>
		<link>http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/</link>
		<comments>http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 14:33:09 +0000</pubDate>
		<dc:creator>Alex Costa</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[DATE]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[time setting]]></category>

		<guid isPermaLink="false">http://itechlog.com/?p=976</guid>
		<description><![CDATA[<a href="http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/" title="It is not safe to rely on the system’s timezone settings"></a>Recently I have been having the following error on my PHP code every time I call the PHP function date();  Mostly when running it on my local test server. Warning: date(): It is not safe to rely on the system&#8217;s &#8230;<p class="read-more"><a href="http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/" title="It is not safe to rely on the system’s timezone settings"></a><p><img style="float: left; padding-right: 10px;" src="http://itechlog.com/wp-content/uploads/2011/01/php_logo.png" alt="" width="150" height="80" align="left" />Recently I have been having the following error on my PHP code every time I call the PHP function date();  Mostly when running it on my local test server.</p>
<p><strong>Warning: date(): It is not safe to rely on the system&#8217;s timezone settings</strong></p>
<p><strong>Cause:</strong> Since PHP5.1.0 the E_RESTRICT setting causes PHP to report error for every call<br />
 to a date/time function, if no default time is set.<br />
 <strong><br />
 Fix: </strong>There are 2 approaches to  resolving this.</p>
<ol>
<li><strong>Set time setting to your PHP script</strong> with the function <a href="http://php.net/manual/en/function.date-default-timezone-set.php" target="_blank">date_default_timezone_set</a>();  with the intended time zone/location eg: for GMT one can use date_default_timezone_set(&#8216;Europe/London&#8217;); </li>
<li><strong>Set time setting to your php.ini </strong>file by editing the line <a href="http://php.net/manual/en/function.date-default-timezone-set.php" target="_blank"><strong><em>;date.timezone =</em></strong> to <strong><em>date.timezone = &#8220;Europe/London&#8221;</em></strong> </a> or you required location. This is good for setting a server wide time setting. </li>
</ol>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/DATE' rel='tag' target='_self'>DATE</a>, <a class='technorati-link' href='http://technorati.com/tag/error' rel='tag' target='_self'>error</a>, <a class='technorati-link' href='http://technorati.com/tag/PHP' rel='tag' target='_self'>PHP</a>, <a class='technorati-link' href='http://technorati.com/tag/php.ini' rel='tag' target='_self'>php.ini</a>, <a class='technorati-link' href='http://technorati.com/tag/PHP5' rel='tag' target='_self'>PHP5</a>, <a class='technorati-link' href='http://technorati.com/tag/time+setting' rel='tag' target='_self'>time setting</a></p>

<!-- end wp-tags-to-technorati -->
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>October 7, 2011 -- <a href="http://itechlog.com/easy-tips/2011/10/07/spotify-crashes-in-linux-under-wine/" title="Spotify crashes in Linux under Wine">Spotify crashes in Linux under Wine</a></li><li>August 10, 2011 -- <a href="http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/" title="Cardsave error &#8220;transaction date/time expired&#8221;">Cardsave error &#8220;transaction date/time expired&#8221;</a></li><li>August 26, 2009 -- <a href="http://itechlog.com/wordpress/2009/08/26/wordpress-media-upload-http-error/" title="Wordpress Media upload HTTP Error">Wordpress Media upload HTTP Error</a></li><li>May 13, 2009 -- <a href="http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/" title="Automatically display form data with PHP">Automatically display form data with PHP</a></li><li>April 14, 2009 -- <a href="http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/" title="PDF to Email with registration">PDF to Email with registration</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically display form data with PHP</title>
		<link>http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/</link>
		<comments>http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/#comments</comments>
		<pubDate>Wed, 13 May 2009 12:23:44 +0000</pubDate>
		<dc:creator>Alex Costa</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[$_POST]]></category>
		<category><![CDATA[foreach()]]></category>
		<category><![CDATA[html form]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://itechlog.com/?p=723</guid>
		<description><![CDATA[<a href="http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/" title="Automatically display form data with PHP"></a>This is a simple PHP  script to automatically display (dump output)  data submited from a html form. The form setup all inputs (form fields) need to have the same name with [] at the end to turn it into an &#8230;<p class="read-more"><a href="http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/" title="Automatically display form data with PHP"></a><p>This is a simple PHP  script to automatically display (<strong>dump output</strong>)  data submited from a html form.</p>
<p><strong>The form setup</strong></p>
<ul>
<li>all inputs (form fields) need to have the same name with [] at the end to turn it into an array,  e.g &lt;input type=text name=formdata[]&gt;</li>
</ul>
<p style="padding-left: 30px;">formq.html content</p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">&lt;form method=post action=showme.php&gt;<br />
Name: &lt;input type=text name=formdata[]&gt;&lt;br&gt;<br />
Email: &lt;input type=text name=formdata[]&gt;&lt;br&gt;<br />
</span></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">&lt;input type=submit value=ok&gt;<br />
&lt;/form&gt;</span>
</p>
<p style="padding-left: 30px;">
<p><strong>The Script setup</strong></p>
<p style="padding-left: 30px;">showme.php content</p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">&lt;?php<br />
$data = $_POST['formdata']; # get value from the form fields</span>
</p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">foreach ( $data as $key =&gt; $value ) { # loop through array collecting the results</span></p>
<p style="padding-left: 30px;"><span style="color: #3366ff;">echo  &#8220;$value&lt;br&gt;&#8221;;  # output the data  &#8211; print to page<br />
}<br />
?&gt;</span></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/%24_POST' rel='tag' target='_self'>$_POST</a>, <a class='technorati-link' href='http://technorati.com/tag/foreach%28%29' rel='tag' target='_self'>foreach()</a>, <a class='technorati-link' href='http://technorati.com/tag/html+form' rel='tag' target='_self'>html form</a>, <a class='technorati-link' href='http://technorati.com/tag/PHP' rel='tag' target='_self'>PHP</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_self'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>December 4, 2008 -- <a href="http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/" title="Search Engine Optimization  SEO in PHP (Book)">Search Engine Optimization  SEO in PHP (Book)</a></li><li>November 7, 2011 -- <a href="http://itechlog.com/programming/2011/11/07/arduino-the-open-source-hardware/" title="Arduino the Open Source hardware">Arduino the Open Source hardware</a></li><li>August 10, 2011 -- <a href="http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/" title="Cardsave error &#8220;transaction date/time expired&#8221;">Cardsave error &#8220;transaction date/time expired&#8221;</a></li><li>January 31, 2011 -- <a href="http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/" title="It is not safe to rely on the system’s timezone settings">It is not safe to rely on the system’s timezone settings</a></li><li>July 8, 2009 -- <a href="http://itechlog.com/itechlog-news/2009/07/08/android-to-iphone-apps-with-xml/" title="Android to iPhone Apps with XML">Android to iPhone Apps with XML</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDF to Email with registration</title>
		<link>http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/</link>
		<comments>http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 15:20:00 +0000</pubDate>
		<dc:creator>Alex Costa</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[email pdf]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPMailer]]></category>

		<guid isPermaLink="false">http://itechlog.com/?p=697</guid>
		<description><![CDATA[<a href="http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/" title="PDF to Email with registration"></a>Serve PDF files on your website by requesting the user to register their email address. The PDF file is sent to the given email address and the user details registered on a database. This is a very simple script and &#8230;<p class="read-more"><a href="http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/" title="PDF to Email with registration"></a><p>Serve PDF files on your website by requesting the user to register their email address. The PDF file is sent to the given email address and the user details registered on a database. This is a very simple script and relies on four main features.</p>
<p><strong></strong></p>
<p><strong>Apache mod_rewrite (via the .htaccess file)</strong></p>
<p><strong>PHPMailer</strong></p>
<p><strong>MySQL database</strong></p>
<p><strong>the simple-register.php script itself</strong></p>
<p><span id="more-697"></span></p>
<p>See a <a href="http://itechlog.com/pdf/test.pdf" target="_blank">demo here</a></p>
<p>Let&#8217;s start, first you need to create the folder on your site where you are going to place your PDF files, in my case I called it /pdf/ so the address to your files should be something like this, http://yoursite.com/pdf/yourfile.pdf</p>
<h3>1. Apache mod_rewrite (via the .htaccess file)</h3>
<p>create a text file and name it .htaccess and add the follwing text</p>
<pre class="”php”">RewriteEngine On
RewriteBase /
RewriteRule ^(.*).pdf$ /pdf/simple-register.php?file=$1 [R=301,NE,L]</pre>
<p>Mod_rewrite will redirect any trffic to your .pdf file to the registration form &#8220;/pdf/simple-register.php&#8221;, if you save the php file with a different name you will need to adjust this file with the correct filename.</p>
<h3>2. PHPMailer</h3>
<p>is an openSource mailer script which you can <a href="http://phpmailer.codeworxtech.com/" target="_blank">download from their official site</a>. After download extract the class.phpmailer.php file to your /pdf/ folder</p>
<h3>3. MySQL database</h3>
<p>Create a database with a table with the following details</p>
<pre class="”php”">`ID` int(10) unsigned zerofill NOT NULL auto_increment,
  `name` text NOT NULL,
  `email` text NOT NULL,
  `file` text NOT NULL,
  `ip` text NOT NULL,
  PRIMARY KEY  (`ID`)</pre>
<p>if you want you can save the following code as a .sql file and upload to your MySQL using PHPmyAdmin.</p>
<pre class="”php”">CREATE DATABASE `pdflog`;
USE `pdflog`;

-- --------------------------------------------------------

--
-- Table structure for table `download_log`
--

CREATE TABLE IF NOT EXISTS `download_log` (
  `ID` int(10) unsigned zerofill NOT NULL auto_increment,
  `name` text NOT NULL,
  `email` text NOT NULL,
  `file` text NOT NULL,
  `ip` text NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;</pre>
<h3>4. Create the simple-register.php script</h3>
<p>just copy the following code to a text editor and save the file as &#8220;simple-register.php&#8221; or any other name you may want to, but remember to also change the redirection on your .htaccess file.</p>
<p>Before you can upload your script you will need to edit some details on your file, just look at the section &#8220;############ variables for the email function ######&#8221; and add the required information. You will also need to change the database connection information, just look for the line matching the details below and change accordingly.</p>
<pre class="”php”">$dbHost = "localhost"; 	# set host - most likely you don't need to change this
$dbUser = "user";		# set database user
$dbPass = "password";		# set password
$dbName = "databbse";		# set database name</pre>
<p><strong>The script code</strong></p>
<pre class="”php”" style="overflow: auto; height: 400px; width: 100%;"> &lt;?php

echo "&lt;center&gt;&lt;div style=\"width:500px;text-align:left\"&gt;";
$email = $_POST['email'] ;
$name = $_POST['name'] ;
$pdf_file = $_REQUEST['file'] ;

$file = str_replace(".pdf","",$pdf_file); # a workaround for frinedly URL stuff

$allowed_file = "pdf"; # set single filetype

$file = "$pdf_file.$allowed_file";

$filename = str_replace("/pdf/","",$file); # removes the directory /pdf/ from the string

$ip=@$REMOTE_ADDR; // get IP address
if(!$ip) {$ip=$_SERVER['REMOTE_ADDR'];}

############ variables for the email function ######

$webmaster = "webmaster@yourdomain.com"; 	#webmaster or site email address
$site_name = "your site name";			#website name

$subject = "Your requested File: $filename"; #email subject line
$body_html = "&lt;b&gt;Dear $name&lt;/b&gt;&lt;br&gt;&lt;bR&gt;Please find attached the file requested.&lt;/b&gt;"; # HTML version of the message sent to user
$body_txt = "Dear $name\n\nPlease find attached the file requested."; # TEXT only version of the message sent to user
$sent_msg = "&lt;center&gt;&lt;h2&gt;Thank you&lt;/h2&gt; The file has been sent to $name - $email&lt;/center&gt;"; # message displayed on the page after file has been sent

$errot_subject = "Blocked action attempt [$email]"; # error email subject line
$error_body_html    = "&lt;b&gt;This person: $name - $email&lt;/b&gt;&lt;br&gt;&lt;br&gt;has attempted to downlod the file: $filename"; # HTML message to webmaster in case of attempt to access not permited file
$error_body_txt = "This person: $name - $email\n\nhas attempted to downlod the file: $filename";# TEXT message to webmaster in case of attempt to access not permited file
$error_msg = "&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;h2&gt;&lt;center&gt;&lt;font color=#ff0000&gt;Access to this file is not permited.&lt;/center&gt;&lt;/h2&gt;&lt;h4&gt;&lt;/font&gt;&lt;br&gt;Your details have been logged.&lt;br&gt;&lt;br&gt;IP Address: $ip &lt;br&gt; Email: $email &lt;br&gt; Name: $name &lt;br&gt; &lt;/h4&gt;"; # error message showed when user attempt to download a not permited filetype 

############ end vadiables #########################

if(!$email) {  #if email field is blank display the registration form

echo "&lt;center&gt;&lt;br&gt;&lt;br&gt;&lt;h2&gt;&lt;b&gt;Please enter your details to proceed!&lt;/b&gt;&lt;/h2&gt;&lt;br&gt;&lt;br&gt;&lt;form method=post&gt;&lt;input type=hidden value=\"$filename\" name=name&gt; Name: &lt;input type=text name=name&gt;&lt;br&gt;Email: &lt;input type=text name=email&gt;&lt;br&gt; &lt;input type=submit value=send&gt;&lt;br&gt;&lt;br&gt;&lt;div style=\"text-align:left\"&gt;"; 

echo "&lt;/div&gt;&lt;/form&gt;&lt;/center&gt;";

}

else { #otherwise send the file 

$data[] = explode(".", $file);

while (list ($key,$val) = @each ($data)) {

$file_type = $val[1];

}
 # can only email PDF files, for security
if($file_type == $allowed_file) {
$blocked = 0; # information for the database 0 = no attempt to access unauthorized file

sendInfo($webmaster, $site_name, $name, $email, $subject, $body_html, $body_txt, $filename, $sent_msg);

}

else {
$blocked = 1; # information for the database 1 = attempt to access unauthorized file

sendInfo($webmaster, $site_name, $webmaster, $site_name, $error_subject, $error_body_html, $error_body_txt, $filename, $error_msg);
}

	}# end else

###### write details to to database
regtodb($name, $email, $filename, $ip, $blocked); 

echo "&lt;div&gt;&lt;/center&gt;";

?&gt;

&lt;?php

############## functions #############

# write to database

function regtodb($name, $email, $dfiles, $ip, $blocked) {

$dbHost = "localhost"; 	# set host - most likely you don't need to change this
$dbUser = "user";		# set database user
$dbPass = "password";		# set password
$dbName = "databbse";		# set database name

mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());
$query="INSERT INTO download_log VALUES ('','$name','$email','$dfiles','$ip', '$blocked')";
$result=mysql_query($query);

mysql_close();

}

# send email with phpMailer

function sendInfo($webmaster, $site_name, $name, $email, $subject, $body_html, $body_txt, $filename, $sent_msg) {

require_once("class.phpmailer.php");

$mail = new PHPMailer();

$mail-&gt;From = $webmaster;
$mail-&gt;FromName = $site_name;
$mail-&gt;AddAddress($email, $name);
$mail-&gt;AddAttachment($filename, $filename);

$mail-&gt;IsHTML(true);                                  // set email format to HTML

$mail-&gt;Subject = $subject;
$mail-&gt;Body    = $body_html;
$mail-&gt;AltBody = $body_txt;

if(!$mail-&gt;Send())
{
   echo "Message could not be sent. &lt;p&gt;";
   echo "Mailer Error: " . $mail-&gt;ErrorInfo;
   exit;
}

echo $sent_msg;

	}

?&gt;</pre>
<p>Now upload your files to your newly create /pdf folder together with your pdfs. Remember that your links must be to the pdf file and not the script, the mod_rewrite will take care of the redirection for you.</p>
<p>You may also want to add a <a href="http://recaptcha.net/plugins/php" target="_blank">captcha</a> type feature to avoid spam.</p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/email+pdf' rel='tag' target='_self'>email pdf</a>, <a class='technorati-link' href='http://technorati.com/tag/PDF' rel='tag' target='_self'>PDF</a>, <a class='technorati-link' href='http://technorati.com/tag/PHP' rel='tag' target='_self'>PHP</a>, <a class='technorati-link' href='http://technorati.com/tag/PHPMailer' rel='tag' target='_self'>PHPMailer</a></p>

<!-- end wp-tags-to-technorati -->
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>August 10, 2011 -- <a href="http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/" title="Cardsave error &#8220;transaction date/time expired&#8221;">Cardsave error &#8220;transaction date/time expired&#8221;</a></li><li>January 31, 2011 -- <a href="http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/" title="It is not safe to rely on the system’s timezone settings">It is not safe to rely on the system’s timezone settings</a></li><li>May 13, 2009 -- <a href="http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/" title="Automatically display form data with PHP">Automatically display form data with PHP</a></li><li>February 18, 2009 -- <a href="http://itechlog.com/open-source/2009/02/18/sugarcrm-installation-error-sessionsave_path-not-set/" title="SugarCRM Installation error: session.save_path not set">SugarCRM Installation error: session.save_path not set</a></li><li>December 4, 2008 -- <a href="http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/" title="Search Engine Optimization  SEO in PHP (Book)">Search Engine Optimization  SEO in PHP (Book)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SugarCRM Installation error: session.save_path not set</title>
		<link>http://itechlog.com/open-source/2009/02/18/sugarcrm-installation-error-sessionsave_path-not-set/</link>
		<comments>http://itechlog.com/open-source/2009/02/18/sugarcrm-installation-error-sessionsave_path-not-set/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 19:47:06 +0000</pubDate>
		<dc:creator>Alex Costa</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[session.save_path]]></category>
		<category><![CDATA[SugarCRM Error]]></category>

		<guid isPermaLink="false">http://itechlog.com/open-source/2009/02/18/sugarcrm-installation-error-sessionsave_path-not-set/</guid>
		<description><![CDATA[<a href="http://itechlog.com/open-source/2009/02/18/sugarcrm-installation-error-sessionsave_path-not-set/" title="SugarCRM Installation error: session.save_path not set"></a>SugarCRM Community Edition 5.2.0a has shown me the following error during installation. &#8220;The session.save_path setting in your php configuration file (php.ini) is not set or is set to a folder which did not exist. You might need to set the &#8230;<p class="read-more"><a href="http://itechlog.com/open-source/2009/02/18/sugarcrm-installation-error-sessionsave_path-not-set/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://itechlog.com/open-source/2009/02/18/sugarcrm-installation-error-sessionsave_path-not-set/" title="SugarCRM Installation error: session.save_path not set"></a><p><a target="_blank" href="http://www.sugarcrm.com/crm/download/sugar-suite.html">SugarCRM Community Edition 5.2.0a</a> has shown me the following<b> error during installation. <br /></b><b><i><br />&#8220;The session.save_path setting in your php configuration file (php.ini)<br />
is not set or is set to a folder which did not exist. You might need to<br />
set the save_path setting in php.ini or verify that the folder sets in<br />
save_path exist.&#8221;</i></b> </p>
<p>Before you attempt to follow my instructions here, please check that the <b>session.save_path</b> in your <b>php.ini</b> is properly set and that your webserver is behaving normally.</p>
<p>This error is apparently a bug in the installation process of SugarCRM so to get past it you need to edit a PHP file. 
<ol>
<li>Open the file SystemCheck.php (it is located in the install folder)</li>
<li>uncomment lines 184 to 210&nbsp; (just place /* on line 183 &nbsp; and&nbsp; */ on line 211)</li>
<li>save file and restart installation</li>
</ol>
<p><img style="max-width: 800px;" src="http://itechlog.com/wp-content/uploads/2009/02/sugar-error.png" /></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/PHP' rel='tag' target='_self'>PHP</a>, <a class='technorati-link' href='http://technorati.com/tag/session.save_path' rel='tag' target='_self'>session.save_path</a>, <a class='technorati-link' href='http://technorati.com/tag/SugarCRM+Error' rel='tag' target='_self'>SugarCRM Error</a></p>

<!-- end wp-tags-to-technorati -->
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>August 10, 2011 -- <a href="http://itechlog.com/code-snipets/2011/08/10/cardsave-error-transaction-datetime-expired/" title="Cardsave error &#8220;transaction date/time expired&#8221;">Cardsave error &#8220;transaction date/time expired&#8221;</a></li><li>January 31, 2011 -- <a href="http://itechlog.com/web-programming/2011/01/31/it-is-not-safe-to-rely-on-the-systems-timezone-settings/" title="It is not safe to rely on the system’s timezone settings">It is not safe to rely on the system’s timezone settings</a></li><li>May 13, 2009 -- <a href="http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/" title="Automatically display form data with PHP">Automatically display form data with PHP</a></li><li>April 14, 2009 -- <a href="http://itechlog.com/web-programming/2009/04/14/pdf-to-email-with-registration/" title="PDF to Email with registration">PDF to Email with registration</a></li><li>December 4, 2008 -- <a href="http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/" title="Search Engine Optimization  SEO in PHP (Book)">Search Engine Optimization  SEO in PHP (Book)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://itechlog.com/open-source/2009/02/18/sugarcrm-installation-error-sessionsave_path-not-set/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Search Engine Optimization  SEO in PHP (Book)</title>
		<link>http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/</link>
		<comments>http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 23:55:02 +0000</pubDate>
		<dc:creator>Alex Costa</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[MOD_REWRITE]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://itechlog.com/?p=101</guid>
		<description><![CDATA[<a href="http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/" title="Search Engine Optimization  SEO in PHP (Book)"></a>The term SEO (Search Engine Optimization) has become a new phenomenon with marketeers.  As a programmer/developer it&#8217;s very hard to find a good book on such a broad subject but recently I found this great book. The authors go about &#8230;<p class="read-more"><a href="http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/" title="Search Engine Optimization  SEO in PHP (Book)"></a><p><a href="http://www.amazon.co.uk/gp/product/0470100923?ie=UTF8&amp;tag=costafamily-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0470100923" target="_blank"><img src="https://images-na.ssl-images-amazon.com/images/I/5184%2B7hkqxL._SL160_.jpg" border="0" alt="" align="right" /></a><br />
The term SEO (Search Engine Optimization) has become a new phenomenon with  <a title="or MARKETER - One that sells goods or services in or to a market, especially one that markets a specified commodity" href="http://www.thefreedictionary.com/marketeer" target="_blank">marketeers</a>.  As a programmer/developer it&#8217;s very hard to find a good book on such a broad subject but recently I found this great book. The authors go about explaining and guiding you through exercises that are relevant for both programmers and marketeers.  It contains detailed chapters on Website Content, Links, Webmaster tools and <a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html" target="_blank">MOD_REWRITE</a>. The code snipets found in this book can be used as a good reference guide to any SEO project.   This <a title="SEO with PHP" href="http://www.amazon.co.uk/gp/product/0470100923?ie=UTF8&amp;tag=costafamily-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0470100923" target="_blank">book is for PHP Programmers</a> but they have also published a <a title="SEO with .net" href="http://www.amazon.co.uk/gp/product/0470131470?ie=UTF8&amp;tag=costafamily-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0470100923" target="_blank">.NET version.</a></p>
<p>If  you develop with <a title="Wordpress.org" href="http://wordpress.org" target="_blank">WordPress.org</a> this releted post can also be very helpfull:  <a title="SEO and WordPress" href="http://itechlog.com/wordpress/2008/12/13/seo-and-wordpress/" target="_blank">SEO and WordPress</a></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Books' rel='tag' target='_self'>Books</a>, <a class='technorati-link' href='http://technorati.com/tag/MOD_REWRITE' rel='tag' target='_self'>MOD_REWRITE</a>, <a class='technorati-link' href='http://technorati.com/tag/PHP' rel='tag' target='_self'>PHP</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_self'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Search' rel='tag' target='_self'>Search</a>, <a class='technorati-link' href='http://technorati.com/tag/SEO' rel='tag' target='_self'>SEO</a></p>

<!-- end wp-tags-to-technorati -->
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>June 5, 2009 -- <a href="http://itechlog.com/itechlog-news/2009/06/05/keyword-search-and-website-ranking-tools/" title="Keyword search and website ranking tools">Keyword search and website ranking tools</a></li><li>May 13, 2009 -- <a href="http://itechlog.com/web-programming/2009/05/13/automatically-display-form-data-with-php/" title="Automatically display form data with PHP">Automatically display form data with PHP</a></li><li>March 27, 2009 -- <a href="http://itechlog.com/web-programming/2009/03/27/htaccess-301-redirect/" title=".htaccess 301 Redirect">.htaccess 301 Redirect</a></li><li>December 13, 2008 -- <a href="http://itechlog.com/wordpress/2008/12/13/seo-and-wordpress/" title="SEO and Wordpress">SEO and Wordpress</a></li><li>January 10, 2012 -- <a href="http://itechlog.com/social-networking/2012/01/10/google-search-goes-social/" title="Google search goes social">Google search goes social</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://itechlog.com/web-programming/2008/12/04/search-engine-optimization-seo-in-php-book/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

