Edmonds Commerce Logo
  • home
    • blog
  • ecommerce
    • product catalogue
    • order processing
    • customer services
    • stock control
    • human resources
    • management information
  • development
    • oscommerce
    • php
    • mysql
    • open source
    • performance tuning
  • design
  • marketing
  • contact us
    • pricing

Edmonds Commerce Blog

Freelance PHP Ecommerce and SEO Developer in the UK

Latest Posts

Securing a LAMP Server with mod_security
osCommerce Easypopulate File Creator Class
CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc

Most Popular Posts

PHP Email Attachment Function Freelance osCommerce UK Ultimate osCommerce Checkout - Fast and Friendly PHP : Dead Easy Excel Export

Archive for February, 2008

Next Entries »

EAN13 Barcode Check Digit with PHP

Friday, February 15th, 2008

EAN13 is a barcode format. It consists of 12 numbers which you will generally have a range assigned to you. The 13th digit is called the check digit and is formulated by loooking at the other 12 digits. The purpose of the check digit is to ensure that the number is being read correctly as if any of the numbers do not match up, the check digit will not validate.

If you need to create check digits in PHP, here is my handy function:

PLAIN TEXT
PHP:
  1. function ean13_check_digit($digits){
  2. //first change digits to a string so that we can access individual numbers
  3. $digits =(string)$digits;
  4. // 1. Add the values of the digits in the even-numbered positions: 2, 4, 6, etc.
  5. $even_sum = $digits{1} + $digits{3} + $digits{5} + $digits{7} + $digits{9} + $digits{11};
  6. // 2. Multiply this result by 3.
  7. $even_sum_three = $even_sum * 3;
  8. // 3. Add the values of the digits in the odd-numbered positions: 1, 3, 5, etc.
  9. $odd_sum = $digits{0} + $digits{2} + $digits{4} + $digits{6} + $digits{8} + $digits{10};
  10. // 4. Sum the results of steps 2 and 3.
  11. $total_sum = $even_sum_three + $odd_sum;
  12. // 5. The check character is the smallest number which, when added to the result in step 4,  produces a multiple of 10.
  13. $next_ten = (ceil($total_sum/10))*10;
  14. $check_digit = $next_ten - $total_sum;
  15. return $digits . $check_digit;
  16. }

Other Barcode Related Resources:

http://phpclasses.fonant.com/browse/package/3643.html

http://thinkabdul.com/2007/01/04/barcoder-freeware-ean-13-barcode-reader-for-java-j2me-mobiles/

Posted in barcode, php | No Comments »

Building Spiders: Grab Data, Post Forms and Interact with Web Sites Automatically

Thursday, February 14th, 2008

One of the most useful and powerful things you can do with PHP is to create a programme which will simulate a web browser and can grab data, post data to forms and generally interact with other web sites - automatically.

For PHP to be able to work like this it must have the CURL library installed and active. It is the CURL library which actually handles all of the interaction and PHP is my scripting language of choice for interacting with CURL.

A simple CURL function is like this:

