Sanitizing numeric input in PHP

Going trough some PHP code I have to clean up I'm a bit surprised at finding that it can take many lines using everything from preg_match to addslashes and mysql_escape_string to sanitize numeric input.
So I thought I share a method that I find handy:

$id = (int) $_GET["id"];

In some cases it might want to handle any attempts to input a string where an number is expected though.
When converting a string to an integer PHP will default to 0, rather than something handy like NaN.
Usually it's not too much a problem if someone tries to hack you site and only gets directed to the contents for "id=0" when they try to input "id=1;DROP TABLE users".

But one would think that this should work as a check:

$id = (int) $_GET["id"];
if($_GET["id"] == $id){
	echo "ok";
} else {
	die("error");
}

But even if $_GET["id"] is "foo" it will equal 0, again because PHP will evaluate a string that doesn't represent a number as 0.

Instead I use this to check if the input string actually evaluates to a number:

if(ctype_digit(strval($_GET["id"]))){
	echo "ok";
} else {
	die("error");
}

Dreamspell calculator

I added a little application to the download section.
It takes a Gregorian date and converts it to a dreamspell date and then calculates the kin, guide, analog and antipode to generate the affirmation for that day.
For those of you not familiar with the dreamspell calendar it's a reinterpretation of the Mayan calendar by Dr. José Argüelles.
It's based around 20 "glyphs" and 13 "tones" which make up the 260 day year called the Tzolkin.
The idea behind it is to create a new calendar system that actually is in tune with natural cycles, unlike the Gregorian system we use today, but mostly it's used to cast horoscopes.
Here is one resource for more information about the calendar.

My wife wanted to have an neat application for displaying the affirmation of the day and to look up a persons birth "kin", so I put this one together for her:

If this sort of stuff interest you are free to hotlink to the swf using the following URL:
http://www.resonantearth.com/ingrid/dreamspell.swf
You can download the swf here.

To get the source visit the download page.

Site update

I have been meaning to upgrade my site for quite a while now, but since I just haven't had the time to spend on fixing up and redesigning my flash site so it's up to standards I decided to replace it with a simple wordpress blog for now.
And I must say I'm quite happy with functionality of it, and adhering to the old "content is king" mantra the first thing I will do is taking up blogging again and spend some time making applications for download.

I have copied the old posts from the BlixtBlog, but I could not be asked to transfer all the comments.
So my apologies to everyone who has been posting...if I make a new Flash-based blog system I will use wordpress for the back end and make sure the same thing doesn't happen again.

Does Flajax make sense?

Well, the word in itself maybe not, I just made that up myself.
But as you probably guess I'm talking about using Flash and AJAX together.

After my last post that also involved Flash and AJAX, "Right tool for the job...or right job for the tool?", I came across the following blog entry: Ajax and Flash Together
Some good examples of AJAX and Flash integration and I couldn't help to ask myself a couple of questions.

In what way does it affect me as a user if the buttons controlling flash is in the HTML page or part of the swf?

Looking at Yahoo finance and Google finance I really have difficult to see that the user would have advantages or disadvantages from an AJAX mix compared to only Flash.
The only case would be if there is browser incompatibilities with JS or that they lack the flash plug-in.
Obviously buttons is no good without graph and vice versa, so not having to rely on two separate technologies being available as expected is better. But to me it could just as well be one big swf...I would not notice any difference apart from when I right click.

On the google page I can agree that it's neat how it highlights the headlines to the left when you click the corresponding box in the graph. Using HTML for those headlines makes it possible to completely retain their visual identity, even if the result in Flash could be made very similar looking.

In what way would it affect me as a developer having to implement one over the other solution?

I cannot see that it would have any advantages when developing to move buttons to control the graph outside of the swf.
Anyone who can make the graphing app can in no time add the buttons instead of making a handler to respond to JS calls from the HTML buttons.

