Archive for the 'PHP / MySQL' Category

HTTPDJS

HTTPDJS (HTTP Dynamic Javascript) is something I cooked up a while back when some of the available scripts out there had disappeared, or just were too buggy.

What does it do?

The problem with the XMLHttpRequest object, is that you cannot perform cross domain requests, something called the “same domain policy” comes into effect. This applies to other things such as iframes. I needed a way to perform requests from a remotely hosted forum (ProBoards in this case) that worked near enough like the XHR object. Before, I used to set a no content header in the PHP script, but there was no way to send data back without putting more work in, so I thought it was time for a script of my own.

So here it is, can’t remember when I created this. Might have been sometime last year. The zip file comes with an examples folder so you can see how it works (3 examples). The main things you need to do is include the HTTPDJS.js file, and the base64.js file (put above HTTPDJS.js). Next, you will need to edit the URL to the api.php file, this can be found in the HTTPDJS.js file.

GET and POST is supported.
Sending your own parameters is supported too.
Sending large amounts of data will be split up into parts and rebuild on the server.

Using it (example)

var request = new HTTPDJS();
var params = “action=post&user=peter&msg=hello";

request.isReady = function(){
   alert(request.responseText);
}

request.open("POST", “http://mydomain.com/post_message.php");
request.send(params);

The source

HTTPDJS.zip

Any questions, post below.

Sortables with backend

Something I have been working on that I thought I would show you…

http://pixeldepth.net/Javascript Projects/Sortables/Sortables.html

May release the source when I get round to it, including the PHP for it.

PHP Date Class

I have a date class that I wrote which I have tidied up and thought I would put it up for download.

The class is very simple to use, and all the parameters are explained in the file, just look at the “make” function, there are comments above it explaining the parameters.

I have included examples in the bottom of the file so you can test it for yourself. Basically the date class will generate dates (depending on the parameters) such as these…

Today, at 11:40 AM
1 hour ago
15 hours ago
Yesterday, at 11:40 AM
2 days ago
15 days ago
20 days ago
4 weeks ago
42 weeks ago
29th Dec 2005, 11:46 AM

dateclass.zip

Edit - Fixed some bugs (5th July 2007)

Simple Code Tag Plugin

Before, I was using a plugin called “iG:Syntax Hiliter” to format any code I posted in my entries, but for me it was too much, and sometimes it wouldn’t format the code correctly, some lines would be further indented than others. So I decided to write my own little plugin, I didn’t need all the syntax highlighting, just something that transforms my tabs into spaces to keep the indents as they should be.

So yeah, it’s only around 20 lines of PHP :D

Example…

_float: function(obj, p){
   if(obj && p){
      obj.style[((typeof obj.style.cssFloat != "undefined")? "cssFloat" : "styleFloat")] = p;
   }

   return obj;
}

:D

PHP Manual CSS Update?

I was just looking up something in the PHP manual, and when I came to the sample code I noticed they have changed the style. Here, take a look to see what I mean…

http://php.net/manual/en/function.levenshtein.php

…If you have visited it before you will see the changes made to it. Personally I think it looks worse now, I preferred the previous layout for code snippets. If they do keep it like that, I think it should just be the one box, not a box inside a box.

Yes, I know it’s something small :P

What do you think?

Increase RSS Excerpt / Summary

One thing that was annoying me was the length of the RSS Excerpt for entries. Overall the length is 55 words, which isn’t that much to be honest. Problem is, there is no way to change this from the administration area that I can see. So, I went hunting though the source and found out that it is hard coded in, which is a little disappointing. I really hope WordPress think about including some RSS options so we can have a little more control over our feeds. Anyway, if you want to change yours, here are the instructions….

Goto the folder “wp-includes” and look for a PHP file called “formatting.php” and open it in notepad or whatever you prefer to use. On line 780, look for this…

$excerpt_length = 55;

Change 55 to how many words you want to display in the RSS excerpt. For me, I changed it to 85.

Hopefully that will be useful to someone and save them a bit of time :D

Mail Server

Because most of my programming is done offline PHP’s mail() function doesn’t work, and I’ve never been bothered to setup anything to make it work until now.

Have a look at this…

http://www.phpeasystep.com/workshopview.php?id=23

It’s so simple and easy to do. I used Thunderbird instead of Outlook, and it works fine.

Now all your activation / signup emails can be tested offline.

PHP-GTK I’m loving it

I had tried PHP-GTK 1 before, and never really got into it, I gave it about a day. But now I have decided to go back to it, and have been playing around with it the last couple of days, and I must say, I’m really enjoying it.

Once you have everything installed and running, it’s so easy to start writing your applications. The main downfall of it at the moment, is that there is no compiler for PHP-GTK 2, so distributing your applications is a bit awkward at the moment. Saying that, there is a free compiler in the works called “PriadoBlender”, at the moment the developer is working on 1.5 (I believe) which will support PHP-GTK 2. I can’t wait, that means you can compile your application into an exe file and then give it out, so whoever downloads it doesn’t need to install GTK and PHP.

So yeah, in the mean time I’m just trying stuff out, getting to know the classes / methods / properties. Yesterday I created a program called “Hasher” just to test it out. The program is useless, but it was fun to try…

Hasher

Anyone else tried PHP-GTK?

Hush Hush

A few months ago I was working for JV Trading, though not officially, as I wasn’t on the books. My job was basically doing anything, most of the work was hard manual labour. The place I was working at was a nightclub that was getting completely redone, inside and out, a lot of money being spent on it. As for why my job ended, don’t ask, lets just say that the person I was working for doesn’t have a sense of humour and didn’t like people standing up for them self by talking back, which is what I done.

Anyway…they opened the club last night with the new name called “Hush Hush”, which I’m not really liking myself. I heard that there has been problems with the toilets and the pipes. The toilets were leaking sewage, and the pipes that go from the pumps to the bar were squirting over the customers. Why? Because it was all a rushed job, regardless if it looks all nice, the job was rushed, which is no fault to the contractors. That’s what I heard from my source :P.

I also noticed that they have a new website, and all I can say to the company who were paid to create it needs to fire the PHP programmer. I haven’t looked for any exploits, and won’t bother, but from a quick look around, there is no form validation done server side, they rely on client side validation (yes JavaScript). So I went to the signup form, clicked submit, and there I was, already logged in without having to provide any information, same applies to every other form on there.

Here is the link if you wish to check it out…

http://www.hushhushlounge.co.uk