PLAIN TEXT
PHP:
  1. function curl($url){
  2.  
  3. $timeout = '300'; //how long before CURL gives up on this page
  4. $go = curl_init();
  5. curl_setopt ($go, CURLOPT_URL, $url);
  6. curl_setopt ($go, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt ($go, CURLOPT_FOLLOWLOCATION, 1);
  8. curl_setopt ($go, CURLOPT_TIMEOUT, $timeout);
  9. $spage = curl_exec($go);
  10. curl_close($go);
  11. return $page;
  12.  
  13. }

This function when called and echoed will output the entire html of the $url specified.

For grabbing data from this page to be inserted into a database (for example when spidering a suppliers web site for product information to be inserted into your site) we then use regular expressions to find what we are looking for and then insert that into the database.

so for example if we wanted to grab the product title and we knew that this was wrapped in a h1 tag with the class "product title" we could use this regexp to grab this:

PLAIN TEXT
PHP:
  1. $page = curl($url);
  2.  
  3. $pattern = '%
  4. <h1 class="product_title">(.+?)</h1>
  5. %i';
  6.  
  7. preg_match($pattern,$page,$matches);
  8.  
  9. print_r($matches); //we can see the entire array of matches and choose which we want to insert into the database

We can also Post data to web sites using curl. This allows us to do all kinds of things including grabbing data that is displayed on the submission of post forms. Here is an example Curl Post Function:

PLAIN TEXT
PHP:
  1. function curl_post($url,$post_data){
  2.  
  3. $timeout = '300'; //how long before CURL gives up on this page
  4. $go = curl_init();
  5. curl_setopt ($go, CURLOPT_URL, $url);
  6. curl_setopt ($go, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt ($go, CURLOPT_FOLLOWLOCATION, 1);
  8. curl_setopt ($go, CURLOPT_TIMEOUT, $timeout);
  9. //now for the post section
  10. curl_setopt($go, CURLOPT_POST, true);
  11.  
  12. curl_setopt($go, CURLOPT_POSTFIELDS, $post);
  13. $spage = curl_exec($go);
  14. curl_close($go);
  15. return $page;
  16. }

It can be tricky to figure out exactly what data should be in the post string. To help you out though is this incredibly handy addon for firefox: Live Http Headers.

This addon lets you see exactly what is going on between your browser and the web site you are visiting. This can quickly and easily give you the information you need to replicate the same behaviour with your CURL script.

Edmonds Commerce specialise in working with PHP and CURL. If you have any spidering, screen scraping or other application that requires PHP to actively interact with other web sites - get in touch today to see how we can help you benefit from this incredibly powerful technique.

Related Resources

http://www.phpfour.com/blog/2008/01/20/php-http-class/

http://www.phpclasses.org/browse/package/1988.html

http://www.phpit.net/article/using-curl-php/

http://skeymedia.com/intro-to-curl-with-php/

Posted in curl, firefox, php, programming, spidering | 1 Comment »

Web Developer Toolbar for Firefox

Tuesday, February 12th, 2008

The web developer toolbar is an excellent addition to the great firefox web browser. It allows you ultimate control over the behaviour of your web browser and helps you to fine tune layouts. The toolbar has a real time html and css editor built in which is great for tweaking things. For those of you who have a nice big 22" monitor to develop on, the resize functionality is awesome for replicating the viewport of whichever resolutions you want, so that you can ensure your layout still works on an 800 x 600 display for example.

As a web development tool for those of us who hand code things instead of using dreamweaver or whatnot - it is an excellent tool.

You can download the web developer toolbar here

Unfortunately there is some kind of bug with Firefox where if an update fails or the browser crashes, then your web developer toolbar may stop working. In fact it is still working but all of the icons disappear. All you have to do to fix it is right click it, select customize and then select "Restore Default Set". Thanks to Voodish for the fix.

Posted in web development | No Comments »

Advanced Google Search Queries

Monday, February 11th, 2008

Google is undoubtably the world's most well known and widely used search engine. However I doubt that a large proportion of Google users really understand the power of Google search and the various ways it can be used to track down very specific information and resources.

Here is my breakdown of the most useful advanced search operators to be used in Google:

Phrases:

Instead of just searching for keywords, it is often much more useful to group keywords into phrases. This is very easy to do, simply wrap your chosen phrase in "speech marks". By doing so you will only pull pages which display the entire keyphrase as it is, instead of pages which display all of the keywords, but not necessarily as a phrase.

See the results of these two searches:

edmonds commerce Bulk Catalogue Handling or edmonds commerce "Bulk Catalogue Handling"

Site:

You can limit your search to pages within a certain web site. This can be great for finding things, but as a web master it is also useful for seeing how many of your pages are being spidered and indexed by Google.

e.g. site:www.edmondscommerce.co.uk shows all of the pages that are indexed by google under the edmonds commerce domain name.

InURL:

The inurl: operator searches for the term in the URL of the site. This is good for finding specific sections of a web site. So for example I can see how many of the Edmonds Commerce Blog pages are indexed by mixing up the site: operator and also using the inurl: operator to only pull pages that have the blog/ sub folder in the URL.

e.g. site:www.edmondscommerce.co.uk inurl:blog
InTitle:

Like the inurl: operator, the intitle: operator looks for the keyword in a specific place, this in in the <title> tag of the page. The title tag is what is usually displayed as the link text in Google search results pages.

So another way of finding all of my indexed blog posts is to search for the word Blog in the title

eg. site:www.edmondscommerce.co.uk intitle:blog

The Minus Operator:

A very powerful operator, the - minus sign allows us to show results that do not match the following. So if we want to find pages from the Edmonds Commerce domain that do not have the words "web design" on the page, we can do the following search:

e.g. site:www.edmondscommerce.co.uk -"web design"

Conclusion

Google is a great search engine and it is definitely worth playing around with your searches to get the best results. Also, as a web master you should really be doing everything you can to figure out how the big G works so that you can ensure you are doing everything in your power to get your site to the top of the results.

Related Blogs:
Hybrid SEM: The ultimate guide to advanced searching

Putrefy: Google Advance Search

Seo Smarty: Advanced Search Commands

Posted in search engine optimisation | No Comments »

HOSTS file, Vista and Blocking Unwanted Adverts

Friday, February 8th, 2008

The hosts file is a highly useful little text file that most people are not really aware of. Basically what it does is set a specific url to an IP address that you specify. This is great for testing web server etc. Also, we can block unwanted content by changing the IP address for the URLs that the adverts are coming from. The convention is to change the IP address to 127.0.0.1 which basically means the local computer itself.

Editing the HOSTS File

Your hosts file can usually be found in

c:/windows/system32/drivers/etc/

it is a text file, but does not have .txt at the end - it has no dot at all.

To edit it in XP, simply right click the file and select to open in notepad. Make your edits then save the file. For your edits to work you will generally have to restart whichever programmes you wanted to change the behaviour of.

Editing the HOSTS File in Windows Vista

The HOSTS file is much more secured under Windows Vista. This is fair enough because malicious changes to your HOSTS file could set you up for all kinds of things such as phishing attempts etc. However it does make it a bit more tricky for you to edit it yourself.

Heres how to do it:

1) Browse to Start -> All Programs -> Accessories
2) Right click "Notepad" and select "Run as administrator"
3) Click "Continue" on the UAC prompt
4) Click File -> Open
5) Browse to "C:\Windows\System32\Drivers\etc"
6) Change the file filter drop down box from "Text Documents (*.txt)" to "All Files (*.*)"
7) Select "hosts" and click "Open"
8) Make the needed changes and close Notepad. Save when prompted.

