Writing Secure PHP, Part 4
11 September 2008 | 57 comments | code, coding, development, mysql, php, programming, security, tips, tutorial, web, webdesign, webdev
The fourth part of the Writing Secure PHP series, covering cross-site scripting, cross-site request forgery and character encoding security issues.
PHP Querystring Functions
5 December 2006 | 53 comments | links, code, development, url, querystring, reference, php, functions, programming, tips, variable
Adding and removing variables to and from URLs using PHP can be a relatively simple process admittedly, but I have a couple of functions I use often to make the process even less time-consuming.
Add Querystring Variable
A PHP function that will add the querystring variable $key with a value $value to $url. If $key is already specified within $url, it will replace it.
function add_querystring_var($url, $key, $value) {
$url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
if (strpos($url, '?') === false) {
return ($url . '?' . $key . '=' . $value);
} else {
return ($url . '&' . $key . '=' . $value);
}
}
Remove Querystring Variable
A PHP function that will remove the variable $key and its value from the given $url.
function remove_querystring_var($url, $key) {
$url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
return ($url);
}
RSS to iCal
19 October 2006 | 16 comments | rss, weather, php, bbc, ical, convert, tools, web, webdev, code, rss2ical
I have been looking for a way to convert the BBC weather feed for my area to iCal, so I can subscribe to it. It's date-based, after all, and RSS never seemed to me to be an appropriate format for subscribing to weather information. iCal always struck me as being "better" for that purpose. Of course, the BBC only have an RSS feed for local weather. What I needed was a converter.
After some hunting, I discovered that Dean Sanvitale had written a PHP script to convert RSS feeds to iCal format. However, his site (codent.com) appears to be long since abandoned and the script is no longer available from there. Fortunately, the Wayback Machine did have a copy. Dean originally released the script under a Creative Commons License which, fortunately, allows me to make the script available to download from this site (note: the script is available from this site under the same license).
So, if you're looking for a way to convert an RSS feed to iCal, this PHP script will do the job. Thanks Dean!
Source: rss2ical.txt
Regular Expressions Cheat Sheet (V1)
14 September 2006 | 172 comments | code, howto, cheatsheet, development, regex, regexp, expressions, reference, programming, tips, regular
Regular Expressions are very powerful, and many people find their unusual syntax hard to get to grips with. This A4 reference serves as a guide to regular expression patterns and options.
JavaScript Cheat Sheet
1 August 2005 | 102 comments | code, webdev, cheatsheet, development, reference, programming, ajax, web, webdesign, javascript, guide
A quick reference guide for JavaScript, listing methods and functions, and including a guide to regular expressions and the XMLHttpRequest object.
PHP Cheat Sheet (V1)
22 April 2005 | 247 comments | code, webdev, development, cheatsheet, cheat, reference, programming, php, web, webdesign, tools, cheatsheets
I'm fed up with having to visit php.net to look things up. This A4 cheat sheet is designed to sit by your desk and make your life easier.
Preload Images with CSS
23 December 2004 | 58 comments | code, rollover, webdev, howto, preload, web, design, image, webdesign, images, css
How to preload images using CSS and so avoid delays with rollover effects.
View Page Structure
12 October 2004 | 26 comments | imported, code, xhtml, tool, cheatsheet, design, webdesign, useful, tools, resources, css
A tool that outputs the structure of a page. Makes working with CSS (especially resolving inheritance issues) much easier.
Writing Secure PHP, Part 1
16 July 2004 | 109 comments | code, coding, development, mysql, php, programming, security, tips, tutorial, web, webdesign, webdev
Learn how to avoid some of the most common mistakes in PHP, and so make your sites more secure.
The Gunning-Fog Index is a measure of text readability based upon sentence length and difficult words in a passage.
Output Caching for Beginners
9 June 2004 | 121 comments | code, cache, webdev, performance, article, development, tutorial, programming, php, web, caching
High-traffic sites can often benefit from caching of pages, to save processing of the same data over and over again. This caching tutorial runs through the basics of file caching in PHP.
Email Address Validation
1 June 2004 | 203 comments | code, development, email, php, programming, regex, regexp, security, tutorial, validation, webdesign
How to validate email addresses according to ISO standards with PHP.
VBScript Regular Expressions
7 November 2003 | 34 comments | code, regex, regexp, reference, programming, asp, vbscript, vb, regular, scripting, expressions, regular-expressions
Regular expression reference and examples for VBScript.