Items filtered by date: December 2014

Thursday, 04 June 2015 18:23

Center Homepage Banner

The homepage banner is not centered and requires a bit of coding.

This would involve setting a wrapper to 100% and the banner size inside to fixed with a max-width and auto margins. I would also apply these changes via the overide system.

Example Code:

#homepage-slider {
  padding-left: 0;
  padding-right: 0;
  margin-bottom: 14px;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  position: relative;
  z-index: 1;
  float: left; }
  
@media (max-width: 767px) {
	#homepage-slider {
	width: 100%;
	max-width: 100%;
	padding-top: 20px; }
}
	  
#homepage-slider #homeslider {
	margin: 0 auto;
	padding: 0; }
Published in Prestashop

These should be used in the header.tpl and can be changed to make code run on specific pages.

Run code only on the homepage

1.

{if $page_name == 'index'}
    <div class="home">
{else}
    <div>
{/if}

2.

{if $page_name == 'index'}
<script type="text/javascript">
    var yiw_prettyphoto_style = 'pp_default';
</script>
{else}
{/if}

 

Published in Prestashop

There might come times when you click on a link to a file, for instance a PDF,  and it opens in the browser but instead you want it to download.

If we take PDFs as an example, these will always open in the browser because that is how Adobe Reader is rigged to show the PDF, in the browser. To do otherwise we need to force the download.

Well there are solutions and i will outline them below.

HTML Download Tag

There is a new config option that you can use in a hyperlink

<a href="/path/to/file" download>Click here to download</a>

The code above does work but if you add this into a WYSIWYG it is slightly modified, and that new version also works so is probably a better version.

<a href="/path/to/file" rel="external" download="">Click here to download</a>

Notice that the download option now has parenthesis to hold a variable so it looks like a normal option. The rel="external" seems to be optional and could just be added by the JCE editor as a matter of course.

<a href="/path/to/file" download="">Click here to download</a>

Variant

This could be the same command used better and also allows you change file names which is useful for dynamically create content.

<a href="/files/adlafjlxjewfasd89asd8f.pdf" download="expenses.pdf">Download Your Expense Report</a>

Old HTML Hack

This is a bit of a hack and is listed for completeness. It will cause a windows to open which will trigger the download and hopefully the new window will also dissapear.

<a href="/path/to/file" download target="_blank">Click here to download</a>

PHP Headers

You can alter the Content-Type headers via your PHP session

application/force-download

By default all files are delivered using the content type application/force-download, which forces all browsers to display a “save file as” dialog instead of displaying the file.

.htaccess

This is a useful method because you can globally change download behaviour using the htaccess. The method is similiar to the PHP method where you change the headers sent to the browser but it is done on the server level.

Specify Files or File Types

<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>
  • This will cause all PDFs to download.
  • You can change the file type that the rule affects or add more.
  • With FilesMatch you can target specific files.

Global

AddType application/octet-stream .csv
AddType application/octet-stream .xls
AddType application/octet-stream .doc
AddType application/octet-stream .avi
AddType application/octet-stream .mpg
AddType application/octet-stream .mov
AddType application/octet-stream .pdf
  • Above i have included a few version of this declaration you can put in the .htaccess file.
  • You only need to add the rules that apply to the files you want to force to download.
  • These command are global.

Other

These are other methods i have come across that might be useful to other people.

1. I found a very simple solution for firefox (only works with relative rather than direct href): add type="application/octet-stream"

<a href="/./file.pdf" id='example' type="application/octet-stream">Example</a>

2. Disable PDF plugins, this is more for the end user and is not applied on the server.

Tools> Add-ons> Adobe Acrobat(Adobe pdf plugin for Firefox)> DISABLE

Links

Published in General

Can you help me discover the solution to removing .html from Magento category URL?
How configure magento such that the category url does not have “.html” in the url?

If you want to remove .html from all Magento’s category URL then Follow the below steps

  1. Go to System -> Config -> Catalog -> Search Engine Optimizations tab
  2. Delete “.html” from Category URL Suffix.
  3. Go to System->Index Management
  4. Reindex “Catalog URL Rewrites”
  5. Refresh cache

If you want to remove  .html from all Magento’s product URL then steps will same. Except

