Archive for the ‘PHP Libraries’ Category

Web Framework

Friday, April 18th, 2008

Attached is a copy of a very very alpha stage web framework I just made. I took most of the code from a site I’m developing, and removed the site specific stuff from it. It’s fairly advanced, just not fully complete.

Features includes:

An interactive command line mode (pipe your email, run cron jobs, all through the same application, with complete separation from the web interface)
An advanced controller/view architecture (no models yet).
Controllers run in a fully virtual environment (virtual IP, session, etc), allowing unit testing of practically anything.
A database revision system
An advanced exception model for comprehensive error reporting and logging
Maximum security with session hijacking and HTML/SQL injection prevention

Keep in mind, this is not CakePHP or Ruby on Rails. It doesn’t do as much for you, but in turn it provides maximum flexibility. This is not a “for dummies” framework, you have to know what you’re doing but it has major potential. Absolutely every line of code is written with maximum flexibility and modularity in mind.

It’s attached in a zip. Barely any documentation, if you have any questions at all though feel free to ask me.

Alpha Web Framework

URL Builder Class

Saturday, April 12th, 2008

This class allows you to build URLs using an easy object oriented interface.

Example:

// My blog

$url = new sb_url;
$url -> setDomain(’www.sambarrow.com’);

echo $url -> generate() . ‘<br />’;

// My blog archives

$url -> setPath(’/archives’);

echo $url -> generate() . ‘<br />’;

// My blog (using SSL)

$url -> setPath(’/');
$url -> setProtocol(sb_protocol_https);

echo $url -> generate() . ‘<br />’;

Download:

URL Builder Class

Fully object oriented + strongly typed PHP

Friday, April 11th, 2008

I wrote a few classes today allowing you to use all of your types as objects (like in Java).

$string = new vstring(’Hello!’);
$upper = $string -> upper();
echo $upper -> get();

This will output “HELLO!”

Strong PHP Types

Brute force login attack protection system

Sunday, March 30th, 2008

This script allows a user X failed logins. After this, their account is locked for N minutes. After the lock ends, they are allowed X more failed logins, and the process starts from the beginning. All logins are logged with IP address and timestamp.

This script is specific to a site I recently made, so it will have to be adapted to your login system. I can do this if you are interested, charging for my time, or you can do it, just replace my site specific functions (alerts_add, app_redirect, and db_*) and create the tables.

Login Protection System Script
Login Protection System SQL Export

Common matching functions

Sunday, March 30th, 2008

These are 3 functions that will match zip codes, alphanumeric strings, and email address.

Common matching functions

Database Select Query Builder

Thursday, March 27th, 2008

Just something I was messing around with. I made a class that allows you to build your own queries, with full support for conditionals. Pretty interesting, take a look. It’s all done using object oriented.

Database Select Query Builder

Database Security Functions

Tuesday, March 11th, 2008

These two functions escape data for sql queries, and apply backticks to table/column names. They can be used in conjunction with the mysql functions for easy updating, insertion, etc. that I will be posting soon.

DB Security Functions

CSV Escape Functions

Thursday, March 6th, 2008

Use these functions in place of fputcsv() if you are using an earlier version of php, or if you want to parse a CSV row but not write it directly to a file.

CSV Escape Functions

CSS Compression Function

Thursday, March 6th, 2008

Nice function, I use it in pretty much every application I develop. I can’t guarantee that it’s safe but in all the time I’ve used it I’ve never had a problem.

I went on one of those CSS compression sites, and this function that I had wrote reduced my CSS file to 2506 bytes, exactly the same size as the most advanced compression the site offered.

function compressCss(scalar $string) {
$blank = array(”\r”, “\n”, “\t”);
$string = str_replace($blank, ”, $string);
$string = str_replace(’ {’, ‘{’, $string);
$string = str_replace(’;', ‘;’, $string);
$string = str_replace(’: ‘, ‘:’, $string);
$string = str_replace(’, ‘, ‘,’, $string);
$string = str_replace(’;}’, ‘}’, $string);
$string = str_replace(’ }’, ‘}’, $string);
$string = preg_replace(
array(’#/\*.*?\*/#s’), ”, $string
);
return trim($string);
}

Useful date/time functions.

Thursday, March 6th, 2008

Attached is a few functions I have written having to do with dates and times.

Date/Time Functions