Nov
21
2008
0

An interview with Shouts & Hollers

Shouts & Hollers is an online "ezine" of sorts that is published by Charleston, WV, area bloggers.  Bill Gardner got in contact with me to answer a few questions regarding a recent sideproject of mine.  Read it here.

Thanks Bill!

Written by Kevin in: Misc., Personal, WebDev
Jul
22
2008
1

Masking PHP via .htaccess

What we're doing: turning the .php extension into .whatever
Why we're doing this: security, seo, or because you want to (then you'll have to answer why for yourself)
How to do this:

In your .htaccess file, we're going to tell apache to parse your choice of a single or multiple .whatevers as php.
So if we wanted to parse .html files as php, we would do something like this:

AddType application/x-httpd-php .html

And if we wanted to parse .bunnyboyfoofoo files as .php:

AddType application/x-httpd-php .bunnyboyfoofoo

And if we wanted to parse .bunnyboyfoofoo, .html, .htm, .py, .kevinsmith, .google files through php:

AddType application/x-httpd-php .bunnyboyfoofoo .html .htm .py .kevinsmith .google

Simple and fun to play with if you're that type of person.

PS:  Sorry it has been so long since my last update...it's summer, I've been enjoying it.

Written by Kevin in: PHP, WebDev
Jun
03
2008
0

301 Permanent Redirect PHP and HTACCESS

Just to compare two of the different ways to effectively do a proper redirect...

PHP:
(old.php)

<?
header ('HTTP/1.1 301 Moved Permanently');
header('Location: http://kevinsmithdesigns.com/new.php');
exit;
?>

.HTACCESS

 
Redirect 301 /old.php http://www.kevinsmithdesigns.com/new.php
 

--------------
I much prefer .htaccess so you can delete old.php and keep track of all redirects via one file (.htaccess).
.htaccess is also probably the safest way to redirect (if you're the SEO conscious type)

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

Javascript onfocus-onblur, show-hide table-div

For an example, visit SecretTweet.com and click in the textbox up top--the only textbox on the whole page. The captcha, tags field, language field, and submit button all are hidden until needed by the user.

<html>
<head>
<script type="text/JavaScript">
<!--
function showthetable(theTable)
{
      if (document.getElementById(theTable).style.display == 'none')
      {
            document.getElementById(theTable).style.display = 'block';
      }
}
//-->
</script>
</head>
 
<body>
<textarea name="whatever" cols="55" rows="2" onfocus="showthetable('TABLENAME');return true;"></textarea>
 
<div class="options">
<table border="0" cellpadding="0" cellspacing="0">
<tr id="TABLENAME" style="display: none;">
<td>
Hidden content until onfocus!  Hooray!
  </td>
</table>
</div>
 
Written by Kevin in: Javascript, WebDev
Apr
29
2008
0

Insert Ads Between MySQL Results

If you are pulling information from a mysql database and want to insert either ads (like adsense) or just repeat the headers after every X amount of results, here's my way of doing it:

<?
//connect to the mysql database\
//I always like to define the value of $i as 0 just to keep things straight in my mind.  You can set this to whatever number you want to start counting from
$i=0;
 
//The query -- this is an example from one of my sites.
$result55 = mysql_query("SELECT * FROM table WHERE safe='y' AND language='english' ORDER BY timedate DESC LIMIT 10");
 
//Do the basic while statement
while($row = mysql_fetch_array($result55))
{
//Set the count of $i to plus 1
$i++;
//echo your results
echo $row[id];
//create an if statement and print out an ad on whatever number you like.  Since I limited my query to ten results, I'm going to print an ad after the 5th result (in the middle, obviously).  Note that adsense will only allow you to print three ads on any given page.
if ($i == "5"){ ?>
INSERT ADSENSE CODE HERE
<?
}
?>
 

See a working demo of this at www.SecretTweet.com -- the ad script is repeated after every 3rd ad when the query limits the results to 10. This way I can achieve the maximum number of ads allowed by google while spreading out the ads evenly within the results.

Written by Kevin in: MySQL, PHP, WebDev
Apr
05
2008
1

Personal Review of Firefox 3 Beta 5 & Screenshots

I recently downloaded Firefox 3 Beta 5 (the supposed last stage of beta for the new browser) and, after a few hours of usage, decided to note a few things about it.  I'm no professional developer or anything; I'm just sharing my opinion on things.

Firefox 3 Screenshot

What I'm Sure I Like:
GMail is much faster.

Firefox 3 Screenshot
The Applications tab in Options.  Makes me happy.

Firefox 3 Screenshot
The new Page Info options.
The new Malware Protection.  ThumbsUp!

Firefox 3 Screenshot
Multiple text selects via the control key.

Firefox 3 Screenshot
The new download manager.  It's clean and you can pause/resume downloads efficiently...awesome.


What I'm Sure I Don't Like:
Folder menus seem to lag quite heavily sometimes.  This might have been my computer having a blonde moment, though.
Only one of my extensions for FF2 had an upgrade...but this has nothing to do with Firefox..I just don't like it lol.

Firefox 3 Screenshot
The default theme's back-forward navigation buttons -- They're soooo close together I found myself repeatedly hitting back instead of forward (and forward instead of back).  Eventually, I went to Backspace and Shift+Backspace.


What I'm Unsure About:
Smart Bookmarks -- While it's a nice idea, put most used bookmarks and recently visited sites in a folder on the quick links bar totally eliminates the usefullness for me.  I have most most visited sites on my quicklinks bar already.  And if they would have left the recently visited/address bar alone, there wouldn't be a problem in the first place.  Which leads me to my next point:

Firefox 3 Screenshot
The new recently visited dropdown address bar
Firefox 3 Screenshot
Tabscrolling forward and reverse.  It just doesn't seem efficient to me.
Firefox 3 Screenshot
Bookmark tagging (just like del.icio.us and other services) -- Good idea for webservices but I'd rather stick to the basics with my applications.


What I'm Indifferent About:
Firefox 3 Screenshot
The hyped "One-Click Site Info!" -- this was available before (with two clicks) and really doesn't have that much of an impact on me.

Written by Kevin in: Misc., Personal, WebDev
Apr
01
2008
0

Javascript Expand/Collapse Element

Note: This piece of code wasn't entirely created by me. Also, I don't claim to be knowledgeable in javascript...I'm just sharing.

function expandCollapse() {
for (var i=0; i<expandCollapse. »
arguments.length; i++) {
var element = document.getElementById »
(expandCollapse.arguments[i]);
element.style.display = (element.style. »
display == "none") ? "block" : "none";
	}
}

Which will allow you to expand and collapse a div in css. I needed this for a new addition to VisitMatewan.com that I'm working on. Handy....

Written by Kevin in: Javascript, WebDev
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

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