Edmonds Commerce : Web Development, Design, SEO

Archive for the 'php' Category

Ultimate osCommerce Checkout - Fast and Friendly

Wednesday, July 2nd, 2008

I have recently completed the second stage of development for my ultimate oscommerce checkout system. This is a replacement for the standard osCommerce checkout which splits into numerous stages, meaning that to actually place an order meant visiting about 5 different pages.

My system rolls every single stage into a single page for entering details and a subsequent confirmation page simply to allow the customer to double check the details.

I have now finished adding full and detailed AJAX error checking so that as the customer fills out the fast checkout page, their input is checked and validated. If their input is OK the input box turns green, otherwise it turns pinky-red and a red error message box displays telling them exactly what the problem is.

This means that it will be nearly impossible for a customer’s checkout process to be complicated by breaking one of the oscommerce character limits or making some other error.

If you want your osCommerce checkout to be as fast and userfriendly as possible then you need to sign up for:

Edmonds Commerce Ultimate osCommerce Checkout

Here are a few screen shots of the system running on a client site.

Existing Customer Login

validates email address and checks that the email address is registered

Existing Customer

Validates Inputs

Validates email addresses to help prevent typos and also checks that double entry of email or password matches up.

validate email

Set Account, Shipping and Billing Address in One Page

The Fast Checkout system automatically defaults the shipping and billing address to the acccount address. If the customer wants to set another address for either of these, an expandable section allows them to enter a new address or select an existing address book entry. Incorporates full AJAX error checking.

shipping billing address

Price

This system can be set up on your site for £997. If you are interested in having the ultimate checkout experience and ensuring that you convert the maximum amount of baskets then get in touch with Edmonds Commerce today.

PHP Email Attachment Function

Friday, June 20th, 2008

Sending an email with PHP is pretty straight forwards. It's very useful for emailing reports generated from cron jobs etc.

Sometimes though you need your application to email an attachment.

After a load of messing around I have hacked together this email attachment PHP function.

PHP:
  1. function email_attachment($to_email, $email, $subject,$our_email_name, $our_email, $file_location, $default_filetype='application/zip'){
  2.     $email = '<font face="arial">' . $email . '</font>';
  3.     $fileatt = $file_location;
  4.     if(function_exists(mime_content_type)){
  5.         $fileatttype = mime_content_type($file_location);
  6.     }else{
  7.         $fileatttype = $default_filetype;;
  8.     }
  9.     $fileattname =basename($file_location);
  10.     //prepare attachment
  11.     $file = fopen( $fileatt, 'rb' );
  12.     $data = fread( $file, filesize( $fileatt ) );
  13.     fclose( $file );
  14.     $data = chunk_split( base64_encode( $data ) );
  15.     //create mime boundary
  16.     $semi_rand = md5( time() );
  17.     $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  18.     //create email  section
  19.     $message = "This is a multi-part message in MIME format.\n\n" .
  20.     "--{$mime_boundary}\n" .
  21.     "Content-type: text/html; charset=us-ascii\n" .
  22.     "Content-Transfer-Encoding: 7bit\n\n" .
  23.     $email . "\n\n";
  24.      //create attachment section
  25.     $message .= "--{$mime_boundary}\n" .
  26.      "Content-Type: {$fileatttype};\n" .
  27.      " name=\"{$fileattname}\"\n" .
  28.      "Content-Disposition: attachment;\n" .
  29.      " filename=\"{$fileattname}\"\n" .
  30.      "Content-Transfer-Encoding: base64\n\n" .
  31.      $data . "\n\n" .
  32.      "--{$mime_boundary}--\n";
  33.      //headers
  34.     $exp=explode('@', $our_email);
  35.     $domain = $exp[1];
  36.     $headers = "From: $our_email_name<$our_email>" . "\n";
  37.     $headers .= "Reply-To: $our_email"."\n";
  38.     $headers .= "Return-Path: $our_email" . "\n";    // these two to set reply address
  39.     $headers .= "Message-ID: <".time()."@" . $domain . ">"."\n";
  40.     $headers .= "X-Mailer: Edmonds Commerce Email Attachment Function"."\n";          // These two to help avoid spam-filters
  41.     $headers .= "Date: ".date("r")."\n";
  42.     $headers .= "MIME-Version: 1.0\n" .
  43.                     "Content-Type: multipart/mixed;\n" .
  44.                     " boundary=\"{$mime_boundary}\"";
  45.     
  46.     mail($to_email,$subject,$message, $headers, '-f ' . $our_email) or die ('<h3 style="color: red;">Mail Failed</h3>');
  47. }

