Archive for July, 2008

Zen Cart Welcome Email Editor

July 31st, 2008

I’ve just dug up a script that I wrote a while back for someone. It’s not the most advanced thing in the world and it does what it says on the tin.

Within Zen Cart there is a menu on the admin pages called ‘Tools’ which has an option called ‘Email Welcome’. This script is a default Zen Cart page to simply show you what the welcome email looks like.

Screenshot 1

hint: be sure to turn on html emails and it will show you both the html and text versions (default text only is set)

I have modified this script to allow the editing of these pages if you have little or no knowledge of writing PHP although some HTML skill is required.

Zen Cart puts together a number of PHP Defines to build the welcome email and normally when you want to modify it then you have to trawl through three of four files of these defines to get to the one you want.

This script basically does that for you and parses/updates the files necessary with your new information. The following image shows the new page and i’m sure no explanation is needed to show you how to use it.

Screenshot Thumbnail 2

Known Bugs: the only thing I know to be wrong with it is that some defnes reference other defines and this script doesn’t respect that. There are only one or two defines like this so nothing to worry about unless you intend to change the name of the shop owner frequently. If you do change it, however, then just make sure you use this system to update the welcome email at the same time. Nice and easy!

UPDATE: Please make sure to chmod your languages/[language]/email_extras.php, languages/[language]/create_account.php and /languages/[language].php files (in both catalogue and admin) to be writable by apache if not this may not work.

Wordpress Session Management

July 14th, 2008

I’ve been working on YourMembers for some time now and have started selling it on newmedias with Tim Nash and I wanted to get some useful stats on the current state of the website. Luckily the selling site is running on Wordpress so I put together a simple plugin to give me some information on my last days visitors.

Believe it or not I call it ’session manager’ and It’s freely available through this site and via the wordpress plugin directory (when I get around to uploading it). It gives you the following information:

  • The number of visitors in the last day (configurable)
  • The number of pages each visitor looked at
  • Which they were
  • The times each page was visited

That’s it!

I find that a lot of stats plugins give what I would call too much information (ie pretty graphs, information on screen resolution and things like which browser the client is using). Session Manager differs because it provides is a very light weight single table implementation giving 90% of the functionality for 10% of the overhead.

I have been using it on this site and newmedias for the last week or two and it has been instrumental in giving me enough stats data to satisfy that ‘whose looking at my site’ itch. Exactly what I needed!

Any feedback would be greatly appreciated and if anyone fancies having a look at the code and trying to make something more of it then i would be keen to hear about it. I have written it in very clear coherent PHP that anyone could understand.

See the Session Manager page for the download link.

Spoofing a Post Request

July 7th, 2008

Ever needed to test what a form does on your site without having to go through and fill the thing in over and over? Alternatively have you ever needed to emulate a post request to a callback script or similar, something which is usually done by a secure server? Well I have!

If this happens then you can emulate the request to yours (or someone elses) server from anywhere using the following code.

<?php

$params = array('http'=>array('method'=>'POST','content'=>$string));
$context = stream_context_create($params);

$fp = @fopen($url, 'rb', false, $context);

if (!$fp) {
	echo 'Failed to open file pointer.';
} else {
	$response = @stream_get_contents($fp);
	if ($response === false) {
		echo 'POST Failed!';
	} else {
		echo $response;
	}
}

?>

Usage

Basically just pass the code above a URL in the variable $url and a formatted string in the format:

key1=var1&key2=var2&…

You should really stick it in a function and wrap in an HTML form but I’m not going to do it all for you! If all goes well then you should see the response from the post request, otherwise the appropriate error message will be shown.

Security Issues

Ever considered where else you could use this script? Ever though about how some people could use this script against your site? It could potentially be used for a DOS attack against anywhere but this is NOT what I recommend it be used for,  It’s just a handy tool for sending POST requests but if you are worried by this then there are a number of things you can do to prevent it.

The best I can think of is sending a DB stored random number with each POST. When your script receives it it should check the DB and delete that record if it exists then run the form, otherwise if it doesn’t exist then display the appropriate error message.