2. Delete “.html” from Product URL Suffix.

Original link : http://www.blog.magentosupport.net/2011/07/remove-html-from-category-or-product-url-for-magento-webshop/

Published in Magento

Cause

If you receive this error it is most likely a fault in your template files.

This is most likely caused by you using out of date or faulty code in your template that is overiding the base code. Base code is not usually faulty.

Solution

  • Remove the dodgy files in your template and allow the base code to be used.
  • clear the magento cache

If this does not work, upgrading your shop might be an option.

Links

Published in PayPal

To fix this annoying error I got, when I tried to Re-Index the Data all you have to do is

deleting everything in the /var/locks folder

in your magento folder, of course.

That’s it!

Published in Magento

in magento 1.5+ you cannot see what categories a product is assigned to in the admin. This feature for some reason was removed in magento. This is one of the stupidest things i have come across but kiwigrid has written a an extension to overide this behaviour and force the category tree to expand the category branches that have the product in it. It will not just expand the whole tree. The product category tab takes slightly longer to load whilst the code checks categories and then expands the tree where needed but you dont really notice.

This plugin is easy to install and does not overwrite any core code.

To Install

NB: do this on your demo site first before applying to your live store.

  1. download Kiwigrid AutoExpandProductCategoryTree Extension (on the right side click 'Download Zip')
  2. extract this file
  3. in the extracted files navigate to ../Kiwigrid_AutoExpandProductCategoryTree-master/Kiwigrid_AutoExpandProductCategoryTree-master/src , You should just see the 'app' folder
  4. upload this folder directly to your 'public_html' folder (this should be where you magento is installed), this means the files inside the 'app' folder on your desktop will go into the 'app' folder on the website
  5. if you cache is running you need to empty the following before you will notcie the code workingas expected (you might not need to do both as i wiped both of them in one go)

Useful Links

These are the links i came across whilst doing my research

Published in Magento
Sunday, 22 February 2015 22:23

PHP Easter Eggs - Worked Example

The following is the research i did to show what easter eggs PHP had that could be accessed and then prevented form being access by using .htaccess.


Using htaccess to deny access to PHP Easter Eggs

This is a worked example of Rewrite rules. With special forcus on when you need to involve the = or ? in a url with a query which sometimes is recognised just as a url by some parts of mod_rewrite.

Below is some example urls that you can use to test the htaccess file with. Pay special attention to the = ?. Some of these URL will not be recognised as having queries.

Next to each line in the htacces codes is ome numbers that match to the example URLs. The numbers signify which successfully performed a rewrite.

URL Examples:

1 - http://localhost/turnip.php?tool=PHPE9568F36-D428-11d2-A769-00AA001ACF42  (common exploits hits first)
2 - http://localhost/turnip.php=PHPE9568F36-D428-11d2-A769-00AA001ACF42       (this has no query)
3 - http://localhost/turnip.php?=PHPE9568F36-D428-11d2-A769-00AA001ACF42
4 - http://localhost/=PHPE9568F36-D428-11d2-A769-00AA001ACF42
5 - http://localhost/tmp/?=PHPE9568F36-D428-11d2-A769-00AA001ACF42

htaccess code

## Disallow PHP Easter Eggs (can be used in fingerprinting attacks to determine
## your PHP version). See http://www.0php.com/php_easter_egg.php and
## http://osvdb.org/12184 for more information

These success codes are valid on xammp only

#135#  RewriteCond %{QUERY_STRING} ^(.)*PHPE9568F36-D428-11d2-A769-00AA001ACF42(.)* [NC]
#135#  RewriteCond %{QUERY_STRING} .*PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#135#  RewriteCond %{QUERY_STRING} .*=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#135#  RewriteCond %{QUERY_STRING} (?=PHP).* 		[NC]	"# PHP Version Probing"
#135#  RewriteCond %{QUERY_STRING} .*(?=PHP).* [NC]
#35#   RewriteCond %{QUERY_STRING} ^=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#35#   RewriteCond %{QUERY_STRING} (&|^){1,1}=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#2#    RewriteCond %{QUERY_STRING} ^(.)+PHPE9568F36-D428-11d2-A769-00AA001ACF42(.)+ [NC]
#none# RewriteCond %{QUERY_STRING} ^%3F=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#none# RewriteCond %{QUERY_STRING} ^(.*)\?=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]