What have I missed?
In what way does combining Flash and AJAX help the user in those examples?
In what way does it help developers?

Right tool for the job…or right job for the tool?

Usually when people discuss Flash, AJAX and HTML there will be a lot of people saying "just use the right tools for the job, both have their strengths."
Seems obvious enough and makes sense.
But do we really have to learn to use all tools, and could one not turn it around to say that we should find jobs that fit our tools?

I many times been thinking I should have a look at AJAX because I might get a project where it would be a good solution.
The main reason I haven't bothered is that I have problem finding uses for it where Flash is in any way inferior. The only reason to go with AJAX that I can see is if you have a HTML page where AJAX could feel more visually integrated, but on technical merits alone I find it hard to see where AJAX would be a better tool.

The point I'm trying to make is not about if Flash is better than AJAX.
Regardless of the merits of using AJAX vs. Flash I really dislike having to deal with browser issues and a far from ideal development environment

Sure, if there was no demand for Flash and I had to make sure to put food on the table, then an AJAX job might seem tempting.
But as we all know Flash is higher in demand than ever, so why would I start using a technology that I don't enjoy working with that basically fills only fills some of functions as the one I already master?
To make sure that I can give the best solution to a customer who have a project that is one of the few where I think AJAX would be a better choice?
No thanks, if that situation would arise I'll be happy to send them on to someone who likes to deal with browser incompatibilities.

As long as I have the possibility I rather choose jobs where my skills is the right solution. Sure I like to keep up with new technologies, but only as long as they seem nice to work with and they bring new advantages. But to choose what tools to use according to the jobs on offer doesn't appeal to me.

So, what's your approach, choosing the skills that you find nice and useful to find matching jobs or adapting your skill set to the jobs on offer?

Better backbutton and deeplinking

I'm glad to have discovered that someone made an effort making a script similar to my backbutton and deeplinking solution for Flash.
Maybe old news to many of you, but since I get some visitors here looking for such a solution I thought I mention it.

http://www.asual.com/swfaddress/

I haven't got a chance to try it out and only had a look at the info on their web page, but it seems to be a very good alternative to my own script.

Back

It's been a while since the last update.
First of all I had a little daughter in april...Disa:

I won't blame her for the lack of updates to the blog and the systems available on the download page though. She's been amazing and hardly ever create a fuzz....a real little angel.

But I've been enjoying the excellent summer we had in Sweden with the family and also had a lot of work, both with development and around the house.
I will try to better now and make some blog posts, add some recently done projects in the portfolio as well as maybe release updated versions of the systems.

Web 3.0

Ok, I know there seems to be enough difficulties defining what Web 2.0 actually means.
So of course attempting to define what web 3.0 will be is silly, or if you are enough of a visionary will make you stinking rich and renowned.
I guess I will fall into the silly category, but I do like to speculate (although I would prefer to become stinking rich and renowned) :)

I must say I would have completely failed perceiving what web 2.0 would be about a few years ago.
It took me ages to see what is so useful about XML and syndication, and I'm still neither a flickr or del.icio.us user. I recently started blogging and the only typical web 2.0 service I actually is using is audioscrobbler, or last.fm as they are called now.

So my speculations about the future is similar still to what I was foreseeing in the end of the 90's. Maybe I'm looking to far into the future or looking in the wrong direction.
But anyway...here we go....the future of the web according to me:

AI
This is the big one I think.
I guess the first thing at least I think about when I hear AI is robots, or translated into a web environment, avatars.
And I do imagine we will see a few sales or support avatars and get just as annoyed with them as with the MS search puppy.
But in essence what those avatars will be is kind of like search engines that analyse how you interact with the website or respond to questions you ask them.
So the main area where AI will be useful is to behind the scenes modify what the user is presented with. The websites will turn intelligent and guide us to the information we need, or the products we don't need but maybe can't resist.