Block MSN Messenger Adverts.

I am not a big fan of in your face adverts, especially within applications. MSN messenger adverts are easy to get rid of though. All we need to do is edit the hosts file, save it and then restart the program.

1.) Open your HOSTS file for editing

2.) Paste the following into the bottom of your HOSTS file:

# Windows Live Messenger ad servers

127.0.0.1  rad.msn.com

127.0.0.1  global.msads.net

127.0.0.1  rss.video.msn.com

127.0.0.1  ads1.msn.com

127.0.0.1  rad.live.com

127.0.0.1  specials.uk.msn.com

3.) Save Your HOSTS File

4.) Restart MSN Messenger

Posted in Windows | No Comments »

Handy Easy Javascript

Thursday, February 7th, 2008

Javascript can seem daunting for new comers who are learning html and coding for the web. However there are a few dead easy things you can do with javascript which do not require any particularly complicated code and can make your site a bit smoother and slicker for the end user.

Form Submit on Change

A dead easy one to make forms automatically submit when people make a selection on a drop down menu. All you have to do is add onchange="submit();" into your opening select tag

PLAIN TEXT
HTML:
  1. <form action="index.php"> <select name="view" onchange="submit();"> <option>option1</option><option>option 2</option></select> </form>

Javascript Back Button

another really easy one - you can replicate the functionality of the back button. This is especially handy if you are displaying content in a javascript window without the usual controls.

PLAIN TEXT
HTML:
  1. <a href="javascript: history.go(-1)"><-- Back</a>

Posted in javascript | No Comments »

Speeding Up osCommerce

Wednesday, February 6th, 2008

osCommerce is a great ecommerce package which is hugely popular due to its full feature set, massive options for customisation and a huge support base. However if you want to run a large catalogue, or have plenty of visitors then speed can become an issue. There are a number of things you should look at to increase the overall speed of your osCommerce store

The problem is in the way that osCommerce has evolved, and also in the way that they have tried to make the code base as portable as possible. This means that as standard, the software may be doing quite a few processes that are not really necessary for your store.

