Auto-Notification of Broken Links, Fantastic Pre-Written Anti-Spam .htaccess File!
Recently I’ve been learning a bit about .htaccess, redirecting visitors who come via now-broken links.
To help with this, I inserted a little mailer script into my error 404 page that sends me an email containing the referring URI, the URI the visitor was trying to reach and various other tidbits of information. It works well, allowing me to quickly fix broken links that I would otherwise be unaware of.
It also writes the beginning of a rewrite rule, as if I wasn’t lazy enough.
Here it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <? php //mail me about this error... $to = "mike(@)pagesofinterest(.)net"; $base = "http://pagesofinterest.net"; $referrer = $_SERVER['HTTP_REFERER']; $requested_page = $_SERVER['REQUEST_URI']; $agent = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; $subject = "Error 404 - $requested_page"; $body = "The page: $requested_page, referred to by $referrer does not exist. Fix this or add a rewrite.\n\nAgent: $agent\n\n"; $body .= "IP: $ip \n\n"; mail($to, $subject, $body, $headers); //append to file: $redirect = "Redirect 301 $requested_page http://pagesofinterest.net/\n"; $filename = "redirects.txt"; $fh = fopen($filename, 'a'); fwrite($fh, $redirect); fclose($fh); ?> |
Use:
sort redirects.txt | uniq > unique_redirects.txt
In a terminal to get a smaller file containing only unique broken links.
One problem was the sheer volume of messages I was getting. I did some research, and it seems this site has become the target of spammers. After a bit of googling on how to discourage this, I came across the best thing a newb could hope for: a perfect, commented example. Aaron Logan has graciously made his .htaccess file available to the world. It handles bad user agents, known bad IP’s, and keywords in referrer URI’s. It is gold.
You can get your own copy of it here: best anti spam .htaccess file.
Thanks Aaron!
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
JS-Kit Recent Comments PHP Script
Jealous of people able to display their blog’s recent comments in the sidebar, I wrote this little script.
It reads recent posts from your site’s comment rss feed and prints n comments out in a nicely formatted div. Using it is as simple as changing one line, uploading the file, and pasting some code wherever you want the recent comments to be displayed.
I tried to make a javascript version, but I the cross-domain AJAX issue thwarted my attempts. Instead I wrote it in PHP – if you don’t have PHP enabled on your hosting then you won’t be able to use this script, sorry!
To use the script, first download it.
Open the file in a text editor. Change the ‘$commentsRSS’ value to your JS-Kit Comments RSS URL. This is the line:
4 | $commentsRSS = 'http://rss.pagesofinterest.net/'; //change this to your comments rss feed |
To find your RSS URL, look here: Customizing JS-Kit Comments. Scroll until you see “Setting up the RSS”.
Once you’ve changed that variable, rename the file to “recent-comments.php”, and upload it to your server.
Take note of where you uploaded it to.
Paste
< ?php include('PATH_TO/recent-comments.php') ?>
wherever you want your recent comments to be displayed.
Change “PATH_TO” to the path to the file, e.g. “http://pagesofinterest.net/code/download/recent-comments.php”. Remove the whitespace between < and ?.
Save, then load the page in your browser. You should see your recent comments displayed wherever you pasted the code.
If you see a strange error message instead, try pasting the contents of the recent-comments.phps file wherever you want the recent comments to be displayed, instead of the above “include” statement.
Any problems, leave a comment and I’ll try to help.
To learn more JS-Kit tricks, read the following posts:
JS-Kit Comments + Greybox on Any Page
Fancy Footer
JS-Kit Comments for Each Blog Entry
JS-Kit Comments: Correct Usage of the ‘Permalink’ and ‘Path’ Attributes
Styling JS-Kit Comments
JS-Kit Comments: Correct Usage of the ‘Permalink’ and ‘Path’ Attributes
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
Exec-php and WP-Syntax Caveat
While migrating my blog articles from Rapidweaver to Wordpress I stumbled across some rather odd behaviour. All posts in http://pagesofinterest.net/blog/2008/06/ were displaying a garbled version of a particular post in that directory. The bottom of each affected post had the following php error message:
Fatal error: Call to undefined function insert_comment() in /home/pagesofi/public_html/wordpress/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 131
After much investigation, I narrowed it down to one thing – Exec-php and WP-Syntax battling for control.
Exec-php was attempting to execute the line below, when there was no whitespace between
<? and phpFor example:
<? php insert_comment("","","http://pagesofinterest.net/mikes/blog_of_interest_files/fancy_footer.php","Fancy Footer - Usage and Tips","","Like these snippets? Leave a comment!",""); ?>
Obviously, I can’t show you the code that causes the craziness.
Keep this in mind if you’re also using these plugins together. If you do run into this problem, open the post that is causing it for editing, and copy its entire contents into a text editor. Paste each line into the Wordpress edit text area, and press save, then view the post. Continue until you see the above error. Fix this line, then continue down the post. The point of this is to find each line that causes this error, and to fix it.
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
Fancy Footer Update
I’ve updated the Fancy Footer snippet, now Trackbacks/Pingbacks will be able to find your posts – the previous version’s implementation was … lacking.
The previous snippet used the post permalink as both the permalink and the path – the Trackback/Pingback system didn’t like “http://“ being included in the path attribute.
I was afraid that I wouldn’t be able to find a solution that allowed us to have Trackback/Pingback support and keep our existing comments.
I am glad to say that my fears were unfounded, and I managed to come up with a solution. The snippet now parses out the “http://domain.com” part of the permalink, and uses that for the path attribute for the widgets. Happily, JS-Kit must do a similar thing, as it hasn’t messed up my comments (the path attribute is what JS-Kit uses to determine what page to display which comments).
The snippet may be downloaded here. To learn how to use this snippet, read Fancy Footer – Usage and Tips.
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
Fancy Footer
Update: Added Trackback/Pingback to prefix snippet.
After being annoyed at the time it took to add my typical blog-post footer (RSS, Email subscription links, Social Bookmark links, JS-Kit comments), it finally dawned on me that I could do all this with one PHP script, have 1/3rd the code at the bottom of each post, and easily change the footer of EVERY BLOG POST AT ONE TIME.
The last thing was the decider, as I recently changed the width of my entire site, and wanted the comments/social bookmarks list to fit nicely with the new width, but didn’t relish the thought of changing the fiddly code I use at the bottom of each post.
So I created a PHP script that is included in the “Prefix” of my blog pages. It consists of one function that is passed a few pieces of information, and spits out a nicely formatted footer section.
This post will explain how to use this script in your site. I have packaged the script + prefix + function call into three snippets, which can be downloaded here: Fancy Footer.
1) Double click on the snippets to install, close and reopen RW. Press ⌘5 to open the snippet window, and find the “PREFIX – RSS, Email, Social Links, Comments + Ratings Inserter” snippet. Double-click on this snippet to go into edit mode.
2) I have labeled each segment clearly, so that you may easily delete those you do not wish to display in your blog. As an example: I do not want the RSS/Email links to display. I press ⌘5 to open the snippet window, and double click on the PREFIX snippet. I search for the line:
//DON'T WANT EMAIL/RSS LINKS? DELETE FROM HERE:"Then select the lines between it and the line that reads:
//TO HERE!Then I press delete. The script will no longer output RSS/Email links.
The Social Bookmark links come in two flavours: one with links that behave normally, with the page loading in the current window. The other has links that will open in a Greybox, if Greybox has been set up in your theme. Jan Erik Moström has written an excellent tutorial explaining how to set a theme up for Greybox. It can be found here: RapidWeaver – using Greybox in a theme. If you decide to use the Greybox enabled section, comment the standard section out, and uncomment the Greybox section, as per the instructions within the file.
If you decide to use the RSS/Email and/or Social Bookmarking Sections:
a) The RSS/Email and Social Bookmarking sections require the images included in the download. These images need to be uploaded to your server. Do this with an FTP program, then open your browser and find the folder you uploaded the images to and copy the URL.
As an example: the images used in my footer are located at: http://pagesofinterest.net/images/, and this is the URL that I would copy for this step.
b) If you closed the snippet window, reopen it and double click on the PREFIX snippet to open it for editing. You will need to replace PATH_TO with the URL you copied in a, above. I find this easier to do within a text editor using Find & Replace. To do this simply select the entire text of the snippet and copy it into a text editor window, then use Find & Replace to replace PATH_TO with the URL you copied. When you’re done, double check the new text. Where an image’s src tag read “src=”PATH_TO/image_name.jpg”", it should now look something like (using the example URL):
"src="http://pagesofinterest.net/images/image_name.jpg"
Now select all of the text and copy it back into the snippet window. Press save.
The Email and RSS section require you to have an RSS feed for your blog, and a “subscribe to this blog via email” page. If you lack one of these, you won’t be able to use this section. Just delete it, as described above.
3) The JS-Kit section is highly customizable. I have set it up so that there will be a “comment count” line with 5-star user-ratings below. Beneath these will be a “Leave a Comment!” link, under which the comments will be displayed.
Note that any part of the JS-Kit section can be changed. As there are such a large amount of options, I’ve created a list of the parts I think you’d most likely want to play with:
Type:
- The ratings widget may be configured to display in three modes: combo, split and score.
Combo displays one row of 5 stars.
Split displays two rows of 5 stars – the left row represents the total rating, the right the user’s rating.
Score is actually an entirely different method of rating – thumbs up/down.
Once you’ve decided which you would like to use, replace “view=’combo’” with your desired style.
Options:
1 | view='split', view='score', view='combo' |
starColor='Golden':
- Colour of rating stars. Colour options: Ruby, Red, Golden, Blue, Green, Emerald, Indigo, Violet.
No ratings:
- Delete the following:
1 | <div view='split' class='js-kit-rating' title='".$post_title."' permalink='".$post_permalink."' path='".$post_permalink."' starColor='Golden'></div> |
paginate='10':
- No more than 10 comments will be displayed. If there are more than 10 comments, they will be split into “pages” that are accessible via small links or arrows at the top/bottom of the comments section. If you do not care how many comments are displayed at a time, remove this.
Anything coming after “Label:”:
- Will be displayed as a label. Change this text to whatever you wish.
The line:
1 | <div class='js-CreateCommentBg' style='width:100%;border:none;'> |
- style='SOME_CSS_STYLE' your desired styling options here. currently set so that the comment area will be as wide as the div it is
nested in.
The line:
1 | <div><textarea name='js-CmtText' rows='6' cols='62' style='width:550px;height:200px;'></textarea></div> |
- cols='XX': where XX = the number of columns for the comment text area.
- style='SOME_CSS_STYLE' your desired styling. Currently set to be 200px high and 550px wide.
The line:
1 | <div class='js-commentAvatarArea' style='min-width:550px;max-width:551px;'></div> |
- style='SOME_CSS_STYLE' your desired styling. If changing width, you must use both min and max values – it is a hack fix but it works.
Remember that everything here is open to alteration. Don’t like the order in which components are displayed? Swap their position and see what happens!
4) Open your blog page. Press ⌘⇧I to open the Page Inspector, select the “Header” tab. Now select the “Prefix” tab, and drag the modified snippet into this field.
5) Assuming you are using the JS-Kit Comments sections, change to the “General” tab of the Page Inspector. Check the “Footer” box, and copy whatever footer text you normally use into it. Append the following to this:
1 | <script src="http://js-kit.com/comments-count.js"></script><script src="http://js-kit.com/comments.js"></script><script src="http://js-kit.com/ratings.js"></script> |
These are required for JS-Kit to function. Placing them in the footer means that the important stuff – your blog content – will load more quickly. The loading of these scripts will not cause the page load to “freeze”.
6) Choose a blog entry and drag the BLOG ENTRY snippet to whatever position you want the items to appear. Select the code that appears and press ⌘. to ignore formatting. This is very important.
The “filler” parts that are within the insert_comment() brackets need to be replaced with your information:
RSS_URL: The URL pointing to your RSS feed.
EMAIL_SUBSCRIPTION_URL: The URL pointing to your “Subscribe to this blog via Email” page.
POST_FULL_PERMALINK: The FULL permalink for this post. As an example, for this page this is:
“http://pagesofinterest.net/mikes/blog_of_interest_files/fancy_footer.php”
POST_TITLE: The title of this post.
SCROLL_FROM_TOP_TAG: The tag for the div a “Scroll to Comments” anchor would scroll to, if you were using Scroll to Anchors With jQuery.
LEAVE_A_COMMENT_LABEL: The label for the “Leave a comment” link that when pressed allows a visitor to leave a comment.
SCROLL_TO_TOP_TAG: The tag for the anchor that would scroll to the top of the page, if you were using the above scrolling method.
IMPORTANT:
If you decide not to use any of the sections or scrolling, you MUST replace values related to those sections with empty quotes. As an example, here is a fancy footer BLOG snippet that is not displaying RSS or EMAIL links, and does not use SCROLLING:
<? php insert_comment("","","http://pagesofinterest.net/mikes/blog_of_interest_files/fancy_footer.php","Fancy Footer - Usage and Tips","","Like these snippets? Leave a comment!",""); ?>
Notice the use of empty quotes in place of variables that are not required. Not doing this correctly will give visitors an error page instead of your lovely blog post.
That’s it!
Probably best to try this out on a test blog (I did) before committing changes to your precious main blog. Play with it, publish it to a server and see if the results are what you expected. When you’re sure you have it how you want it, copy the code over to your main blog.
I’ve used a stylesheet to style my JS-Kit comments , and I am really pleased with the result. I plan on writing a post explaining how to style comments, and will link to it from here when it is done.
Enjoy!
To learn more JS-Kit tricks, read the following posts:
JS-Kit Comments + Greybox on Any Page
JS-Kit Comments for Each Blog Entry
JS-Kit Comments: Correct Usage of the ‘Permalink’ and ‘Path’ Attributes
Recent Comments PHP Script
Styling JS-Kit Comments
JS-Kit Comments: Correct Usage of the ‘Permalink’ and ‘Path’ Attributes
Scroll to post title
Chinese Idiom Database Updates
I hit a brick wall with my plugin development, so I spent some time updating the Chinese Idiom Database.
A long time ago a kind person emailed me with some suggestions for the database. I thought all of his ideas were wonderful, and have just finished implementing them all, plus some minor improvements to the code, which will make further updates less painful. As this database was my first attempt at PHP programming, the code was … messy.
I also implemented a few things I wanted to do a long time ago, but couldn’t because of the state the code was in.
These are the changes:
There is now an “All Idioms” page that displays all the idioms’ English meaning, which will make it possible for people just starting to learn Chinese to browse idioms.
Both the English and the Chinese “All Idioms” pages’ links open in a Greybox above the page, which avoids a full page load.
One may move forward or backwards through the idioms within the Greybox, using the “Previous, Next” links.
Idioms may be given thumbs-up/down ratings.
Each time an idiom is returned as a search result or viewed by following a link from one of the “All Idioms” pages, a count is incremented. This will allow us to see which idioms have been viewed the most, which will give me some idea of how many people actually use the database (if any at all).
The hardest part was making the Greybox pages show the “Next/Previous” links, but that was only hard because I am a still pretty new to MySQL. During the page generation, I needed to be able to pull the idiom/English translation from the next and previous entries in the list of all idioms. After much irritation, I managed to do it like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | $result = mysql_query("SELECT * FROM idioms WHERE zh_idiom!=''") or die(mysql_error());
$result_copy = mysql_query("SELECT * FROM idioms WHERE zh_idiom!=''") or die(mysql_error());
$prev = mysql_result($result_copy, mysql_num_rows($result_copy)-1 ,'zh_idiom' );
$next = mysql_result($result_copy, 1 ,'zh_idiom');
$count = 0;
while($row = mysql_fetch_array($result)) { //make one page for each idiom
$file_name = $row['zh_idiom'] . ".php";
$file = fopen($file_name,"w");
$update_count = "<?php ".'$'."dbhost = 'localhost';
".'$'."dbuser = 'pagesofi_student';
".'$'."dbpass = '".'$'."a|Qt;jXg+Nf';
".'$'."dbname = 'pagesofi_idioms';
".'$'."conn = mysql_connect(".'$'."dbhost, ".'$'."dbuser, ".'$'."dbpass) or die('Error connecting to mysql');
mysql_select_db('pagesofi_idioms');
mysql_query(\"UPDATE idioms SET times_accessed=times_accessed+1 WHERE zh_idiom='".$row['zh_idiom']."'\") or die(mysql_error());
".'$'."result = mysql_query(\"SELECT * FROM idioms WHERE zh_idiom='".$row['zh_idiom']."'\");
".'$'."count = mysql_fetch_array(".'$'."result);
?>";
$top = "<META http-equiv=Content-Type content='text/html; charset=UTF-8'><head><link rel='stylesheet' type='text/css' media='screen' href='idioms_individual.css' /></head>
".$update_count ."
<title>".$row['zh_idiom']."</title>
<html><body><p></p>
<p>".$row['zh_idiom']."</p><br>".$row['pinyin']."<br><br>". "<p1>".stripslashes($row['en_translation'])."</p1><br><br><p5>" . $row['example'] . "</p5><br/><br/><p2>Keywords: " .$row['key_word']."<br/>Viewed <?php echo " .'$'. "count['times_accessed'] ?> times. <br/>Entered by ".$row['creator']." on ".$row['date_created']."</p2><br/><div class='js-kit-rating' view='score' title='".$row['zh_idiom']."' path='".$row['zh_idiom']."' permalink='http://pagesofinterest.net/idiom/search_results.php?zhongwen=".$row['zh_idiom']."'></div>
<div id='nextPrev'><a id='prev' href='".$prev.".php'>Previous</a><a id='next' href='".$next.".php'>Next</a></div>
<script src='http://js-kit.com/ratings.js'></script>
</body>
</html>";
fwrite($file, $top); |
I’m sure that my way is not the best way, but it works. If the database ever becomes massive, or I can’t find anything better to do, I’ll look at changing it.
As this script is only run when an idiom is added, so a little inefficiency is OK, right?
Shhh… I’ll make it better later, promise!
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
Roy’s Wordpress Cumulus Tag Cloud in Rapidweaver!
MAJOR UPDATE: This tutorial has been updated to work with the new version (1.14) of Roy’s Cumulus Tag Cloud. The embed script has changed significantly. If you had trouble with the last version, give this one a try – it has been improved a lot!
If you scroll down and look left, beneath the menu you’ll see a new addition to the page.
I’ve managed to find a way to integrate Roy’s awesome tag cloud plugin with Rapidweaver’s blog page.
And now that you’ve seen it, I figure you’ll want it too – and this is how to do it:
Note: requires php – will NOT work on .Mac.
This tutorial has been written with the “code-phobic†in mind. It may bore you with details that you feel are obvious. If so, just skim read until you find the parts that interest you. I’ve included screenshots of various steps in the process – to view the full size images, just click on the thumbnail of each image. The image will load on top of this page.
If you feel that this tutorial is too complicated, or you run into any problems, please let me know by posting a comment below.
As long as your server has PHP, I am confident that you/we will be able to get this beatiful tag cloud going.
1) Make a blog page. At this time, the script does not work with Rapidblog. I will look into this when I have finished a few other projects I have going.
2) Add some blog entries.
3) Download the tag cloud file pack here. This It contains a snippet that is used to insert the cloud, the swf file, “swfobject.js” and “cloud_creator.phpâ€, that gets tag information.
4) Upload both “tagcloud.swf†and “swfobject.js†to your server. Note URL that points to these files. If you’ve uploaded them to the root directory of your server, then the path will look like: “http://your_doman_name.com/tagcloud.swf†and “http://your_doman_name.com/swfobject.jsâ€.
5) Upload the “cloud_creator.php†file to your blog’s “files†directory. The directory will either be called “files†or “blog_name_filesâ€. The first image shows an example of each. The second image shows an example of how the blog files directory should look before the “cloud_creator.php†file has been uploaded.
6) Open “cloud_creator.php†in your browser. You should see a blank page.
7) Make sure “cloud_creator.php†is working. Check that “cloud_file.html†has been created in the blog files directory.
8) Change the page’s extension to .php.
9) Change the sidebar to HTML
10) Drag the snippet into the sidebar. Change the addresses to match your site. If you aren’t happy with the default tag text colour, change the last 6 numerals of:
0x333333
to any hex colour. I use The RGB Colour Calculator to get my hex values.
11) Change the URLs in the following two lines to match your site, then paste them into the header.
For example, from:
1 2 | <script type="text/javascript" src="http://pagesofinterest.net/mikes/swfobject.js"></script>
<? include('http://pagesofinterest.net/mikes/blog_of_interest_files/cloud_creator.php'); ?> |
To:
1 2 | <script type="text/javascript" src="PATH_TO/swfobject.js"></script>
<? include('PATH_TO/cloud_creator.php'); ?> |
12) Publish your page – you’re done!
Thanks for reading – if you like this tag cloud, head over to Roy’s Site and let him know!
13) With the updated version of the flash file, there are a few extra options worth mentioning:
1 2 | so.addVariable("tspeed", "100"); so.addVariable("distr", "true"); |
The first controls the speed of rotation. Increase it for faster rotation, decrease it for slower. I use slower rotation for bigger clouds, and faster for smaller to be best.
The second tells the cloud whether to attempt to spread the tags out evenly throughout the sphere. Change “true” to “false” to disable this (why would you want to disable it? I don’t know).
Thanks for reading – if you like this tag cloud, head over to Roy’s Site and let him know!
It has been brought to my attention that some hosts do not allow standard use of the “include(‘URL’)†function. If you get a message that looks similar to this:
Warning: include() [function.include]: URL file-access is disabled in the server configuration in /a/path/to/a/domain.com/index.php on line XX
In your “include” parts (there are two, one in the snippet, one that gets pasted in the header in step 11), instead of using this (with paths changed to suit your site):
1 | <?php include("http://pagesofinterest.net/cumulus_test/blog/cloud_creator.php"); ?> |
Do this (changing the paths to suit your site):
1 | <?php include($_SERVER['DOCUMENT_ROOT']."/files/cloud_creator.php"); ?> |
The $_SERVER['DOCUMENT_ROOT'] asks the server for the path to the current file, .”/files/cloud_creator.php” appends the path to the file we want.
The snippet’s include should look something like:
1 | <?php include($_SERVER['DOCUMENT_ROOT']."/files/cloud_file.html"); ?> |
When you get it working, or get stuck – I want to know! Leave a comment and I’ll respond as soon as I am able.
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title

























Recent Comments
Great Wall
LinkedIn
Thu, 14 Jan 2010 12:54:50 +0000
Tag Cloud
LinkedIn
Thu, 14 Jan 2010 12:54:50 +0000
The Best Photographer In Shanghai
When we pick them up :( Don't know when that will be yet!
Chose another 49 today
Wed, 13 Jan 2010 14:13:21 +0000
The Best Photographer In Shanghai
When do we get to see them!!!!!
Tue, 12 Jan 2010 19:08:51 +0000
Installing Jdownloader In Ubuntu
Thank You!!!!
It works like a charm!!!!!!!!!!!!
Tue, 05 Jan 2010 13:02:35 +0000
Arrived In Shanghai
Done, look left!
Sun, 03 Jan 2010 15:37:03 +0000