The PHP and Email Journey Continues :-)

For a fully featured email attachment class this is definitely worth checking out. If you just want a quick function though without any bells and whistles then you should find my function will do the trick.

Get Name from Email Address

Wednesday, June 11th, 2008

Check out this simple and easy function for extracting the name from an email address. It's not very advanced but it is quite handy. Of course it could be used for similar applications by simply changing the character to split on.

PHP:
  1. function email_name($email_address, $split='@'){
  2.     return ucwords(strtolower(substr($email_address, 0, strripos($email_address, $split))));
  3. }

There are some very powerful things you can do with PHP and email. Check out this POP3 email class for some ideas. I am just starting to scratch the surface of this functionality and will doubtless have some more great things to show soon.

Freelance osCommerce UK

Monday, June 9th, 2008

It seems that there are many UK webmasters who struggle to find a reliable UK based web developer who specialises in PHP. I have heard stories of people who claim to be osCommerce experts but in reality they simply know how to install a few contributions and that's about it.

If you are looking for a freelance osCommerce developer, especially if you would prefer to deal with someone else in the United Kingdom then you would do well to get in touch with me. I now have a long list of happy clients who have had their osCommerce sites improved, speeded up and automatically populated with huge catalogues.

So to clarify. Edmonds Commerce is a Freelance web developer who specialise in osCommerce and is UK Based.

PHP Random Sleep Function with Flush

Monday, June 9th, 2008

Sometimes you want your script to pause for a short period of time before repeating a loop or proceeding to the next step. This may be to reduce server load or even to simulate the natural pauses that a person would make whilst browsing a site. This kind of thing is especially true if you are building a system to scrape content such as product information from a suppliers web site and you do not want to hammer their server to death and get your IP banned.

PHP:
  1. function sleep_flush($chunks=10){
  2.  
  3.     $c=0;
  4.  
  5.     while($c <$chunks){
  6.  
  7.        $rand = rand(2000000, 6000000);
  8.  
  9.        echo '<br> . . . sleeping for ' . round(($rand / 1000000),2) . ' seconds . . . zzzzzzzzzzzzzz<br>';
  10.  
  11.        flush();
  12.  
  13.        usleep($rand);
  14.  
  15.        $c++;
  16.  
  17.     }
  18.  
  19. }

This function will do just that for you. Also it has a built in flush which will help in preventing the script from being regarded as timed out if you are running it from the web browser.

PHP 301 Redirect Function with Headers Check and Javascript Fallback

Thursday, May 22nd, 2008

If you are changing your URL structure, for example when moving to a search engine friendly URLs system, you need to be able to let Google and all the other search engines that the page has moved to the new URL. You really don't want to display the same content on two URLs

So to achieve this we can do what is called a 301 redirect. This is a special redirect message which basically says "has permanently moved to". By doing this, all of the search engine power, rank or whatever you want to call it will be directly transferred to the new URL.

However

Sometimes your script might spit out the headers earlier than you expect. If this happens then your site will fail completely to load with a fatal error along the lines of

warning: Cannot modify header information - headers already sent by (output started at ....

We really don't want this to happen, so what we can do is wrap the redirection in a headers_sent check and then fall back to a javascript redirect if headers have been sent for some reason. This is belt and braces logic.

Note script tags need spaces removing

PHP:
  1. function requrl_check($correct_url, $delay=3){
  2.     $request_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  3.     if($request_url != $correct_url){
  4.         if(!headers_sent()){ //going to assume that headers are not sent
  5.         header("HTTP/1.1 301 Moved Permanently");
  6.           header('location: ' . $correct_url . '');
  7.           exit();
  8.        }else{
  9.           echo "<h3>The Page $request_url has Moved</h3>
  10.          <a href=$correct_url>$correct_url</a>";
  11.           echo '<h3>Now Refreshing in ' . $delay . ' Seconds</h3>Refreshing to:<br>' . $correct_url . '<s c r i p t type="text/JavaScript"><!--
  12.         setTimeout("location.href = \'' . $correct_url . '\';",' . ($delay * 1000) . ');
  13.         --> </s c r i p t>';
  14.             exit();
  15.         }
  16.     }
  17. }

tidy :-)

