Archive for April, 2010

Magento: New url on a existing installation (after a move)

Tuesday, April 20th, 2010

Magento stores the base url in the database.
The easy way to change this is to use the admin interfece, but if that is not possible (for instance you have swapped ip for a dev machine – or moved data from a existing installation to another machine) then it is possible to do the update in the database.

  • In the table “core_config_data” find the keys “web/secure/url” and “web/secure/url” and just update these to the new address. Hint: The addresses should end with “/” otherwise magento won’t like it.
  • Clean out var/cache/* and var/session/* (use “rm -rf” on a *nix environment)

.htaccess to allow google ads (the indexing bot) [or limit user-agents via .htaccess]

Monday, April 19th, 2010

Sometimes there is a need to only allow limit access to a site using a .htaccess file.
If you still wish to be able to serve Google adsense on this page then the following example is good for this (yes the allow line should be changed to suit your needs)

# Google_ads agents
BrowserMatchNoCase Mediapartners-Google good_pass
BrowserMatchNoCase Adsbot-Google good_pass
<LIMIT GET POST>
order deny,allow
deny from all
allow from 123.456.789
#Google ads
allow from env=good_pass
</LIMIT>

PHP: casting stdClass Object to a array

Thursday, April 15th, 2010

When using Soapclient to access a webservice the returned object will be of a stdClass Object.

If you don’t wish to access this as an object, but would find it easier to use it as an array then a quick cast solves this.

/*As an object*/
print_r($soapResult->contents);
/*cast to an array*/
$soapResult = (array)$soapResult;
print_r($soapResult['contents']);

 at the top of the page (UTF-8 BOM)

Wednesday, April 14th, 2010

These characters are the Byte Order Mark (BOM) of the Unicode Standard.

This can be solved in two ways:

  • Save the file without the BOM (some editors have this as an advanced option)
    • Using vi:
       :set nobomb

      and then save the file

  • Make sure the right encoding is used to present the file (meta charset) / .htaccess or similar