Archive for December, 2009
Defining Custom Address Format in Magento
Written by shuron on December 13, 2009 – 02:09 -If you want to change the default address representation in your Magento shop you should simply add new address format for desired country. It should be done in the table mage_directory_country_format.
The following example illustrates how to do this. This statemet inserts the same format in three forms: HTML, text and PDF for beeing used in PDF documents like invoices.
INSERT INTO `mage_directory_country_format` (`country_id`, `type`, `format`) VALUES
('DE', 'html',
'{{depend company}}{{var company}}<br />{{/depend}}\n
{{var firstname}} {{var lastname}}<br/>\n
{{var street1}}<br />\n
{{depend street2}}{{var street2}}<br />{{/depend}}\n
{{depend postcode}}{{var postcode}}{{/depend}}{{depend city}} {{var city}}{{/depend}}
{{depend region}}, {{var region}}{{/depend}}<br/>\n
{{var country}}<br/>\n{{depend telephone}}Tel : {{var telephone}}{{/depend}}\n
{{depend fax}}<br/>Fax : {{var fax}}{{/depend}}'),
('DE', 'text',
'{{depend company}}{{var company}}\n{{/depend}}
{{var firstname}} {{var lastname}}\n
{{var street1}}{{depend street2}}{{var street2}}\n{{/depend}}\n
{{depend postcode}}{{var postcode}}{{/depend}}{{depend city}} {{var city}}{{/depend}}
{{depend region}}, {{var region}}{{/depend}}\n
{{var country}}
{{depend telephone}}\nTel : {{var telephone}}{{/depend}}
{{depend fax}}\nFax : {{var fax}}{{/depend}}'),
('DE', 'pdf',
'{{depend company}}{{var company}}|\n{{/depend}}
{{var firstname}} {{var lastname}}|\n
{{var street1}}|{{depend street2}}{{var street2}}|\n{{/depend}}\n
{{depend postcode}}{{var postcode}}{{/depend}}{{depend city}} {{var city}}{{/depend}}
{{depend region}}, {{var region}}{{/depend}}|\n
{{var country}}
{{depend telephone}}|\nTel : {{var telephone}}{{/depend}}
{{depend fax}}|\nFax : {{var fax}}{{/depend}}|')
Prioduces something like:
My Company GmbH
Max Mustermann
Mönkeberg Str. 123
22090 Hamburg
Hansestadt Hambug
Deutschland
Tags: address, address format, Magento, sql, sql statement, table
Posted in Magento | No Comments »
Denied access with pure PHP
Written by lexa on December 8, 2009 – 12:05 -Often you have to protect a directory or website, so that not everybody has access to it. Besides, there are several possibilities as for example using .htaccess, but the best and quickest method as it seems to me is with PHP code.
You create a file with the name login.php, with following contents:
<?php
$user = "test";
$pw = "12345";
function authenticate () {
Header("WWW-authenticate: basic realm=\"Restricted Area\"");
Header("HTTP/1.0 401 Unauthorized");
echo "Restricted Area!";
exit;
}
if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pw) {
authenticate();
}
?>
Then you have to include the login.php to the top of index.php:
<?php
include ("login.php");
?>
Thats all! It is important that there are no other index.* files in the directory.
Tags: access, denied, directory listing, HTTP Header, PHP, protection
Posted in General, PHP | 1 Comment »