Further Reading:
www.stuntdubl.com
www.intertwingly.ne
webgasm.actiononline.biz
www.techcounter.com
www.chiropractichomepage.com
123howtoguide.com
searchblog.tamar.com

PHP Generated SQL

Wednesday, May 21st, 2008

If you find yourself laboriously building SQL queries by typing each field = 'value' statement... think again.

Imagine this:

PHP:
  1. $sql_query = mysql_query("select * from table");
  2.  
  3. $insert_elsewhere_sql = "INSERT INTO other_table SET ";
  4.  
  5. while($s = mysql_fetch_assoc($sql_query)){
  6.     foreach($s as $k=>$v){
  7.     $insert_elsewhere_sql .= "$k = '$v', ";
  8. }
  9.  
  10. $insert_elsewhere_sql = substr($insert_elsewhere_sql, 0, -2);

This will generate a valid SQL insert statement with all of your field, value pairs set up.

Time saver or what?

Purashop : SEO Services

Wednesday, May 14th, 2008

I am right in the middle of a big SEO overhaul for purashop who have been good clients of mine for a while now.

My initial project for them was a fast checkout system. Getting rid of the standard osCommerce checkout procedure and rolling it all up into a single page which is loads faster, easier to use and much more customer friendly.

They have recently asked me to help them out with their search engine optimisation. The first thing I have done is install my bespoke SEO URLs system. This includes product, category and manufacturer SEO URLs. It even includes SEO page urls, no .html?page= for these guys, it's a full static looking URLs system and runs with even less server load than the original oscommerce.

This is a major contrast with the Edmonds Commerce approach to SEO URLs compared with other systems out there. I have seen people who are using systems which dynamically preg_replace every single URL after it has already been generated, adding a huge amount of server load.

The extra icing on the cake though is the SEO URLs search system combined with a search logging system and a popular searches page. This page is excellent as it is not only a nice resource for customers, but is incredibly search engine friendly. As the content is dictated by the searches performed on the site, the page constantly keeps itself up to date with the latest trends and will constantly optimise their site for the most relevant and active topics of the moment.

I am continuing to tweak and improve their SEO package and have high hopes for a marked improvement in traffic in the not too distant future.

Flash and PHP Charts and Graphs

Wednesday, May 14th, 2008

It is entirely possible and easy enough to create all kinds of charts and graphs using only PHP along with the GD library.

These days PHP is generally compiled with the GD library enabled so it is highly likely that you already have access to it. It is a powerful system, unfortunately often only used for creating thumbnail images.

For building management information systems with real time generated graphs there are some excellent classes available which will help you display information in a graphical and therefore easier to understand manner.

Checkout these great free graph classes:

Class: Google Graph
Class: Bar Graph generator
Class: Graph Drawing Class 2

However, sometime the graphics produced by GD simply are not flash enough for your application.

When you want something really flashy on your web site then you really can't go wrong using flash.

There are a few flash graph packages you can purchase online for not too much cash. However if you prefer to keep it all open source then I highly recommend checking out this open source flash graph class.

Open Flash Chart project

Further Reading:

noteplog.com
bivald.com
blogs.sun.com
www.webappers.com
blogulate.com
www.linewbie.com
hotware.wordpress.com
wordpress.designpraxis.at
www.stat.columbia.edu

Plesk Web Fusion PHP Limits

Friday, April 25th, 2008

While recently migrating a client from a dedicated server which was proving a little too expensive over to one of the great value Linux Virtual Private Servers offered by Web Fusion, I found myself frustrated with the 2mb upload limit apparent in the control panel side of things.

So I went and edited the php.ini to allow for a more generous upload limit. Restarted the server but to no effect.

After a closer inspection I realised that the Plesk control panel actually had its own separate php.ini file. Edited this file and it works.

Another Problem Solved :-)