#24#   RewriteCond %{REQUEST_URI} .*(=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} .*(?=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} ^(?=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (.*)(?=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (^(.*)?=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} .*(=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (.*)(=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (^(.*)=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (PHP).*[NC]
#none# RewriteCond %{REQUEST_URI} ^(=PHP).*[NC]
#Rewrite rule forced on# RewriteCond %{REQUEST_URI} (?=PHP).* 	[NC]	
#Rewrite rule forced on# RewriteCond %{REQUEST_URI} ^.*(?=PHP).*[NC]

#RewriteRule ^(.*)$ extra/joomla-fingerprinting.php [L]
#RewriteRule ^(.*)$ extra/joomla-fingerprinting.html [L]

These codes are valid on my webserver with Extra Security Including suhosin

#  RewriteCond %{QUERY_STRING} ^(.)*PHPE9568F36-D428-11d2-A769-00AA001ACF42(.)* [NC]
#  RewriteCond %{QUERY_STRING} .*PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#  RewriteCond %{QUERY_STRING} .*=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#  RewriteCond %{QUERY_STRING} (?=PHP).* 		[NC]	"# PHP Version Probing"
#  RewriteCond %{QUERY_STRING} .*(?=PHP).* [NC]
#none#  RewriteCond %{QUERY_STRING} ^=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#none#  RewriteCond %{QUERY_STRING} (&|^){1,1}=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#  RewriteCond %{QUERY_STRING} ^(.)+PHPE9568F36-D428-11d2-A769-00AA001ACF42(.)+ [NC]
#  RewriteCond %{QUERY_STRING} ^%3F=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]
#  RewriteCond %{QUERY_STRING} ^(.*)\?=PHPE9568F36-D428-11d2-A769-00AA001ACF42 [NC]

#24#   RewriteCond %{REQUEST_URI} .*(=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} .*(?=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} ^(?=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (.*)(?=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (^(.*)?=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} .*(=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (.*)(=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (^(.*)=PHP).*[NC]
#24#   RewriteCond %{REQUEST_URI} (PHP).*[NC]
#none# RewriteCond %{REQUEST_URI} ^(=PHP).*[NC]
#Rewrite rule forced on# RewriteCond %{REQUEST_URI} (?=PHP).* 	[NC]	
#Rewrite rule forced on# RewriteCond %{REQUEST_URI} ^.*(?=PHP).*[NC]

#RewriteRule ^(.*)$ extra/joomla-fingerprinting.php [L]
#RewriteRule ^(.*)$ extra/joomla-fingerprinting.html [L]

Selected code for PHP Easter Egg Protection

These rules work on my Xampp:

Database Version: 5.1.33-community 
Database Collation: utf8_general_ci 
PHP Version: 5.2.9 
Web Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9 
Web Server to PHP interface: apache2handler 

the rules

RewriteCond %{QUERY_STRING} (?=PHP).*	[NC]	"# Also PHP Version Probing"
RewriteCond %{REQUEST_URI} .*(=PHP).*	[NC]
RewriteRule ^(.*)$ extra/joomla-fingerprinting.php [L]

The following occurs on my live server with those rules:

Database Version: 5.1.50 
Database Collation: utf8_general_ci 
PHP Version: 5.3.2 
Web Server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635

the rules

1. 404
2. 403
3. shows elephant
4. 403
5. shows elephant

 

Published in PHP
Sunday, 22 February 2015 22:13

What is My IP Address - Script

Simple Method

simply create a file on your website and run this, your IP will be displayed.

<? 
echo $_SERVER["REMOTE_ADDR"];
?>

also

<?php 
$ip = getenv("REMOTE_ADDR") ; 
echo "Your IP is " . $ip; 
?>

Displaying IP in a Graphic Mode

Show IP Display visitor's IP Address in an image with this simple php code.
Your IP Address: 40.206.137.115
Create a new page, copy the text below and save it as image.php (or whatever you wish)

<?php
$img_number = imagecreate(275,25);
$backcolor = imagecolorallocate($img_number,102,102,153);
$textcolor = imagecolorallocate($img_number,255,255,255);

