Mar
22
2008
0

Use Sticky Forms!

If a user inputs information that generates an error OR if he/she leaves a field blank, save them time (and increase your turnover) by using sticky forms. It's so simple and improves usability so much...

Let's say we're collecting first and last names (to keep it simple):

 
form.php
<?php
if (isset($_POST['submitted'])) {
 
		// Print the results.
		echo '
<h1>Your Name:</h1>
 
First: ' . $_POST['first'] . ' Last: ' . $_POST['last'] . '
 
';
 
	} else { // Invalid submitted values.
		echo '
<h1>Error!</h1>
 
Please enter a valid name.
 
';
	}
?>
<h2>Your Name</h2>
<form action="form.php" method="post">
 
First:
<input type="text" name="first" size="30" maxlength="40" value="<?php if (isset($_POST['first'])) echo $_POST['first']; ?>" />
 
Last:
<input type="text" name="last" size="30" maxlength="40" value="<?php if (isset($_POST['last'])) echo $_POST['last']; ?>" />
<input type="submit" name="submit" value="Submit!" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
 

So, if a user inputs a first name but no last name (or last but no first), it will show whatever the user has already typed (and preventing them from having to type it again)...if the form is lengthy, this is very handy and such a time saver.

Written by Kevin in: PHP, WebDev
Mar
21
2008
0

Multidimensional Arrays

Multidimensional arrays are basically arrays within arrays. So, let's make one.

 
<?
//Our first array is going to be for dairy products:
$dairy = array(1 =&gt; 'Milk','Cheese','Yogurt');//Our second array is going to be for animals:
$animals = array(1 =&gt; 'Cow','Duck','Horse','Chicken');
 
//Now let's pretend we wanted to combine these arrays (I should've chosen something like Months and Years or States and Territories...but I'm sticking with dairy products and farm animals ;) ....)
$combined = array('Dairy' =&gt; $dairy, 'Animals' =&gt; $animals);
 
//Idea: This is the best way to categorize interests for personalized profiles etc....
//Echoing what we've just done...
echo "I want to echo Cow!  {$combined['animals']['Cow']}";
 
?>

Of course, if you're just wanting to echo Cow, just use echo "Cow";...but if you're building things from arrays like drop down menus or if you're collecting interests, this is helpful.

Written by Kevin in: PHP, WebDev
Mar
15
2008
0

Sharing the voolia.com core

I started a sideproject called Voolia a few weeks ago so I could send multiple urls through Twitter. After getting it to a stable state (meaning it functions perfectly for what I want to do lol), I just left it alone. I checked the stats on it today to find that it has been getting some attention from random websites...pretty neat.

You might be surprised at how simple the base of the site is. It's under 50 line (counting empty lines and comments!) ...check it out:

 
<?
//define vars
$links = $_POST["links"];
$email = $_POST["email"];
$dateadded = date('Y/n/j');
 
//build callsign
// Notice that I don't user lowercase l and the number 1....too easily mistaken for eachother.
function createsign() { $chars = "abcdefghijkmnopqrstuvwxyz023456789ABCDEFGHIJKMNOPQRSTUVWXYZ";
srand((double)microtime()*1000000); $i = 0; $pass = '' ;
while ($i <= 2) { $num = rand() % 33; $tmp = substr($chars, $num, 1);
$pass = $pass . $tmp; $i++; } return $pass;}
$callsign = createsign();
 
//Check if callsign already exists...
 $q2 = mysql_query("SELECT * FROM links WHERE callsign='$callsign'");
   $q3 = mysql_fetch_object($q2);
    if($q3->callsign == $callsign) {
$callsign = createsign(); //do it again
}
 
//insert vars
$insertlinksquery = "INSERT INTO links (links, dateadded, email, hits, ip, callsign) VALUES ('$links', '$dateadded', '$email', '0', '".$_SERVER['REMOTE_ADDR']."', '$callsign')";
$runinsertlinksquery = mysql_query($insertlinksquery) or die(mysql_error());
 
//now do a foreach and insert each url within the murl as $callsign+1;
//first, we pull up what we just insertted ...i need to make this more efficient!
$result = mysql_query("SELECT * FROM links WHERE callsign='$callsign1'");
$row = mysql_fetch_array($result);
$linksrow = $row['links'];
 
