<?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>Website Design Ireland, Website Development &#187; PHP</title>
	<atom:link href="http://www.eire-webdesign.ie/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eire-webdesign.ie/blog</link>
	<description>Web Design and Development</description>
	<lastBuildDate>Sat, 02 Jan 2010 14:53:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP Form creation and basic validation</title>
		<link>http://www.eire-webdesign.ie/blog/2010/01/02/php-form-creation-and-basic-validation/</link>
		<comments>http://www.eire-webdesign.ie/blog/2010/01/02/php-form-creation-and-basic-validation/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 14:41:51 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP create form fields function]]></category>
		<category><![CDATA[php forms]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/?p=119</guid>
		<description><![CDATA[As a developer and web designer,  the most frustrating part I have found  is when working with forms. Long time ago (about 2 years now) I start putting togheter few PHP function trying to make my life a lot easier, but never got the time to finish it off. Finally I have put everything on the side [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer and web designer,  the most frustrating part I have found  is when working with forms.<br />
Long time ago (about 2 years now) I start putting togheter few PHP function trying to make my life a lot easier, but never got the time to finish it off.</p>
<p>Finally I have put everything on the side and got cracking on this due to a new project that involves the making a few very long forms.</p>
<p>The thought of writing all the html code (tables or DIVs) and validate them made me go back to this little project and decided to give it more thoughts.</p>
<p>This is the first release of the PHP code for this project so, if you would like to give it a bash and make use of it please do so&#8230;</p>
<p>A sample can be found here: <a title="sample php form" href="http://www.eire-webdesign.ie/create_validate_form.php"><strong>SAMPLE PHP FORM</strong></a></p>
<p>Some of the features:</p>
<ul>
<li>Choice of using TABLE or DIVs for layout</li>
<li>You can create more than one form on the same page making sure the right one is validated on submission</li>
<li>Basic form validation</li>
<li>Option to make the field required or not</li>
<li>Show ERROR message  beside the required field &#8211; standard</li>
<li>Option to set the ERROR message text &#8211; set to REQUIRED in the sample form</li>
<li>Show ERROR message at the top of the form as well - optional</li>
<li>Cuts form creation time in more than half</li>
<li>Automatically sets the values of the field after posting the form</li>
<li>Option to add javascript code to the field (e.g. for use with ajax, etc)</li>
<li>and much more&#8230;</li>
</ul>
<p>If you find any errors and anything that could help improve the functionality of this project, please leave a comment and I&#8217;ll make sure it gets done ASAP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2010/01/02/php-form-creation-and-basic-validation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Monitor changes made to the .htaccess file</title>
		<link>http://www.eire-webdesign.ie/blog/2009/03/19/monitor-changes-made-to-the-htaccess-file/</link>
		<comments>http://www.eire-webdesign.ie/blog/2009/03/19/monitor-changes-made-to-the-htaccess-file/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 09:59:46 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/?p=108</guid>
		<description><![CDATA[After what happened to &#8220;Grandad&#8221;  @ Head Rambles recently, got me thinking in finding a way to monitor any changes made to the .htaccess file. Grandad&#8217;s .htaccess file, was injected with some malicious code, checking for the USER_AGENT, in turn redirecting &#8220;Googlebot, Slurp, msnbot&#8221; to another website. This can be easily achieved as the server itself  updates [...]]]></description>
			<content:encoded><![CDATA[<p>After what happened to &#8220;Grandad&#8221;  @ <a href="http://www.headrambles.com/" target="_blank">Head Rambles</a> recently, got me thinking in finding a way to monitor any changes made to the .htaccess file.</p>
<p>Grandad&#8217;s .htaccess file, was injected with some malicious code, checking for the USER_AGENT, in turn redirecting &#8220;Googlebot, Slurp, msnbot&#8221; to another website.</p>
<p>This can be easily achieved as the server itself  updates the date &amp; time of the file/s changed by adding a timestamp to it.<br />
Keeping track is not that hard, once we have this value stored for later comparison.</p>
<p>The solution I came up with, is to create a directory where a new text file is created, which in turn will store the existing file timestamp.</p>
<p>With a bit of PHP coding, we can read the contents of the text file created and compare it with the existing timestamp of the file itself.<br />
If the current timestamp is not equal to what we have stored, an ALERT email will be sent to the website administrator, who can verify the content of the file itself, making sure no malicious changes were made as per example given above.</p>
<p>The code can be downloaded from <a title="donwload file" href="http://www.eire-webdesign.ie/_monitor_htaccess.txt" target="_blank"><strong>here &gt;&gt;</strong></a></p>
<p>and please let me know if you encounter any problems&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2009/03/19/monitor-changes-made-to-the-htaccess-file/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Debugging Live Website</title>
		<link>http://www.eire-webdesign.ie/blog/2008/04/03/debugging-live-website/</link>
		<comments>http://www.eire-webdesign.ie/blog/2008/04/03/debugging-live-website/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 18:15:23 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[debugging SQL]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/2008/04/03/debugging-live-website/</guid>
		<description><![CDATA[Debugging a live website it&#8217;s a pain in the neck, especially if you are working on changing database queries. You can&#8217;t &#8220;echo&#8221; the SQL query to find out how is formatted and why the result are not the right ones, but you CAN &#8220;Email&#8221; it to yourself and check it out when it arrives in [...]]]></description>
			<content:encoded><![CDATA[<p>Debugging a live website it&#8217;s a pain in the neck, especially if you are working on changing database queries.<br />
You can&#8217;t &#8220;echo&#8221; the SQL query to find out how is formatted and why the result are not the right ones, but you CAN &#8220;Email&#8221; it to yourself and check it out when it arrives in your inbox.</p>
<p>This is exactly what the php function below will do:<br />
( just change the <a href="mailto:myemail@server.com">myemail@server.com</a> to your email address )</p>
<pre lang="php">
function ewd_email_sql($sSql){  $my_email = "myemail@server.com";//set your email address

  $my_subject = "SQL Query Email";//email subject

  $my_message = !empty($sSql) ? $sSql : "SQL Query was empty";

  $my_ip = ""; //enter your IP ADDRESS to make sure you only send the email when you view this page

$mime_boundary = "&lt;&lt;&lt;--==+X[".md5(time())."]\r\n\r\n";// Generate a boundary string

  $headers = "From:".$my_email."\r\n".

                "To:".$my_email."\r\n".

                 "MIME-Version: 1.0\r\n" .

                 "Content-Type: text/plain;\r\n".

                 "boundary=\"".$mime_boundary."\"\r\n";

  if(!empty($my_ip) &amp;&amp; $_SERVER['REMOTE_ADDRESS'] == $my_ip){

    mail($my_email,$my_subject,$my_message,$headers);

  }

  return;

}

//usage e.g

$sSql = "SELECT * FROM table_name WHERE something='".addslashes("something_else")."'";

  //email it

  ewd_email_sql($sSql);//call function

..............

//rest of the code below</pre>
<p>Hope it helps&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2008/04/03/debugging-live-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sitemap generator class</title>
		<link>http://www.eire-webdesign.ie/blog/2008/02/21/sitemap-generator-class/</link>
		<comments>http://www.eire-webdesign.ie/blog/2008/02/21/sitemap-generator-class/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 10:44:34 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[sitemap generator class]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/2008/02/21/sitemap-generator-class/</guid>
		<description><![CDATA[This php class will help you generate a sitemap for your website automatically. // sitemap generator class class Sitemap{  // constructor receives the list of URLs to include in the sitemap   function Sitemap($items = array()){   $this-&#62;_items = $items;   } // add a new sitemap item   function addItem($url, $lastmod = '', $changefreq [...]]]></description>
			<content:encoded><![CDATA[<p>This php class will help you generate a sitemap for your website automatically.</p>
<pre lang="php">
// sitemap generator class
class Sitemap{  // constructor receives the list of URLs to include in the sitemap  

  function Sitemap($items = array()){  

    $this-&gt;_items = $items;  

  } // add a new sitemap item  

  function addItem($url, $lastmod = '', $changefreq = '', $priority = '', $additional_fields = array()){  

  $this-&gt;_items[] = array_merge(array('loc' =&gt; $url, 'lastmod' =&gt; $lastmod,'changefreq' =&gt; $changefreq,'priority' =&gt; $priority), $additional_fields);  

  }  

// get Google sitemap  

  function getGoogle(){  

    ob_start();  

    header('Content-type: text/xml');  

    echo '<!--l version="1.0" encoding="UTF-8-->';  

    echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"></urlset>';  

  foreach ($this-&gt;_items as $i){  

      echo '<url></url>';  

  foreach ($i as $index =&gt; $_i){  

        if (!$_i) continue;  

  echo "&lt;$index&gt;" . $this-&gt;_escapeXML($_i) . "";  

      }  

      echo '';  

    }  

    echo '';  

    return ob_get_clean();  

  }  

// get Yahoo sitemap  

 function getYahoo(){  

 	ob_start();  

 	header('Content-type: text/plain');  

  foreach ($this-&gt;_items as $i){  

 		  echo $i['loc'] . "\n";  

 		}  

 	return ob_get_clean();  

 }  

// escape string characters for inclusion in XML structure  

 function _escapeXML($str){  

 	$translation = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);  

  foreach ($translation as $key =&gt; $value){  

  $translation[$key] = '&amp;#' . ord($key) . ';';  

 		}  

  $translation[chr(38)] = '&amp;';  

  return preg_replace("/&amp;(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&amp;" , strtr($str, $translation));  

 }  

}</pre>
<p>Usage:</p>
<pre lang="php">
$s = new Sitemap(); 
 $s-&gt;addItem("http://www.websiteurl.com", date("Y-m-d"), 'weekly', '1.0');  

 $s-&gt;addItem("http://www.websiteurl.com/link2", date("Y-m-d"), 'weekly', '1.0');  

 $s-&gt;addItem("http://www.websiteurl.com/link3", date("Y-m-d"), 'weekly', '1.0');</pre>
<p>This class can create two type of sitemaps for you &#8211; XML for Google and TEXT for Yahoo</p>
<pre lang="php">
if(isset($_GET['target'])){  

  if(($target = $_GET['target']) == 'google'){  

  echo $s-&gt;getGoogle();//xml sitemap  

  }elseif($target == 'yahoo'){  

  echo $s-&gt;getYahoo();//txt sitemap  

  }  

}</pre>
<p>This class wasn&#8217;t designed by me but by Jaimie Sirovich &amp; Cristian Darie and the reason I put it up here is to help others that are trying to get this done without the headache of creating a new code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2008/02/21/sitemap-generator-class/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>URL rewrite tips and solutions</title>
		<link>http://www.eire-webdesign.ie/blog/2007/12/07/url-rewrite-tips-and-solutions/</link>
		<comments>http://www.eire-webdesign.ie/blog/2007/12/07/url-rewrite-tips-and-solutions/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 11:53:54 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[url rewrite]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/2007/12/07/url-rewrite-tips-and-solutions/</guid>
		<description><![CDATA[Due to server setup and having no access to the php.ini file to change your server settings, we will resume to the .htaccess file for rewriting the URL, removing or adding the www. and removing the PHPSESSID from the URL itself to prevent duplicated content into the Search Engines, so here are few tips to [...]]]></description>
			<content:encoded><![CDATA[<p>Due to server setup and having no access to the php.ini file to change your server settings, we will resume to the .htaccess file for rewriting the URL, removing or adding the www. and removing the PHPSESSID from the URL itself to prevent duplicated content into the Search Engines, so here are few tips to get you started:</p>
<p>First lets create a new file and name it .htaccess (only if you don&#8217;t already have one), and ad the following lines at the very top:</p>
<pre lang="php">
Options +FollowSymlinks
RewriteEngine on
RewriteBase /</pre>
<p>Now we are going to check the URL making sure the www. is always there otherwise we will redirect to the right format URL:</p>
<pre lang="php">
# redirect if not www
RewriteCond %{HTTP_HOST} !^(www)\.domain-name\.ie  

RewriteRule ^(.*)$ http://www.domain-name.ie/$1 [R=301,L]</pre>
<p>Now lets redirect the index.php or .html to the main URL as this creates duplicated content as well:</p>
<pre lang="php">
#redirect index.php or htm to /
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(htm|html|php)\ HTTP  

RewriteRule ^(.*)index\.(htm|html|php)$ /$1 [R=301,L]</pre>
<p>Depending on your server settings, sometimes the PHPSESSID get attached to the end of your URL, which will also created duplicated content, so there is a solution written in php that will check for the PHPSESSID query-string and if found, we will remove it and do a 301 Permanent Redirect to the same page but without it:</p>
<pre lang="php">
//remove session id from url  

if (!empty($_GET['PHPSESSID'])) {  

  $clean_uri = preg_replace('/?PHPSESSID=[^&amp;]+/','',$_SERVER['REQUEST_URI']);  

  $clean_uri = preg_replace('/&amp;PHPSESSID=[^&amp;]+/','',$clean_uri );  

    header('HTTP/1.1 301 Moved Permanently');  

  header('Location: http://'.$_SERVER['HTTP_HOST'] . $clean_uri );  

    exit();  

}  

//</pre>
<p>Please Note: The above solution is not part of the .htaccess file, but has to be added to a common include file available across the site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2007/12/07/url-rewrite-tips-and-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sanitize input from forms or database with php</title>
		<link>http://www.eire-webdesign.ie/blog/2007/11/01/sanitize-input-from-forms-or-database/</link>
		<comments>http://www.eire-webdesign.ie/blog/2007/11/01/sanitize-input-from-forms-or-database/#comments</comments>
		<pubDate>Thu, 01 Nov 2007 15:42:48 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[sanitize input received]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/2007/11/01/sanitize-input-from-forms-or-database/</guid>
		<description><![CDATA[Very often a  website developers has to deal with user input, and if not sanitized properly could break the code or insert malicious code into your database. By creating customised functions, a website developer&#8217;s job, could be made a lot easier and it&#8217;s very handy for doing updates to your code. This function is something I designed, and [...]]]></description>
			<content:encoded><![CDATA[<p>Very often a  <a href="http://www.eire-webdesign.ie/web-development.html" title="website developers">website developers</a> has to deal with user input, and if not sanitized properly could break the code or insert malicious code into your database.<br />
By creating customised functions, a <a href="http://www.eire-webdesign.ie/web-development.html" title="website developing">website developer&#8217;s job</a>, could be made a lot easier and it&#8217;s very handy for doing updates to your code.</p>
<p>This function is something I designed, and will allow you to sanitize your input either coming from a form on your website or a database table before doing anything with it like send an email, display it on the website or do an update / insert to a db table.</p>
<pre lang="php">
//function to sanitise user input
//preventing sql errors and code breaking 

// [1] = numbers     

// [2] = small letters     

// [3] = caps letters     

// [4] = other characters that are included between the [4 ] brackets (e.g. [4.,@-_ ])     

//notice last gap for spaces     

// ' " \ / needs a \ in front like : \' and \" and \\ and \/    

function ewd_sanitize($input, $format){ 

 if($input == ""){     

  return;     

 }else{     

  //prepare characters to be kept     

  $ewd_keep = '#[^'; 

  $ewd_keep .= stristr($format,'[1]') ? '0-9' : '';//allow digits 

  $ewd_keep .= stristr($format,'[2]') ? 'a-z' : '';//allow small letters 

  $ewd_keep .= stristr($format,'[3]') ? 'A-Z' : '';//allow caps letters 

  //other     

  if(stristr($format,'[4')){ 

   $pattern = "/(\[4)(.*?)(\])/"; //match the 4th bracket and get the characters     

   preg_match($pattern, $format, $matches);     

   $ewd = $matches[2]; 

   $ewd_keep .= stristr($ewd,' ') ? ' ' : '';//allow spaces 

   $ewd_keep .= stristr($ewd,'.') ? '\.' : '';//allow dot 

   $ewd_keep .= stristr($ewd,'@') ? <a href="mailto:'@'">'@'</a> : '';//allow @ symbol     

   $ewd_keep .= stristr($ewd,'"') ? '\"' : '';//allow " 

   $ewd_keep .= stristr($ewd,"'") ? "\'" : '';//allow ' 

   $ewd_keep .= stristr($ewd,'-') ? '\-' : '';//allow - dash 

   $ewd_keep .= stristr($ewd,'_') ? '\_' : '';//allow _ underscore 

   $ewd_keep .= stristr($ewd,'(') ? '\(' : '';//allow ( open bracket 

   $ewd_keep .= stristr($ewd,')') ? '\)' : '';//allow ) closing bracket 

   $ewd_keep .= stristr($ewd,'\\') ? '\\\\' : '';//allow \ 

   $ewd_keep .= stristr($ewd,'/') ? '\/' : '';//allow / 

  }     

  $ewd_keep .= ']#'; 

  $input = preg_replace($ewd_keep,'',$input); 

 }     

 return $input;     

}</pre>
<p>Example how to use it in your code:</p>
<pre lang="php">
//this will allow most characteres 

echo ewd_sanitize("checking this text(123) @. O'Connel \/", "[1][2][3][4@.-()\'\\\\/ ]");
//numbers only     

echo ewd_sanitize("checking this text(123) @. O'Connel \/", "[1]"); 

//small letter only     

echo ewd_sanitize("check this Out 123","[2]"); 

//all letters and numbers     

echo ewd_sanitize("check this Out Now 123","[1][2][3]"); 

//allow an email     

echo ewd_sanitize("info@domain-name.com","[1][2][3][4@.-_]");</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2007/11/01/sanitize-input-from-forms-or-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP create form fields</title>
		<link>http://www.eire-webdesign.ie/blog/2007/10/19/php-create-form-fields/</link>
		<comments>http://www.eire-webdesign.ie/blog/2007/10/19/php-create-form-fields/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 20:22:29 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP create form fields function]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/2007/10/19/php-create-form-fields/</guid>
		<description><![CDATA[The other day I was looking for a solution to help me create a form without the hassle to check it again and again for missing arguments or miss-typing. Because i couldn&#8217;t find any ready made solutions I created this little function that made my life less miserable. I hope it could be useful to [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was looking for a solution to help me create a form without the hassle to check it again and again for missing arguments or miss-typing.<br />
Because i couldn&#8217;t find any ready made solutions I created this little function that made my life less miserable.</p>
<p>I hope it could be useful to you too.</p>
<pre lang="php">
/*
$ewd_type - could be text, password, submit, hidden, textarea or select
$ewd_name - the name and id of the input filed
$ewd_value - input value default or returned by post
$ewd_size - the size of the input type text
$ewd_cols - number of colums for the textarea type field - default = 30
$ewd_rows -  number of rows for the textarea type field - default = 6
*/    

function ewd_make_form_field($ewd_type,$ewd_name,$ewd_value='',$ewd_size='',$ewd_cols='',$ewd_rows=''){    

 global $_POST;
 $ewd_size = $ewd_size != "" ? $ewd_size : 30;
 $ewd_cols = $ewd_cols != "" ? $ewd_cols : 30;
 $ewd_rows = $ewd_rows != "" ? $ewd_rows : 6;
     

 switch ($ewd_type) {
  case "text":
   echo "&lt;input type='$ewd_type' name='$ewd_name' id='$ewd_name' size='$ewd_size' value='$ewd_value' onfocus='this.style.borderColor=\"#0072BC\";' onblur='this.style.borderColor=\"silver\";' /&gt;";
   break;
  case "password":
   echo "&lt;input type='$ewd_type' name='$ewd_name' id='$ewd_name' size='$ewd_size' value='$ewd_value' /&gt;";
   break;
  case "textarea":
   echo "&lt;textarea name='$ewd_name' id='$ewd_name' cols='$ewd_cols' rows='ewd_rows'&gt;$ewd_value&lt;/textarea&gt;";
   break;
  case "submit":
   echo "&lt;input type='$ewd_type' name='$ewd_name' id='$ewd_name' value='$ewd_value' /&gt;";
   break;
  case "hidden":
   echo "&lt;input type='$ewd_type' name='$ewd_name' id='$ewd_name' value='$ewd_value' /&gt;";
   break;
  case "select":
   echo "&lt;select name='$ewd_name' id='$ewd_name'&gt; 
     &lt;option value=''&gt;Please Select&lt;/option&gt;";
     $ewd_y_value = explode(" ",$ewd_value);
     foreach ($ewd_y_value as $ewd_word) {
     echo "&lt;option value='$ewd_word'";
      if($ewd_word == trim($_POST[$ewd_name])){
       echo " selected='selected'";
      }
     echo "&gt;".$ewd_word."&lt;/option&gt;";
     }    

   echo "&lt;/select&gt;";
   break;
  default:
   echo "&lt;input type='text' name='$ewd_name' id='$ewd_name' size='$ewd_size' value='$ewd_value' /&gt;";
 }
}</pre>
<p>Method for using the above function:</p>
<pre lang="php">
&lt;form method="post" action="&lt;?php $_SERVER['REQUEST_URI'];?&gt;" name="x_form" id="x_form"&gt;
 &lt;table summary="some form"&gt;
  &lt;tr&gt;
   &lt;td colspan="2" style="background-color:#f5f5f5; padding:3px;"&gt;
    &lt;b&gt;About yourself&lt;/b&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Name:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('text','name',isset($_POST['name']) ? $_POST['name'] : '');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Surname:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('text','surname',isset($_POST['surname']) ? $_POST['surname'] : '');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Email:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('text','email',isset($_POST['email']) ? $_POST['email'] : '');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Phone:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('text','phone',isset($_POST['phone']) ? $_POST['phone'] : '');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Type of Sale:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('select','sale_type','Private Garage Both');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td valign="top"&gt;Extra details:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('textarea','additional',isset($_POST['additional']) ? $_POST['additional'] : '');?&gt;(eg. Engine cc: 1.1 to 1.4)&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td colspan="2" align="center"&gt;
    &lt;?php ewd_make_form_field('submit','submit','Send');?&gt;
    &lt;?php ewd_make_form_field('hidden','country','Ireland');?&gt;
   &lt;/td&gt;   
  &lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2007/10/19/php-create-form-fields/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Image Uploading-Resizing</title>
		<link>http://www.eire-webdesign.ie/blog/2007/10/18/php-image-uploading-resizing/</link>
		<comments>http://www.eire-webdesign.ie/blog/2007/10/18/php-image-uploading-resizing/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 18:21:46 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php image resize]]></category>
		<category><![CDATA[uploading images]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/2007/10/18/php-image-uploading-resizing/</guid>
		<description><![CDATA[The other day I was on the look out for a solution to speed up the process of uploading images on the server. We had the code in place already, and everything was running smooth (resizing, thumbnail creation), but there was just one problem when the user will upload something over 1024 x 800. It [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was on the look out for a solution to speed up the process of <strong>uploading images</strong> on the server.<br />
We had the code in place already, and everything was running smooth (<strong>resizing, thumbnail creation</strong>), but there was just one problem when the user will upload something over <strong>1024 x 800</strong>.<br />
It was taking too long and the user will either get a server error, or just run out of patients, cancelling the upload or just close the browser.</p>
<p>Dealing with users that have no knowledge of adjusting the digital camera to take o lower quality / size picture, or just they don&#8217;t want to or&#8230;, made me think.<br />
I needed a solution that will not break apart in the middle of doing its job, will be fast and doesn&#8217;t require too much of my time.<br />
<strong>So looking at what I have.<br />
</strong>  <strong>1.</strong> 1 x products table<br />
  <strong>2.</strong> 1 x product images table, related to the products table by product id<br />
  <strong>3.</strong> 1 x folder that stores the images</p>
<p><strong>So the solution I came up with was:<br />
</strong>  <strong>1.</strong> Duplicate product images table and add an extra field (status, 1=done, 0 = to be processed)<br />
  <strong>2.</strong> Create a new folder to store the temporary images<br />
  <strong>3.</strong> When the user uploads an image, we store the details into the duplicated table, and upload the image into the temporary folder without doing any work on them.<br />
  <strong>4.</strong> Create a new page that will look into the duplicated table, gets all the records where the status=0, then using while&#8230; statement, the following work was carried out:<br />
    <strong>a. </strong>get the record details, store them into variables<br />
    <strong>b.</strong> get the image path, check to see if the image exist in the temp folder<br />
    <strong>c. </strong>check the size of the current image (we need to resize it to 800px, then again create thumbnail of 100px and ad small_ to the image name)<br />
    <strong>d.</strong> save the images into the right folder this time<br />
    <strong>e.</strong> add the record into the product images table <br />
    <strong>f.</strong> delete the original image from the temporary folder, we don&#8217;t need it anymore<br />
    <strong>g.</strong> update the old record into the database as 1=done <br />
    <strong>h.</strong> send email of how many images has been processed.</p>
<p>Now everything looked good. Run few tests and it was all OK.</p>
<p><strong>The problem:</strong><br />
  <strong>1.</strong> the page had to be called manually, by clicking on a link or typing the URL into the address bar in IE or FF<br />
  <strong>2.</strong> call the page using an include statement into the home page (not really a solution)</p>
<p><strong>The solution:<br />
</strong>  <strong>1.</strong> I was so tired, just didn&#8217;t came to me at all, so i dropped everything and went to get myself a strong cup of coffee, when I clicked &#8211; <strong>CRON JOB </strong><br />
so by setting up a <strong>cron job</strong> to run every 5min. the job becomes automated.<br />
I get an email if anything has been processed so I could if I want to, check it out. If no images are processed, no email arrives so I don&#8217;t give myself too much work, deleting emails &#8211; what&#8217;s the point of doing all that work for? </p>
<p>Hope this helps others as much as it helped me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2007/10/18/php-image-uploading-resizing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Friendly SQL Error message</title>
		<link>http://www.eire-webdesign.ie/blog/2007/10/18/php-friendly-sql-error-message/</link>
		<comments>http://www.eire-webdesign.ie/blog/2007/10/18/php-friendly-sql-error-message/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 18:12:34 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php mysql error]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/2007/10/18/php-friendly-sql-error-message/</guid>
		<description><![CDATA[No matter how much you try there will always be the day when you make a mistake in your sql accessing the database. Sometimes queries are based on some sort of session which, if it times-out the next query to the database will show an error instead of getting the result expected. Sometimes the query [...]]]></description>
			<content:encoded><![CDATA[<p>No matter how much you try there will always be the day when you make a mistake in your sql accessing the database.<br />
Sometimes queries are based on some sort of session which, if it times-out the next query to the database will show an error instead of getting the result expected. Sometimes the query comes from an old page in the Search Engines, the possibilities are unlimited.<br />
Showing a Sql error to the visitor, could mean a lost customer, giving out too much details that are not meant to be seen, etc&#8230;</p>
<p>The biggest problem is &#8220;<strong>How do you know you have made a mistake?</strong>&#8221;</p>
<p>The solution is to send yourself an email when that happens and instead of the error message displayed on the page, you can write a nice message to the visitor that he will accept quicker then &#8220;<strong>The page can not be displayed</strong>&#8220;. <br />
Not many visitors knows how to go back to your Home Page if there are no links that will redirect them there.</p>
<p>There is a simple example bellow that will do just that.</p>
<pre lang="php">function ewd_db_connect($HOST,$USER,$PASS,$DB) {
 $conn = @mysql_connect($HOST, $USER, $PASS) or die(ewd_error($sSql="No Connection to the database"));
 @mysql_select_db($DB) or die(ewd_error($sSql="No Connection to the database"));
 return $conn;
}  

function ewd_db_close($conn){
 mysql_close($conn);
}
function ewd_query($strsql,$conn) {
 $rs = mysql_query($strsql,$conn);
return $rs;
}
function ewd_num_rows($rs) {
 return @mysql_num_rows($rs);
}
function ewd_fetch_array($rs) {
 return mysql_fetch_array($rs);
} function ewd_free_result($rs) {
 @mysql_free_result($rs);
}
function ewd_data_seek($rs,$cnt) {
 @mysql_data_seek($rs, $cnt);
}     

#this is where the fun begins
#if we get a sql error, will show a friendly message then email the error to the webmaster or yourself 

function ewd_error($sSql) {
 echo "We have encounter a problem accessing the database. An email has been send to the Administrator.\n
 We hope to bring the website back on line very soon.\n
 To go back to the home page Click Here (link to your home page)";
 #send email
 $to = "your_email_address";
 $subject = "Error on Website name";
 $headers = "Content-type: text/plain\r\n";
 $body = "Connection Error:". mysql_error();
 $body.="\n\n\nSql Error: ".$sSql;
 $body.="\n\n\nPage: ".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
 $body.="\n\n\nReferer".$_SERVER['HTTP_REFERER']."\n\nIP Address: " .$_SERVER['REMOTE_ADDR'];
 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
   ini_set("SMTP","localhost");
   ini_set("smtp_port","25");
 }
  #send email
  mail($to, $subject, $body, $headers);
}
//define your connection settings 

define("HOST", "localhost"); //domain
define("USER", "user_name"); //user name
define("PASS", "password"); //password
define("DB", "database_name"); //database name  

// Open connection to the database
$conn = ewd_db_connect(HOST, USER, PASS,DB);</pre>
<p>Example how to use it:</p>
<pre lang="php">

$sSql= " Select , Update, Insert statement here ";
$rs = ewd_query($sSql,$conn) or die(ewd_error($sSql)); //this is where the magic happens
if (ewd_num_rows($rs) &gt; 0){
  while($row = ewd_fetch_array($rs)){//do the loop
    //...display data
    //....................................................................................
    //....................................................................................
  } //end while
} //end if
ewd_free_result($rs); // free rs
ewd_db_close($conn);//close connection</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2007/10/18/php-friendly-sql-error-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