imagefill($img_number,0,0,$backcolor);
$number = " Your IP is $_SERVER[REMOTE_ADDR]";

Imagestring($img_number,10,5,5,$number,$textcolor);

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>

All you'll need to display on other pages is the code below.

<img src="http://mysite.com/image.php" border="1">

Links

Published in PHP
Sunday, 22 February 2015 22:09

MySQL database connection testing script

A simple page for testing and troubleshooting a connection to a MySQL database. The PHP script will test the server address, username and password. If the database field is left empty, it will return a list of available databases. Testing a specific database is optional, but if a database name is supplied, it will return a list of the tables in that database (if any exist).

This script is from here:
http://www.ardamis.com/2008/05/26/a-php-script-for-testing-a-mysql-database-connection/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>MySQL Connection Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#wrapper {
	width: 600px;
	margin: 20px auto 0;
	font: 1.2em Verdana, Arial, sans-serif;
}
input {
	font-size: 1em;
}
#submit {
	padding: 4px 8px;
}
</style>
</head>

<body>

<div id="wrapper">

<?php
	$action = htmlspecialchars($_GET['action'], ENT_QUOTES);
?>

<?php if (!$action) { ?>

	<h1>MySQL connection test</h1>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=test" id="mail" method="post">

	<table cellpadding="2">
		<tr>
			<td>Hostname</td>
			<td><input type="text" name="hostname" id="hostname" value="" size="30" tabindex="1" /></td>
			<td>(usually "localhost")</td>
		</tr>
		<tr>
			<td>Username</td>
			<td><input type="text" name="username" id="username" value="" size="30" tabindex="2" /></td>
			<td></td>
		</tr>
		<tr>
			<td>Password</td>
			<td><input type="text" name="password" id="password" value="" size="30" tabindex="3" /></td>
			<td></td>
		</tr>
		<tr>
			<td>Database</td>
			<td><input type="text" name="database" id="database" value="" size="30" tabindex="4" /></td>
			<td>(optional)</td>
		</tr>
		<tr>
			<td></td>
			<td><input type="submit" id="submit" value="Test Connection" tabindex="5" /></td>
			<td></td>
		</tr>
	</table>

</form>

<?php } ?>

<?php if ($action == "test") {

// The variables have not been adequately sanitized to protect against SQL Injection attacks: http://us3.php.net/mysql_real_escape_string

	$hostname = trim($_POST['hostname']);
	$username = trim($_POST['username']);
	$password = trim($_POST['password']);
	$database = trim($_POST['database']);

	$link = mysql_connect("$hostname", "$username", "$password");
		if (!$link) {
			echo "<p>Could not connect to the server '" . $hostname . "'</p>\n";
        	echo mysql_error();
		}else{
			echo "<p>Successfully connected to the server '" . $hostname . "'</p>\n";
			printf("MySQL client info: %s\n", mysql_get_client_info());
//			printf("MySQL host info: %s\n", mysql_get_host_info());
		}
	if ($link && !$database) {
		echo "<p>No database name was given. Available databases:</p>\n";
		$db_list = mysql_list_dbs($link);
		echo "<pre>\n";
		while ($row = mysql_fetch_object($db_list)) {
     		echo $row->Database . "\n";
		}
		echo "</pre>\n";
	}
	if ($database) {
    $dbcheck = mysql_select_db("$database");
		if (!$dbcheck) {
        	echo mysql_error();
		}else{
			echo "<p>Successfully connected to the database '" . $database . "'</p>\n";
			// Check tables
			$sql = "SHOW TABLES FROM $database";
			$result = mysql_query($sql);
			if (mysql_num_rows($result) > 0) {
				echo "<p>Available tables:</p>\n";
				echo "<pre>\n";
				while ($row = mysql_fetch_row($result)) {
					echo "{$row[0]}\n";
				}
				echo "</pre>\n";
			} else {
				echo "<p>The database '" . $database . "' contains no tables.</p>\n";
				echo mysql_error();
			}
		}
	}
}
?>

</div><!-- end #wrapper -->
</body>
</html>

 

Published in PHP
Page 47 of 96