One of the biggest culprits of page load time problems, especially on sites with large catalogues is the split_page_results class. In standard trim, the class performs the most complex query of your catalogue page twice - once to find the number of rows and a second time to actually grab the results. On a small site you may not notice this, but on a larger site this query can represent a large portion of the total page load time.

The answer is to modify the class so that it uses the SQL_CALC_FOUND_ROWS functionality to simultaneously perform the query and calculate the total number of rows. Then to get this number of rows, you only have to select FOUND_ROWS() instead of performing the whole query again.

PLAIN TEXT
PHP:
  1. $count_query = str_replace('select', 'select SQL_CALC_FOUND_ROWS ', $this-&gt;sql_query);
  2. if(!isset($this-&gt;current_page_number)){
  3. $this-&gt;current_page_number = 1;
  4. }
  5. $current_limit = " limit " . ((($this-&gt;current_page_number -1) * $this-&gt;number_of_rows_per_page)) .', ' . $this-&gt;number_of_rows_per_page;
  6. $this-&gt;sql_query = $count_query . $current_limit;
  7. $this-&gt;sql_query = tep_db_query($this-&gt;sql_query);
  8. $count = tep_db_query("select FOUND_ROWS()");
  9. $this-&gt;number_of_rows = mysql_result($count, 0);

Posted in oscommerce | No Comments »

MySQL Find and Replace

Tuesday, February 5th, 2008

One of the most common things that needs to be done when tidying up a database is to bulk find and replace data in MySQL tables. This can be for things like spelling mistakes, changing categories of products or any other value held in a MySQL database table.

Its an easy thing to do though and here is the code:

PLAIN TEXT
MySQL:
  1. UPDATE [table_name] SET [field_name] = REPLACE([field_name],'[string_to_find]','[string_to_replace]');

note - nice syntax highlighting plugin used is mentioned here

Posted in mysql | No Comments »

10 SEO Myths

Monday, February 4th, 2008

The world of search engine optimisation or SEO for short is confusing to say the least. The main problem is that much of SEO knowledge is like a kind of religion. You can never truly know how the Google algorithm works at any one time. You can read up on forums and blogs and maybe do your own experiments to try to get an understanding, but at any one time a lot of what you know about SEO is based on faith.

The other really confusing thing about SEO is that we are always being told different stories. If you are not careful you may be reading blog posts for forums that are from the early years of 2000. By now these posts or comments are generally out of date and not applicable to current day SEO.

So to try to clear things up a bit, here is a list of the 10 most common SEO Myths that you will encounter when trying to figure out how to get thousands of visitors per day from natural search results.

  • 1. As Many Links as Possible is the Answer
  • 2. Reciprocal Linking is the Answer
  • 3. Paying Someone for Guaranteed First Place Positions is the Answer
  • 4. Directory Submission is the Answer
  • 5. Keywords Everywhere is the Answer
  • 6. Paid Links are the Answer
  • 7. Do No Evil is the Answer
  • 8. Pay Per Click is the Answer
  • 9. Time is the Answer
  • 10. Money is the Answer

Here is a breakdown of this list.

1. As Many Links as Possible is the Answer

From reading about SEO you may get the impression that links are one of the most important aspects of promoting a web site in the search engines. Whilst this is true, it does not follow that the more the better. In fact there are scenarios where you can easily have too many links. Furthermore there are scenarios where certain links can actually work against you.

2. Reciprocal Linking is the Answer

A reciprocal link is simply enough an "I'll link to you if you link to me" scenario. There was a time when reciprocal linking was one of the main white hat SEO techniques. However the latest information from Google is that reciprocal links are being devalued. Reciprocal Links that are worth having are hard to come by and whilst I would not advise you to abandon any form of reciprocal linking, pouring hours and hours into it is most likely a waste of time.

3. Paying Someone for Guaranteed First Place Positions is the Answer

You might get the impression that being in the top of the first page results is all important to getting the most traffic to visit your site. It is true that the vast majority of people do not stray much beyond the first three results presented in the search engine results page. However there is a big difference between ranking number one for a search term that a lot of people are using, and ranking number one for a search term that no one is using.

4. Directory Submission is the Answer

One commonly supported way to build inbound links to your site is to submit it to a long list of directories. This is another technique that used to work well but has since dwindled to the point that it is hardly worth your time. There was a time when directory sites were actually a reasonable source of traffic but this day has long gone. Furthermore, the vast majority of directories these days are cookie cutter sites with little value and highly unlikely to enjoy any visitors other than those people who are still looking to submit to directories.

