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

CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc
Magento UK
PHP Cached Download Function

Most Popular Posts

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

Archive for July, 2008

PHP: Recursive Create Path (if not exists)

Thursday, July 31st, 2008

Handling directories and files with PHP is a snap. However, with this handy function you can always be sure that the destination directory path for your files will exist.

If you pass a path with a filename at teh end, set the second parameter to true eg make_path($path, true)

PLAIN TEXT
PHP:
  1. /*Create  Directory Tree if Not Exists
  2. If you are passing a path with a filename on the end, pass true as the second parameter to snip it off */
  3. function make_path($pathname, $is_filename=false){
  4.  
  5.     if($is_filename){
  6.  
  7.         $pathname = substr($pathname, 0, strrpos($pathname, '/'));
  8.  
  9.     }
  10.  
  11.     // Check if directory already exists
  12.  
  13.     if (is_dir($pathname) || empty($pathname)) {
  14.  
  15.         return true;
  16.  
  17.     }
  18.  
  19.     // Ensure a file does not already exist with the same name
  20.  
  21.     $pathname = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $pathname);
  22.  
  23.     if (is_file($pathname)) {
  24.  
  25.         trigger_error('mkdirr() File exists', E_USER_WARNING);
  26.  
  27.         return false;
  28.  
  29.     }
  30.  
  31.     // Crawl up the directory tree
  32.  
  33.     $next_pathname = substr($pathname, 0, strrpos($pathname, DIRECTORY_SEPARATOR));
  34.  
  35.     if (make_path($next_pathname, $mode)) {
  36.  
  37.         if (!file_exists($pathname)) {
  38.  
  39.             return mkdir($pathname, $mode);
  40.  
  41.         }
  42.  
  43.     }
  44.  
  45.     return false;
  46.  
  47. }

Posted in php | No Comments »

PHP, cURL, CURLOPT FOLLOWLOCATION and open basedir Or Safe Mode

Friday, July 18th, 2008

If you are trying to get a curl script which needs follow on location functionality to run on a server which has either open_basedir or safe mode enabled you will get an error message similar to the following:

CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set

After a bit of digging, some kind soul has put a workaround here

Here is how to use the function

PLAIN TEXT
PHP:
  1. function curl($url){
  2. curl_setopt ($go, CURLOPT_URL, $url);
  3. //follow on location problems
  4.  
  5. if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')){
  6.  
  7. curl_setopt ($go, CURLOPT_FOLLOWLOCATION, $l);
  8.  
  9. $syn = curl_exec($go);
  10.  
  11. }else{
  12.  
  13. $syn = curl_redir_exec($go);
  14.  
  15. }
  16.  
  17. curl_close($go);
  18. return $syn;
  19. }
  20.  
  21. //follow on location problems workaround
  22.  
  23. function curl_redir_exec($ch)
  24.  
  25. {
  26.  
  27. static $curl_loops = 0;
  28.  
  29. static $curl_max_loops = 20;
  30.  
  31. if ($curl_loops++>= $curl_max_loops)
  32.  
  33. {
  34.  
  35. $curl_loops = 0;
  36.  
  37. return FALSE;
  38.  
  39. }
  40.  
  41. curl_setopt($ch, CURLOPT_HEADER, true);
  42.  
  43. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  44.  
  45. $data = curl_exec($ch);
  46.  
  47. list($header, $data) = explode("\n\n", $data, 2);
  48.  
  49. $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  50.  
  51. if ($http_code == 301 || $http_code == 302)
  52.  
  53. {
  54.  
  55. $matches = array();
  56.  
  57. preg_match('/Location:(.*?)\n/', $header, $matches);
  58.  
  59. $url = @parse_url(trim(array_pop($matches)));
  60.  
  61. if (!$url)
  62.  
  63. {
  64.  
  65. //couldn't process the url to redirect to
  66.  
  67. $curl_loops = 0;
  68.  
  69. return $data;
  70.  
  71. }
  72.  
  73. $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
  74.  
  75. if (!$url['scheme'])
  76.  
  77. $url['scheme'] = $last_url['scheme'];
  78.  
  79. if (!$url['host'])
  80.  
  81. $url['host'] = $last_url['host'];
  82.  
  83. if (!$url['path'])
  84.  
  85. $url['path'] = $last_url['path'];
  86.  
  87. $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');
  88.  
  89. curl_setopt($ch, CURLOPT_URL, $new_url);
  90.  
  91. return curl_redir_exec($ch);
  92.  
  93. } else {
  94.  
  95. $curl_loops=0;
  96.  
  97. return $data;
  98.  
  99. }
  100.  
  101. }

Posted in curl | No Comments »

Regular Expression Test Tool

Friday, July 18th, 2008

Creating regular expressions can sometimes be a frustrating experience. Generally I find using regular expressions intuitive and easy, with quick and powerful results. However every now and then you stumble into a regular expression scenario that you just can't seem to crack.

When this happens you might find yourself trying and trying different regular expressions and then echoing out the results and trying to figure out what is going wrong.

At times like this, a regular expression testing tool is invaluable. If like me though you don't really like to shell out on something that you are probably hardly ever going to use then this online regular expression tester is great.

Thanks goes out to these guys for hosting such a simple but eminently useful little tool :-)

Further Reading

http://weblogs.asp.net
http://www.imneebu.com/
http://openoffice.blogs.com/
http://www.oreillygmt.co.uk/
http://spellbook.infinitiv.it/
http://www.alexschultz.co.uk/
http://www.colinneller.com/blog/
http://www.embracingchaos.com/
http://www.hanselman.com/blog/
http://www.phpclasses.org/browse/package/3211.html
http://www.phpclasses.org/reviews/id/0596514271.html
http://blogs.oracle.com/

Posted in regular expressions | No Comments »

PHP : Dead Easy Excel Export

Wednesday, July 9th, 2008

Some people like their excel files. For people who want their data exported in an excel format checkout this chunk of code. It's really easy :-)

First of all you need to download this php excel class

Now try this code:

PLAIN TEXT
PHP:
  1. $query = mysql_query("select * from table");
  2. while($q = mysql_fetch_assoc($query)){
  3.     $output[] = $q;
  4. }
  5. require_once "excel.php";
  6. $export_file = "xlsfile://export.xls";
  7. $fp = fopen($export_file, "wb");
  8. if (!is_resource($fp))
  9. {
  10.     die("Cannot open $export_file");
  11. }
  12. fwrite($fp, serialize($output));
  13. fclose($fp);
  14. header ("Content-Type: application/x-msexcel");
  15. header ("Content-Disposition: attachment; filename=\"exports.xls\"" );
  16. readfile("xlsfile://export.xls");
  17. exit;

That's got to be the easiest thing you have ever done in PHP. Thanks goes to the excellent PHP Classes site.

Here is some further reading:
PHP Excel Formula Parser
PHP Excel Export class
Export data directly to Excel by configuring the MIME Type Profile Option
Power your PHP Business Logic with Excel
Reading/Parsing Excel Spreadsheet using PHP

Posted in excel, php | 1 Comment »

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.

Posted in php | 1 Comment »

  • 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
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • 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

    • Advanced Google Search Queries
    • PHP Random Sleep Function with Flush
    • Saving a File or Webpage using PHP
    • Essential Search Engine Optimisation Research Tool
    • MySQL Add Column if Not Exists - PHP Function
    • Regular Expression Test Tool
    • Flash and PHP Charts and Graphs
    • HP Printer on Ubuntu
    • 10 SEO Myths
    • PHP Generated SQL

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

Freelance PHP Web Design UK Commercial Web Design