Entries from February 2008 ↓
February 27th, 2008 — How to, PHP
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!
February 26th, 2008 — Web Development, Wordpress, Wordpress Functions
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>
February 26th, 2008 — Google Analytics, Wordpress
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
1. 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!
February 25th, 2008 — PHP
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.
February 23rd, 2008 — Web Development
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.
February 22nd, 2008 — games, Gaming Consoles, Wii
February 8th, 2008 — JavaScript, MySQL, PHP, Web Development
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-><strong>field_name</strong>}\";\n\t\t";
$i++;
}
print $jarray."\n";
}
Put your own info where the Text is bold