5. Keywords Everywhere is the Answer

You may get the impression that to rank for your chosen search term, you simply need to repeat that search term as many times as possible in as many places as possible on your page. This is referred to as keyword stuffing and is very much looked down upon by the search engines. In fact it is entirely possible to rank for a search term which does not exist on your page even once. I do not recommend that you test this theory out just yet, but conversely do not be tempted to put your search term on the page any more than is natural for that page.

6. Paid Links are the Answer

After reading about all the ways that people used to build links being closed up by the search engines, or being so labour intensive to be not worth the effort, many people looked towards simply paying a web site a monthly fee to display a link. This has worked well in the past but the search engines quickly became concerned about their algorithms being manipulated with sheer cash. The search engines now go to a lot of effort to devalue or even penalise sites that use paid links. This means that even if you can afford to pay the often huge monthly bills for links, you stand a good chance of gaining at best nothing and at worst a penalisation for your trouble.

7. Do No Evil is the Answer

Google famously stated as its mission statement that they intended to Do No Evil. So you might think that if you play exactly by the rules laid down by Google then the big G will reward you for your steadfast commitment to SEO as Google permits you with high rankings. Unfortunately this is not usually the case and in fact the people who are ranking at the top for competitive search terms are using one or more techniques that cross over into the slightly murkier side of search engine optimisation.

8. Pay Per Click is the Answer

Pay Per Click is the term used to describe the Google Adwords style of search engine marketing. This simply enough means that you set a price you are willing to pay and if you set a high enough price to beat your competitors, your advert will be placed on the search engine results page. Instant gratification! However a badly managed PPC campaign can literally break the bank. We highly discourage you from relying solely on PPC as your search engine marketing strategy. Its damn expensive!

9. Time is the Answer

So after everything you have learned, you might get the impression that you simply need to plug away and dutifully wait for the search engine spiders to come and gobble up your site and give you the rankings. Keep plugging away and putting in the hours for a few years and you will gradually rise to the top. No unfortunatley it is entirely possible that you will sink literally thousands of hours of employee time into your SEO strategy and never gain anything substantial back.

10. Money is the Answer

There aren't many things in life that can not be sorted out by simply throwing unlimited bundles of cash at. That's a sad fact that goes a long way to explaining why the rich get richer whilst the poor get poorer. Thankfully though in SEO terms this is not entirely true and it is definitely possible for a small operation to outrank huge coorporations with vastly larger budgets and resources.

So what is the answer?

That's the rub. There is no definitive answer to what is going to work in SEO. And even if I was to start spilling the beans on some currently successful techniques, there is every chance that by the time you read this article they have already expired or become much less effective.

Related Blogs
Scary SEO Myth Number 5
The SEO Myth
SEO Myths
Three SEO Myths Debunked
Busting Google Indexation Myths
Are We Suffering from Pagerank Paranoia
There are No Secrets and Other SEO Myths

Posted in search engine optimisation | No Comments »

Next Entries »
  • RSS Feed
  • Categories

    • apache
    • barcode
    • creloaded
    • curl
    • customer services
    • debugging
    • ecommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • magento
    • management
    • mod_rewrite
    • mysql
    • oscommerce
    • php
    • plesk
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • scraping
    • search engine optimisation
    • security
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    addons advanced adverts blackhat blocking css curl development directories find firefox google hosts file html javascript keywords links msn mysql myths operators oscommerce paid links paid placement performance php ppc reciprocal linking replace screen scraping security seo serp speed spider spidering tuning user friendly vista web web design web developer
  • Random Posts

    • Magento UK
    • osCommerce Easypopulate File Creator Class
    • Faster File Browsing with Tabs for Ubuntu
    • PHP MySQL Query Function with Easy Error Message
    • Essential Search Engine Optimisation Research Tool
    • Web Developer Toolbar for Firefox
    • MySQL Find and Replace
    • osCommerce Password Reset Using phpMyAdmin
    • Advanced PHP Debug Function
    • Regular Expression Test Tool

Edmonds Commerce related questions? Send us a message or call us on 0844 357 0201.

Freelance PHP Web Design UK Commercial Web Design