Archive for the ‘PHP’ Category

Send Email with attachments in PHP

Although there are ways to send email in PHP using PEAR and other libraries, sometimes you’ll get stuck in a situation where that either isn’t possible or just too much of a faff.

The other day I decided to create a function for this purpose that I can use in my own library of code.

It can be dropped into your include files and used for simple emails without attachments, HTML emails or complex emails with multiple attachments.

I haven’t spent a great deal of time on this so it might not be 100% but works well for me so let me know if there are any flaws that need to be taken care of.

You can download the function (and supporting functions) from here: send email with attachments in PHP

PHP upgrade to 5.x from 4 on CentOS

One of my customers has recently purchased a VPS for their website.  My Linux VPS is on WebFusion, theirs is on EasySpace.

Now unfortunately EasySpace seem to bugger off at 5pm so I had to rely on Google and hope that some of the Linux boys and girls out there were writing in an intelligible way.

Thankfully for me, I was not let down.

My first source was the AtomiCorp wiki: http://www.atomicorp.com/wiki/index.php/PHP

Then I ran into a little problem with a "dummy" library causing my "yum" to fail.  Similar except here: http://languor.us/error-missing-dependency-glibc-common-2-3-4-2-25-needed-package-glibc-dummy-centos-4

With that removed (on account of it being labelled somethink like xxxxxx-dummy-centos-4) I re-ran the update and succesfully upgraded to PHP 5.2.6.

All seems fine (including Plesk) although I expect the packages in Plesk might be out of synch so I'll need to remember the method in case I have to re-install the VPS anytime soon.

PHP, MySQL and even ASP grrr!

I'm not a PHP developer – never have been. I've had to fix problems in PHP sites before now and hence I've picked up a little knowledge of the language.

I've recently been helping my GF to rebuild something using MySQL and PHP and it makes me glad I moved on to using an IDE for server-side programming. It also makes me glad that I can use MS-SQL.

MySQL (we are talking about one of the web-based interfaces here by the way not the actual database) is pretty lousy-looking and difficult to find the features that you need. I know the database has many powerful features but the particular implementation I was using left a lot to be desired.

It's also been a few years since I used Dreamweaver to do any programming but without it I wouldn't have got far very fast in PHP. I'm sure that PHP is far more powerful than classic ASP – in fact I know it is because I've had to do some classic ASP recently. I don't miss using classic ASP though it has to be said.

When I offered to fax something to a friend recently they declined and said they didn't live in the 80s. Classic ASP, like faxes have their uses in todays world but I don't really wanna use them if I don't have to.

I would have to say that anyone moving into web-site server-side programming should look at both camps (PHP and language.NET) before deciding on their path because to be honest once you are used to using one language or system, you'll probably stick with it until it becomes obselete.

The question is when will ASP become obselete?

Using an image submit button in PHP

My colleague was getting frustrated earlier when trying to replicate the effects of a form from one website into a different website.  She was using a HTML input tag set to type=image, as follows:

<input type=”image” src=”images/image-name.gif” alt=”Send Message” value=”Submit” />

Now I don’t get involved in HTML that much anymore so I was curious when she said that although the form was posting back when she clicked on the image, the server-side PHP script wasn’t recognising the postback.  In fact, the page was just re-rendering.  My colleague has used this same simple HTML on numerous occassions before including a GET-based PHP form to another page.

After a trawl around Google we found suggestions from the HTML definition that you should specify the HTML action in the “value” attribute.  This we did as above to no avail.

Now since I am always suspicious of PHP (amongst other technologies) for handling things just that little bit different I looked for any PHP-related posts on the subject.

 Turns out this is actually because IE (from version 6 onwards at least) doesn’t send the value for a HTML input of type=image.  Not like Microsoft to adopt just part of a standard I hear you say with you tongue in your cheek.

Now since the type=image is supposed to return x & y co-ordinates from the browser there is a simple work around.

The server-side code would normally receive the following data from a HTML input tag where type=image:

control_name => value
control_name_x => x co-ord
control_name_y => y co-ord

Since with IE you don’t get the value returned you can simply test for the existence of x or y as follows:

 <?php
if (isset($_POST["control_name_x"]))
{
// form submitted 
}
?>

So there we go, PHP not to blame after all.  What was I thinking?

75 percent of my work is now in PHP

I've had my own business since 2003 but since starting Enjoy Online Ltd in 2007 I've found myself working in PHP most of the time.  There are times when I admire the simplicity of PHP – like when I used to program in classic ASP but to be honest, I count the hours until I can write something in C#.

I know that my knowledge of PHP is limited because I've only been using it since 2006 but I wouldn't use the language out of choice.  In the main, my customers have wanted something in PHP because of some plug-in or server restriction or hosting costs.  I now run have two of my own VPS (one on Windows 2003 and one on Ubuntu) so I have more freedom to push a customer in the .NET direction.  My designer develops in PHP however so to keep my developer busy on larger projects, I have to use PHP.  For smaller projects we can combine the design and development quite nicely with me doing all the development in .NET.

I must admit that .NET has been lagging behind the PHP crowd when it comes to sharing usable plug-ins and scripts.  Quite often although you can get hold of a ready-made control or script it will cost you (or cost you more) when you are using .NET.  When I get the time I will be putting up some of my work that I think would benefit others in the community but in all likelyhood there won't be much PHP script going up because there's already a glut of scripts and posts about pretty much everything you would want to do – or at least most of what I've required as I have been bettering myself.

So the reason for this post?  Basically I am hoping that in 2-3 months I can turn around and say "I do 75% of my work in .NET", or that in 2-3 months it won't be a day that I've come home and cursed other developers for their crazy coding in PHP.

Return top