Twittrash – Twitter Trash and Other Scum on the Internet February 17, 2010
Posted by chris in : rant, seo , add a commentSo I recently started using twitter and you can follow me by going to http://www.twitter.com/cnizzdotcom. I had long been opposed to twitter because I thought it was useless. Of course I was initially opposed to myspace and facebook as well which I am currently using on or have used at one point. I guess I am sometimes a bit reactionary when it comes to knew things. Not just technology, but even certain technologies and methodologies in programming. This is a dangerous thing in my field, but I’m getting more progressive by the day. I laugh thinking about how years ago I stated to a co-worker “extending classes is a horrible idea.” Hey, if we were never wrong, then we’d never improve, right? So I take comfort in my opinions evolving as I become more knowledgeable.
So about a month ago I began using twitter. My use of twitter is really just an exercise in marketing my most important product across the internet, which is me! What I’ve learned in my month with twitter is that twitter is not much different than SEO blackhat, whitehat, and greyhat that you see with ranking in Google. In the SEO world you have scum that write bots (actually they are quite easy to write) which like graffiti in parks (the trashy kind) spam blogs and forums in an effort to win backlinks.
In the twitterverse its the same. You have twitbots, employed by twittrash that will follow someone for a few hours, maybe a few days (its hard to tell) and then unfollow them. All this is done automatically so the twittrash doesn’t have to do it manually. You’ve probably noticed this before. I noticed it right away and assumed it was some bot, but it was confirmed while reading a forum post over at DP. The poster advised another poster to “use a twitter automation program to auto follow then unfollow after time has passed and they don’t follow back.” The term twittrash immediately popped into my head.
There are legitimate ways of winning followers in twitter. It’s hard starting from ground zero and doing things legit (trust me I’m doing it now) but it can be done.
- Find people you know and start following them
- Use hashtags to reach a broader audience
- Write good twits and links to quality content
- Include links to your twitter page everywhere
If you already know the person and they know you are now following them its likely they will reciprocate.
When you use a hash tag such as #php or #embarassing it reaches everyone else listening for that hashtag. Of course spammers use these as well, but you glance over the spam and find the good stuff just like with anything else on the web.
This is a no brainer and its the exact same thing you do when optimizing for google.
Add a link to your twitter page on your facebook, myspace, blog, and to forum signatures
On the web and in life, when ever something good comes a long there will be [insert prefix here]-trash to try and ruin it. Twittrash is no different than snake oil salesman, politicians, and blog spammers. Thanks for reading.
How To Write a Page Controller in PHP for Dynamic Content February 6, 2010
Posted by chris in : php, seo , add a commentThis how to will cover the topic of creating a dynamic content system. It’s a well known fact that when you come across a site like wikipedia that they don’t have an html file for each article. That would be insanity. It would be nearly impossible to display the file tree in an IDE and cumbersome to search through even with an OS that has a slick file system and powerful shell like Linux. Trust me, I worked on a site that created a unique page for each product on their site (they’ve since gotten with the times). So how can web browsers access a page like http://en.wikipedia.org/wiki/Mike_Tyson, when that file doesn’t exist. The application uses a combination of server-side code, database storage, and apache htaccess magic. Here’s how to do this.
Apache HTACCESS
This is the most important part of redirecting dynamic content. The .htaccess file is what makes the magic happen. What happens is a user requests http://en.wikipedia.org/wiki/Mike_Tyson, apache goes to process the request and does its thing. Normally apache would redirect this to a 404 error page because the file does not exist, but if it see’s the .htaccess file in the directory, then apache will follow the rules we defined in the htaccess. Our rule will tell apache that if the file is not found, to go to some other file. We will call this file mycontroller.php (because its the controller in our ModelViewController). Below is some example code to get your started:
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.php
ErrorDocument 404 /404.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ mycontroller.php [L,QSA]
</IfModule>
Recap:
1. We have /public_html/mydomain.com/wiki/.htaccess
This overwrites the Apache Web Servers default operating procedures.
2. We redirect the request to /public_html/mydomain.com/wiki/mycontroller.php
This contains the server side code that will handle our request for the Mike Tyson article.
The Database
Going in detail on this topic is beyond the scope of this article, but you’ll need some sort of database management system to store your article on Mike Tyson and the thousands of other articles. Of course there are other options like an XML file, but a database such as MySQL is the sanest approach for most sites.
Server Side Code
You’ll need some sort of server-side code running whether is ASP, JSP, or PHP. I’m a bit partial to PHP so lets roll with that. In mycontroller.php your code might look something like this:
$uriArr = explode('/',$_SERVER['REQUEST_URI']);
$article = $uriArr[2];
$article = urldecode($page); // in this case the article equates to Mike_Tyson
$sql = "SELECT * FROM article WHERE name = '$article'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 1){
$page = mysql_fetch_assoc($result);
header('HTTP/1.1 200 OK');
header('Connection: close');
include_once 'mytemplatepage.php';
DIE():
}
else{
header('HTTP/1.1 404 Not Found');
header('location: /404.php');
header('Connection: close');
DIE();
}
This is asking our database for any records it has on the request Mike_Tyson. If a row is returned than we know we’ve found our article. We tell the browser that this is a 200 OK request. Then we include a file called mytemplate.php (this file is never actually seen by the browser). We set the record in the database to a variable array called $page. Our mytemplate.php file will look for this variable and begin populating the article. Lets see $page contains the following data: Title, Body, Image, and References. The mytemplate.php file might look something like this:
$title = $page['title ']; $body = $page['body ']; $image = $page['image ']; $references = $page['references ']; echo "<html><head><title>$title</title></head><body>"; echo "<h1>$title</h1>"; echo "<div class="mainImage">$image</div>"; echo "<p>$body</p>"; echo "<p>$references</p>"; echo "</body></html>";
Sweet! We can use the same template for a bunch of different articles, without having to create multiple files. Now if the user had searched for the following url: http://en.wikipedia.org/wiki/Mike_TysonIsEvil, we wouldn’t have an article on that. So instead the code would tell the browser this is a 404 Error and route the browser to the 404.php page.
This is an over simplified version of a dynamic content system, but it would work. If I was developing one of these on a professional level it would be complete with objects to handle requests, string cleaners to protect against SQL injection and XSS attacks, error logging, and the works! Let me know if you have questions I can answer and thanks for reading.
Optimizing Cnizz.Com For Page Speed and SEO February 3, 2010
Posted by chris in : seo , add a commentThis is the first installment of my SEO category. I’ve dabbled in SEO here and there every since I ran a semi-successful (but not successful enough) music site through 2006-2008. The site actually ranked highly for a few good SERPs and received over 10,000 unique visits per month. Though the site is a shell of its former self I still run adsense on it which brings in about $20 a month. Sighh, what could have been. In any case, I feel I’m qualified to talk about SEO to the limited audience this blog attracts.
I was just reading over @ SEOmoz that in 2010 page speed may be considered when ranking SERPs. I downloaded the google page speed for firefox plugin and decided to see where my domain sucked. The results are in:

86 out 100 isn’t too bad, at least its better than what my grades looked like in high school. Lets see what kind of optimizations I can make based off of Googles suggestions.
Image Optimizations
When the plugin says “Specify image dimensions” it’s just telling you that instead of having html for an image that is 50 x 50 like this: img src=”myimage.png” to instead specify its dimensions like this: img src=”myimage.png” height=”50″ width=”50″. Google also says serving scaled images is a no-no. Google become a bit angry because one of my images was 100×100, but I was scaling it in the HTML to be 50×50. Just open up your image editor (I use da GIMP cause I’m on Linux) and scale it to the dimensions you want. After these few modifications I reanalyzed my page and the plugin had bumped up my score to 90 out of 100. Woot! Thats an “A-” grade.
The next image optimization listed was the actual optimization of image compressions. Luckily the plugin will give you the optimized version and tell you how much space it will save. Just expand the “Image Optimization” box, click on the image, save it, and upload it to your server. This moved cnizz.com up to 91 out of 100.
Remove unused CSS
A lot of designers put their CSS into single file. Google advises against this and told me I could reduce the size of my CSS file by 19% (510 bytes) by removing CSS that was not used on the index page. Then something strange happened. Creating a second CSS file and only including that on pages were those classes were used caused by score to go down to 88 (remember I was at 91). Google penalized me for having multiple CSS files! I threw my hands up in the air on that one, marked it as nit-picky, and reverted back to my original CSS structure.
Leverage browser caching
This is the big one. I expect most sites to suffer from this. Its easy to resolve through the use of an HTACCESS file. I threw in the following code:
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|css)$"> Header set Cache-Control "max-age=3600" </FilesMatch>
This bumped me up to 94 out of 100. I could obtain 98 out of 100, by increasing the max-age to an insane amount of time. However on sites were the front page changes frequently such as a high volume e-commerce sites index page this is likely to be a bad idea. Just imagine if those thousands of users that just clicked through your adwords campaign were seeing last weeks special offers, yikes! However caching images that you know will not change unless there is a major site redesign is a good idea.
Conclusion
The google page speed plugin for firefox certainly gives you some great ideas for increasing the speed of your site and reducing the amount of bandwidth being pushed through your pipe. Lots of these suggestions can be implemented in a very short one day to one week project (depending on the size of your site). My advise is run the tool, but be cautious about the changes you make. Remember, you’re using this tool to potentially increase your listings for your targeted SERPs, but more importantly, this is a tool that should improve the experience of your sites users. As always there is balancing act between performance and features.
I welcome your comments