Ministry of Soup Web Development


Time for an update and some more handy sites

December 14th, 2008

Updating to 2.7 today so let’s see how it goes!

Also found this very handy site here.

Decoding %40 and other foibles

December 12th, 2008

Much as you can find this here, i thought i would put it in as it’s very helpful if you spend a lot of time talking to flash using php (and vice-versa). Flash has a habit of confusing things by converting things like the @ to %40 which is not very useful when it comes to storing it in a database for later extraction. Simply run: urldecode() on the offending string and all shall be well. Also of note some ways to encrypt data such as rot13 but I will talk about those another day!

PHP.ini trickery

December 11th, 2008

If you do not have access to your php.ini file, say if you are on a managed server, and need to mess around with it, do not despair! The code below should do the trick nicely. I’m not sure to what extent you can change the settings but i know it has worked on the memory limit:

ini_set(”memory_limit”,”100M”);

Basically, put this code at the top of your php file, rather than the htaccess and away you go. I will edit this to put the url of where i found that.

Retrieving the URL using PHP

December 9th, 2008

Nice handy peices of code for doing what the title says.

echo  ‘http://’.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

echo ‘http://’. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

echo ‘http//’.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

All of the do the same thing. Handy for security stuff.

Found here, cos i’m nowhere near clever enough to know this stuff!

.htaccess trickery

December 8th, 2008

To run PHP5 on a PHP4 server just ensure you have permissions to use htaccess files, then in the root of your directory create a file called “.htaccess” and place this code in it:

AddType x-mapp-php5 .php

It’s that simple!

Credit to these guys

Email personalisation with Enabler

December 4th, 2008

I’ve never used Enabler before, preferring to use Campaign Monitor, but below are a list of codes that are useful in creating personal HTML mails using enabler:

{recipient}      Recipient First Name
{recipientlastname}     Recipient Last Name
{recipientcompany}     Recipient Company Name
{recipientemail}     Recipient Email Address
{recipienttitle}     Recipient Title
{recipientmobile}     Recipient Mobile Number
{sender}      Sender First and Last Names
{senderfirstname}     Sender First Name
{senderlastname}     Sender Last Name
{senderorganisation}     Sender’s Organisation Name

Sending plain text and html mail using PHP

December 3rd, 2008

I cannot remember where i found this script but it has been tinkered with until it does what i want it to do. Originally it just sent plain text with an attachment but i needed to send html mail instead. Once i remember where the script came from I will post the link.

<?php
//define the receiver of the email
$to = ‘test@example.com’;
//define the subject of the email
$subject = ‘Test HTML email’;
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date(’r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = “From: webmaster@example.com\r\nReply-To: webmaster@example.com”;
//add boundary string and mime type specification
$headers .= “\r\nContent-Type: multipart/alternative; boundary=\”PHP-alt-”.$random_hash.”\”";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
–PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset=”iso-8859-1″
Content-Transfer-Encoding: 7bit

We at CPLG would like you to play this new game:

http://www.cplg.com/game

Go on and give it a go!

–PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset=”iso-8859-1″
Content-Transfer-Encoding: 7bit

<body bgcolor=”#666666″>

<div style=”margin:0px auto 0px auto;width:465px;”>
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
<p>Our new game is <a href=”http://hitentertainment.bionic-comms.co.uk/newsboard/”>here</a></p>
</div>
</body>

–PHP-alt-<?php echo $random_hash; ?>–
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print “Mail sent”. Otherwise print “Mail failed”
echo $mail_sent ? “Mail sent” : “Mail failed”;
?>

EDIT

Here is the url of one of the sites I used. This gave me the details on how to do multi-part emails (using attachments).

Here is the url of the other site. This goes into some more details, and i think prefer the code in this one a little more.

Thanks to both the authors for making my life a lot easier!

Coda

November 27th, 2008

This is one of the best programs i have ever used. In terms of simplicity and workflow, it is the best bar none. One of my favourite things about it is the fact that i can work on live projects via the ftp. Prior to this i had used Dreamweaver (which i still use to create HTML emails, another great fun task), textmate and imple plain text editors. And while Dreamweaver and textmate allow you to work on live projects, the simplicity with Coda is beyond measure. But the one feature i have not learned how to use yet is the subversion tools. If anyone does actually read this beyond me, and know’s how it works please email me here.

As a foot note, this program is Mac only i’m afraid but that shouldn’t deter you, buy a Mac!

Password protecting your entire wordpress blog - the easy way!

November 27th, 2008

I have tried several plugins, such as members only and private…something, but none of them ever worked for me. However, I stumbled across this piece of code, here,and it has worked superbly. Merely insert the code into the top of your header.php file located in your theme directory and away you go:

<?php if (is_user_logged_in()){
echo “”;
}
else {
auth_redirect();
};
?>

This also has the advantage of not being affected if you lose your login.

Later on today, I am going to post about what happens if you try to move the url of your blog and can’t get back into it to change it back as this has happened to me on several occasions!

Quick jobs - problems associated with them

November 26th, 2008

I recently built a very small image gallery for one of our clients. I threw it together in a couple of days. But in retrospect, this has taught me a lot more than I originally thought:

  1. It is always better to add things like thumbnailing in as you go, rather than adding them in once the site is live. The reason I missed this in the first place was partly oversight on my part and the crushingly small amount of time I built it in.
  2. When doing links for a delete or flag, turn them into forms as Google’s crawler bots crawl through them and delete/flag the image instantly. Mildly annoying and I would say, not on the list of expected problems.