3 Quick PHP Tips

submit to reddit


1. Use a redirect function in PHP without header/location stuff:

function redirect($page,$time) {
	echo '<meta http-equiv="refresh" content="'.$time.'; url='.$page.'" />';

Now use:


in order to redirect to index.php after 3 seconds.

2. Generate 3 characters salt strings:

// Salt Generator
function generate_salt() {
	// Declare $salt
	$salt = '';
	// And create it with random chars
	for ($i = 0; $i < 3; $i++) {
		$salt .= chr(rand(35, 126));
	return $salt;

Change $i < 3 with more characters, as suited to your needs.

3. Clean up user input:

$name = ucwords(strtolower($name)); // Transforms "heLLO wOrLD" into "Hello World"

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>