Entries from February 2008 ↓

How to remove the file extension: Stripping the String, PHP substr() function

Striping the file extension is valuable on many levels.

<?php

$filename = foobar.exe
function returnFileName($fileName) {

return key(explode(“.”, $fileName));

}
// returns foobar

function returnFileExtension($fileName) {

return end(explode(“.”, $fileName));

}

// returns exe

?>

Result: foobar

Note: Spaces count, so count them!

Display WordPress Post Number on Single Page with post ID

You can see it work throughout this wordpress blog, to the right you see DCE Article 94. Notice you can select the number as text. The number is pulled from the post on every single page by placing this line of code in your wordpress single.php template page.

<?php the_ID(); ?>

Note: When using this line of code be sure it is between these two lines of code in your single.php page

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php endwhile; else: ?>

I place the code in its own div with a background image to create the illusion of unity. I use margins to move the number to the right spot of the image. My CSS and Code looks like this.

<style>
#page_number_id_spawn { float:left; text-align:right; margin-top:240px; width:135px; color:#900; font-size:30px; font-family:Georgia, ‘Times New Roman’, Times, serif;}</style>

<div id=”page_number_id_spawn”><?php the_ID(); ?></div>

Spammers causing inaccurate Bounce/Exit Rates in Google Analytics – Ban Ip Ranges

My letter to Google:

I’ve recently been revamping my site, from studying the analytics i’m getting a high bounce rate because a great deal of my visitors spend 0.00 time on the site with 100% bounce and exit. These visitors are usually from outside the US. I run wordpress as my CMS, I know there is spam problem from people wanting to post comments with advertisements. I have blacklist set up to prevent this the posting, but they still are registering as hits. How can i prevent the spammers from effecting my Analytics data?

The solution:

Create a filter for excluding IP addresses from your data. You can create filters that block a large number of IP addresses that you receive spam data from. You have also mentioned that these visits are mostly from outside US. For this, you may consider creating filters to exclude data from a geographic region.

The filter to exclude all data from an IP address works to exclude clicks from certain sources. You can enter a single IP address, or a range of
addresses.

To create a custom Filter

Prevent inaccrate Analytics data by blocking spammers1. Log in to Google Analytics.
2. Click ‘Filter Manager.’
3. Click ‘Add Filter.’
4. Enter a ‘Filter Name.’
5. Under ‘Filter Type’ choose ‘Custom Filter.’
6. Click ‘Exclude’ and within ‘Filter Field’ choose ‘Visitor Geographical
Region.’
7. Enter the appropriate filter pattern.
8. Apply this filter to the appropriate ‘Website Profiles.’
9. Click ‘Finish.’

You can figure out what IPs to block by check your map overlay in Analytics. Display the full list of countries, pick out the countries with 00:00:00 time on your site, and block that countries IP range.

My offenders this month are: Turkey, Russia, Greece, Ireland (which makes justsherlock sad), Mexico, Switzerland, Portugal, Brazil, Singapore (not a country), New Zealand, Bulgaria, Vietnam, Spain, Czech Republic, and it goes on.

Since these aren’t justherlock’s myspace girlfriends we can block them. Lets start with my girlfriends in Turkey, then Russia.

Here is a link to all the IPs to ban: IP Ranges for TR [Turkey]
Below is an example of the code produced when using a range of IPs from that list and this Google tool: IP Ban Tool

^217\.195\.(1(9[2-9])|2(0[0-7]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$

For Russia the list gets larger: IP Ranges for RU [Russian Federation]

From writing this article and seeing the work, it doesn’t seem worth its weight in labor, so you welcome to do it (post your results). I ended up just banning my own IP so I do not skew the numbers. What I’m considering doing is taking these IP country lists and Banning them through my .htaccess file. USSR you win…. for now!

HTML POST PHP Array Debbugging code that tests passing variables

Great PHP code that displays how the arrays break down when passing from HTML forms to $_POST variables.

echo “<pre>”;
print_r ($_POST);
print_r ($_FILES);
echo “</pre>”;

This helps when juggling multiple files or big database entries.

New Design for DCE: SEO, Legibility, 1024 Screen Design

Please note, the site will look funky between Saturday Feb 23rd 6pm Eastern – Sunday Feb 24th 6pm. During this time we will keep the content legible, but the navigation system maybe be shaky. Please comment to help out!

Changes are going to revolve around overall legibility and typography, smarter advertisements, more contrasting color scheme, usability, 1024 screen design, and a big SEO package.

With the last DCE 0.9 design we averaged 900-1000 hits on a 30 days rotation. In the next 30 Days I will post the numbers back on this Page.

Ghost Squad and Wii Zapper, Fun for Everyone

Ghost SquadGhost Squad is the most fun Light Gun game going for the Wii, at this point and time. Ghost Squad is easy to play and pick up, anyone who can point and click can play. The game originates from an ultra cheesy arcade shooter produced by SEGA. With Wii they added in party mode, new options to the missions, a training segment, and an option to upload scores high scores with Wii Connect. In party mode you can play with up to Four players and do not need 4 Wii Zappers. The single player mode game starts with 3 missions that grow larger with more options as you continually beat them. The levels of the Missions increase, which means more Bad Guys spawning from suitcases and couches! As you play you can unlock a large number of weapon that fire different and different Skins for your Characters.

Get the Wii Zapper and Some of those pistols and have a blast listening to the cheesiest dialog while you annihilate terrorists that spawn from chairs and suitcases. Its truly amazing how they got 150+ terrorists on airforce one without anyone noticing!… sneaky t’s

Umbrella Chronicles is a great game for 2 player mode, but not to have fun with a group.

Before going out on Fridays we have Ghost Squad pre-game sessions (no more beer pong). The fun consists of Two Wii Perfect Shots (which we fight over) and Two Wii Zappers (which comes with links crossbow training). Then we make inside Ghost Squad cracks all night, chicks are into the Ghost Squad guy who can complete all three missions.

Create a Javascript Array with PHP from a MySQL Database Table

Wrote this function to check email addresses already in a database, so I dont have to change pages, and check with javascript. Problem: it exposes your whole email list to the public in the source code, and the source code can become a monster length. So it isnt practical, but it works. (I’m not using it to check emails)

The script proves useful to do other things with javascript and spawn arrays to manipulate data… etc.

function jarray(){

$sql = "SELECT * FROM <strong>table_name</strong> LIMIT 0, 100000000";
$jarray = "var <strong>your_array</strong> = new Array();\n\t\t";
$i = 0;
$q = mysql_query($sql);
while($object = mysql_fetch_object($q)){
$jarray = $jarray."<strong>your_array</strong>[{$i}] = \"{$object-&gt;<strong>field_name</strong>}\";\n\t\t";
$i++;
}

print $jarray."\n";
}

Put your own info where the Text is bold