$i = 0;
$chunks = spliti ("
", $links, 100);
//print_r($chunks);
foreach ($chunks as $value) {
if($value == "") { $newstring = "http://voolia.com"; $cliprow = "http://voolia.com"; } //get rid of empty links from bookmarklet and replace with voolia.com for kicks and giggles
$i++;
$individualcallsign = "$callsign$i";
$insertindividual = "INSERT INTO links (links, dateadded, email, hits, ip, callsign) VALUES ('$value', '$dateadded', '$email', '0', '".$_SERVER['REMOTE_ADDR']."', '$individualcallsign')";
$runinsertindividual = mysql_query($insertindividual) or die(mysql_error());
}
?>
 

Isn't that amazingly simple?...I think so. With just a tiny bit of .htaccess manipulation, you can have your own url redirection service....I find these handy.

Written by Kevin in: MySQL, PHP, WebDev
Mar
14
2008
0

Websites that should be more popular than they are

FaxZero.com - If you're making a casual fax, this is the way to go. It's free, it's online, and it's private. The only downside is the ad that is displayed on the coversheet. Other than that, the fax is 100% normal. Another great thing is it makes multiple delivery attempts so if the fax fails on the first attempt, a second try will come in about five minutes (tested this myself and love it).

The Ultimate Steal - If you're a college student, you can receive a discount on the Microsoft Office Bundle. I haven't tried this yet but I'm definitely going to in the near future. It's Microsoft Office Ultimate 2007 for $60.

JumpCut.com - For those fond of the "For Dummies" series, this is for you. JumpCut is a service from Yahoo! that provides online video editing with some really cool features and it's 100% free (even the storage space). I use it for all my small projects and just general playing.

IBuyJunkMail.com - From Steve Rhode. I used to talk to this guy every morning at Concord University before I went to class. He's a pretty nice fellow and this experiment of his might be worth your time if you're in need of cash quick.

Skip Forced Faceboook Invites When Adding New Apps (add this link to your quick links bar!)

Written by Kevin in: Misc., Personal
Mar
11
2008
0

Never lose track of time again!

With RescueTime.com, track all of your computer habits (both online and offline).

I first came across this website while searching for a to-do list manager. I started to pass it up but figured it looked well developed so I should give it a shot. Here are my current stats for this week (updates automatically every week...how awesome is that? You don't have to make your stats public, either...but what do you have to hide? haha!)

Click here to view my usage for this week.

Thus far, it seems to be fairly accurate. I only compared on day's worth of information that I had logged vs. what Rescue Time had on record. The information is logged, or so they claim, "Forever". Whether or not this is true, I do not know. Your stats are grouped by week, not day. There's also an option to add this information into an RSS reader or have it sent via SMS to your phone (why, I dunno)...The information is recorded by a frugal client that sits quietly in your system tray and sends information every half hour (you can change it at 30 minute intervals to whatever number you like) to the RescueTime site/database via SSL (requires port 443 access -- this shouldn't matter to most users). You can also turn off logging with two clicks anytime you want.

Give it a try: RescueTime.com.

Written by Kevin in: Personal
Mar
10
2008
1

My Top Five Favorite Firefox Addons

These are all used very frequently and always provide the information I was looking for or the result I was wanting. My favorite addon out of them all, though, has to be Screen Grab (number 4 on this list; it's just the way I ordered them).

Alexa Sparky
https://addons.mozilla.org/en-US/firefox/addon/5362
"Sparky is a free FireFox browser plugin built by Alexa, that accompanies you as you surf, providing useful information about the sites you visit without interrupting your Web browsing."

Cooliris Preview
https://addons.mozilla.org/en-US/firefox/addon/2207
"Cooliris Previews gives you the power to browse and share Web links and rich media faster. Just mouse over any link, and the Cooliris preview window immediately appears to show you the content. To email it, just click."

Google Advanced Operations Toolbar
https://addons.mozilla.org/en-US/firefox/addon/1258
"This toolbar provides a shortcut to some of Google's advanced search functions..."

Screen Grab
https://addons.mozilla.org/en-US/firefox/addon/1146
"Screengrab saves entire webpages as images..."

IE Tab
https://addons.mozilla.org/en-US/firefox/addon/1419
"IE Tab - an extension from Taiwan, features: Embedding Internet Explorer in tabs of Mozilla/Firefox..."

What are your favorite Firefox addons?

Written by Kevin in: Personal
Mar
09
2008
1

Handy PHP Shorts

I like simple things...things that require little effort on my behalf. Here are some php functions/"shorts" that will probably prove useful somewhere in your future.

Get META tag information from practically any website (works locally, too!)

$thetags = get_meta_tags ( 'PATH OR URL' );print_r ( $thetags);

Get a ton of information about a user's browser: (also check out phpsniff)

echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";$browser = get_browser(null, true);
print_r($browser);

Show the source of a file:

show_source("http://voolia.com");show_source(__FILE__);  //shows source of current file

Highlight source and number lines (great when you're stuck without an editor...no other use, in my opinion):

 
<style type="text/css">.line { float: left; color: gray; text-align: right; margin-right: 6pt; padding-right: 6pt; border-right: 1px solid gray;} </style>
 
<?php
function highlight_num($file)
{  echo '&lt;code class="line"&gt;', implode(range(1, count(file($file))), '&lt;br /&gt;'), '&lt;/code&gt;'; highlight_file($file); }
highlight_num('highlightfile.php');
?>

Create a very hard to guess unique id (impossible?) - php5 only:

 
$better_token = md5(uniqid(rand(), true));

Delay script execution (great for download scripts or advertising):

 
sleep(60); //in seconds.  this script will sleep for 1 minute as is.

Also check out time_sleep_until.

Print files in a directory:

 
$direct = dir('sample_directory/'); // the directory here
if ($direct)
{
while (false !== ($list = $direct-&gt;read())) {
if (!in_array($list, array('.', '..')))
{ echo "<a href='http://sampledomain.com/sample_directory/$list%5C%22'>$list</a>"; }
}
}
Written by Kevin in: PHP, WebDev
Mar
08
2008
0

Avoiding sql injection attacks

While I'm most certainly no expert on the subject of mysql injection attacks, I do know that, unless you have a ton of valuable information stored in your database, the "hype" of attack prevention is just that: hype. Most scriptkiddies aren't going to waste their time pulling junk information from your database (and besides, you should have a cron job setup to do automatic backups of your databases on a regular basis.

This is all my personal opinion, of course. Any of my sites could suffer possible attack tonight...I would worry too much about it. Just simply restore the most recent backup and THEN work on prevention (I don't have anything that crucial stored in vulnerable databases)...

Despite the above, here's a very basic php function to possibly deter or prevent an sql injection attack:

 
<?
function prevent($input){
    if(is_array($input)){
        foreach($input as $k=&gt;$i){
            $output[$k]=prevent($i);
        }
    }
    else{
        if(get_magic_quotes_gpc()){
            $input=prevent($input);
        }
        $output=mysql_real_escape_string($input);
    }
 
    return $output;
}
>
Written by Kevin in: MySQL, PHP, WebDev
Mar
07
2008
1

Intrinsic Form Values

Rather than type a long explanation of what exactly this is and what it does, it's best to just show you:


If you still don't understand what this does, here's a short explanation: Onfocus of form field, default value is automatically cleared and, if no value is entered, return the default value (onblur).Why use this? Personally, I feels it's a waste of space to label form fields (perfect example on the NY Times Login Page) ...it also looks pretty cluttered.Enough jibjab, here's how I do it (there are other ways, of course...but this one seems to work easiest and the best):

 
<input class="input" name="fieldname" value="Click in me then click away" onfocus="if(this.value == 'Click in me then click away') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Click in me then click away';}">
 
Written by Kevin in: Javascript, WebDev
Mar
07
2008
0

.htaccess Generator Tool

I took the time this morning to develop a very basic, simple .htaccess generator for those of you who, like me, don't like tinkering with .htaccess files and everything that comes with them.

So, without further adieu, check it out!

Do note that this was done in about an hour so I might have made a few mistakes.  If you notice something wrong, leave a comment.  Enjoy : )

Written by Kevin in: WebDev

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes