Require_once and include_once

July 18th, 2006 by daman371 in PHP, Quick Tips, PHP

The include and require functions are handy for using files that contain other variables, functions, etc. What happens when you have a collision between function names though? Well quite simply you get an error.

Read the rest of this entry »

No Comments »

Last modification time

July 17th, 2006 by global in Quick Tips, PHP

You can use flat files to create a simple system to tell the last modification date of a file, but it's much easier than when you're using getlastmod(), no paramaters, it just returns the time stamp of the last modification, which you can pop into the date() function for formatting.

<?php
$last_mod = getlastmod();
$formatted = date("F j, Y g:i A", $last_mod);
echo("This page was last modified: ". formatted);
?>

It's that easy.

2 Comments »

Generating a (semi) random string with PHP

July 17th, 2006 by global in Quick Tips, PHP

It's nice to have an easy way to generate a pretty much random string for whatever you want, especially passwords. There's a couple of ways to do it using PHP, and I'm going to show you one I learned from a friend of mine: Tim. This method just takes a random string, shuffles it around, and some characters from that string. It's a pretty easy method and can be condensed into one line if needed.

<?php
//Just a bunch of characters I typed
$string = 'dfsicjkxcvXSNxmaOZpqxnQDlaciwalaciAghakckUIy';
//Shuffle it up
$shuffle = str_shuffle($string);
//Get 6 random characters from the shuffled string
$random_chars = substr($shuffle, 0, 6);

//Condense into one line:
$random_chars2 = substr(str_shuffle('dfsicjkxcvXSNxmaOZpqxnQDlaciwalaciAghakckUIy'), 0, 6);
?>

Yay for random!

2 Comments »

Pretty URLs using .htaccess

July 17th, 2006 by global in Web Resources

URLs can either be ugly, or pretty. (hopefully they’re pretty) But most sites end up using the ugly structure:

index.php?artid=4388&count=6&pindex=5&random=3

Whilesites like ours use a cleaner structure:

/2006/07/some-weird-name/

Which do you like better?

Read the rest of this entry »

2 Comments »

replace method

July 10th, 2006 by global in JavaScript

The JavaScript replace method allows you to replace one string with the other, e.g looking for recieve and replacing it with receive (rememeber, i before e except after c!) Using it is simple, the first paramater is the string you're searching for, the second the string you're putting in.

var incorrect = "Man, I wish I could spell recieve.";
var correct = incorrect.replace("recieve", "receive");

That's all there is to replacing simple strings in JavaScript.

No Comments »

Make your own functions

July 7th, 2006 by Shwaza in PHP Tutorials, PHP

Making your own functions makes large projects so much easier when coding. I find, however, that not too many people who begin using PHP make their own functions, instead they repeat the same process over and over again, page after page. Believe me, I've done it!

Read the rest of this entry »

1 Comment »

Client-side isn’t always safe

July 5th, 2006 by Shwaza in Quick Tips, Security

With so many more people using all these fancy new techniques on their websites, you can begin to forget how insecure the client side really is. It’s very easy to manipulate content on the client side using browser add-ons and evening creating your own files and running them locally (providing the website isn’t checking referrers). This makes it extremely important that all validation is done server side, although there’s nothing wrong with doing it client side as well. I personally like having client side validation because it allows me to fix my mistakes without having to wait for the page to load and it also conserves server resources.

One thing I have to say is think about the user when implementing client-side validation. You should make sure that your validation is noticeable but won’t annoy the hell out of the user which could cause them to not bother and just leave. In my opinion the best kind of validation is altering the background color of the div (or *shudder* table cell) that the element with a problem is in. I find it clearly shows the user where the problem is but isn’t annoying or intrusive.

So just keep in mind that it’s find to use all the new effects and techniques, so long as you make sure you’re doing it safely and in an non-annoying and unobtrusive way.

No Comments »

You have ‘x’ number of characters left

June 30th, 2006 by global in Javascript Tutorials, JavaScript

For whatever reason, you may have to limit the length of a message, be it for SMS or something else. A user doesn't want to have to guess the length, or run over to Word to find out. Using JavaScript, we can display the exact number of charaters left, and when the user goes over, we can show a warning.

Read the rest of this entry »

No Comments »

ipbsdk

June 27th, 2006 by global in Web Resources

The ipbsdk is a cass for Invision Power Board (ipb) that allows you to control many aspects of the board, like adding topics, posting, checking user groups, and fetching PMs through a PHP class that you include in your custom scripts. This allows easy integration of ipb into other areas of your site, with the SDK, you could easily integrate the login on your front page with your forums. All functions are well documented, the current realease is 1.6 beta 4.

No Comments »

Select only what you need!

June 24th, 2006 by global in Quick Tips, SQL

Selecting data from MySQL databases is easy, just run your query and it's done. I still see people using * in queries when they only need the ID or title, by using that *, you're selecting all the data, instead of just what you need. It's not that hard to select only one row, just specify it instead of putting a *.

SELECT `id` FROM `my_table` WHERE `title` = 'Hoorah!'

You won't really notice a speed increase from one query, but running 30 queries multiple times a minute really adds up.

No Comments »