How would that work?
Take a shop, for example amazon.
The already have a lot of functionality that will customize the content and give you suggestions based on for example "people who bought this book also bought.."
Now take that a step further and have the website registering how long users look at different items to try to measure their interest and serve content based on that.
Maybe use different descriptions targeted at different types of customers based on their browsing and purchase habits. Just like a good salesman would adjust the pitch after making a judgement on what the needs and desires of the customer is.
For example a customer who just bought "flash for dummies" that looks at "actionscript bible" could like to know that it has many chapters really useful for complete beginners while the seasoned actionscript developer might be turned of by knowing that.
Ok, sneaky I admit, but just like a real sales person would do in most cases.
Of course it should be used to find the right product for you and not try to sell you anything you look at.

I'm sure for example google is exploring AI techniques for their search engine.
What do users that search for a certain phrase usually click on?
I don't know if google does calculate on that yet, but it seems to me like a sensible way to have the users actually weed through the results for them.
Are European users maybe more likely to click on some results compared to Americans or Asians?
I know I been annoyed trying to find a shop in the EU when looking for some products.
If google as clever it would presume that since I'm based in EU, and other people from the EU that have been searching for a place to buy American Spirit tobacco went for a result that was a shop not based in the US, it should prioritize those results for me.

Interactive Multimedia
Web 2.0 started changing things a bit, but how many pages isn't still basically an on-line brochure with the only difference that you click a link instead of flicking page by hand?
As bandwidth increases and the technologies like Flash matures I think internet will develop more into being a medium with it's own style.
Not just put some text here with an image there, a link there and maybe if you feel extremly adventurous a video there.
The web has potential to be extremly immersing and efficient in getting messages across and promoting products or services by combining advanced interactivity with all kinds of media, and I think we will see more and more examples of how to do that.

VR
Yes, I know....it was hot in the beginning of the 90's and just never took off.
Or did it? On-line multi player gaming is Virtual Reality even if you don't have the full lawnmoverman-outfit and is immensely popular now.
Maybe for example virtual shopping malls where you can try an outfit on your avatar before buying it could be one possibility.
Environments combining gameplay, social networking and real life interaction like shopping maybe could prove successful, although I guess most people like to keep them separate.
So maybe VR will remain something that is used mostly for game play, but nevertheless it will be a big part of the on-line experience.

Easing scrollbar

I got a request for it and decided to put up my scrollbar for anyone who might be interested.
It's not using the V2 framework and is designed to be lightweight but flexible.

Features:
Only 4k uncompressed.
Can scroll one or several movie clips, text fields or buttons.
Responds to mousewheel, arrow keys and page up/down keys.
Configurable easing.
Fairly easy to alter style by simply editing the component.
Drag area that resizes with the amount of content to scroll.
Can update when changing the size of the content to be scrolled.

So basically just another scrollbar, but if you are looking for something less bloated then the MM V2 components and just want to do some scrolling it might be useful.

Get the download here.

UPDATE:
After doing some testing with several instances on multiple levels I noticed some issues.
I have now updated the download so you can use several instances as well as load them on top of each other and still have the mousescroll and keyboard control working fine.

To update the scrollbar reinstall the component using the extensions manager by double clicking the .mxp file.
Then drag an instance of the component onto the stage in the .fla with an old version. When prompted choose to replace existing items.
You can now delete the newly added instance, and your previous instances will be up to date.

UPDATE 2006-02-12:
An error in ScrollFocus.as made the key and mouse scroll stop working if you removed the first instantiated scrollBar.
The .zip file have been updated with the amended class file.

AS3 example…waveform display

Many thanks to Guy Watson who confirmed that the FFTMode for computeSpectrum doesn't work yet.
I was hoping to be able to post a proper spectral analyser for Flash, but that has to wait until the FFT is sorted.

So for now you can check out the code for the example waveform display I made.
It's pretty much the same as what was posted on www.richapps.de but I used the readFloat method to access the data to make the wave display correctly.

« Previous PageNext Page »