juust ~ php oddities

Unordered list of one element
  • rss
  • begin
  • about
    • vcard
    • WTF is BroJesus
  • php scripts
    • flickr wp widget
    • google multi key serp tool, php script
    • gwt plugin
  • php classes
    • php pagerank class
    • fibonacci class
    • robots.txt parser php class
  • serp
    • serp dashboard wordpress plugin
  • services

google trends II

juust | 22/12/2008

I wanted to reply to a question elsewhere on the site, but a ‘comment’ box isn’t fit for it so I’ll put the reply here. The question was about creating ’search engine friendly’ descriptive URL’s based on keywords from the Google Trends atom feed, listing pages a graph of the trend.

I hacked a quick example together on a subdomain over at trends.trismegistos.net, just to be sure it works.

You can get a site to list http://domain.com/trend_title.html type url’s by using mod_rewrite, an apache module.

In the server directory of the application you can use an .htaccess file to set rules for file access in these folders. When the server gets request from browsers or servers it applies any rewriting rules you define in .htaccess to these requests.

I tried this one :

  1. <ifmodule mod_rewrite.c>
  2.  RewriteEngine On
  3.  RewriteCond %{REQUEST_FILENAME} !-f
  4.  RewriteCond %{REQUEST_FILENAME} !-d
  5.         RewriteRule ^(.*).html /trendinfo.php?title=$1
  6. </ifmodule>

RewriteEngine On
sets the rewrite mechanism on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

tell the apache server that rewriteconditions apply to file-requests that are not an existing file (F) or directory (D). If the requested filename is anywhere in the servers file table, the server dishes out that file, otherwise it will try to apply a RewriteRule. Applying the rule generates a new request, if that returns anything, the server dishes that out, otherwise it returns an htpp-404 ‘file not found’.

The actual url rewrite rule is :
RewriteRule ^(.*).html /trendinfo.php?title=$1
which means :

  • if any filename is requested that satisfies the mask ^(.*).html then
  • take everything before .html
  • add that as variable $1 to trendinfo.php?title=$1
  • see if it sticks

If the browser requests http://domain.com/bob+bowersox.html, the server will assert it is not a file or directory on the server, and test the available rules. When it notices it the requested file ends with .html, it applies the rewrite rule and tries to access http://domain.com/trendinfo.php?title=bob+bowersox.

A browsing user does not notice a thing.

In trendinfo.php I wrote some code to handle the ‘new’ request :

  1. if(!isset($_REQUEST['title'])) {
  2. //if there is no $1, added as title, fake a 404 "file not found" message
  3.         echo 'the emptiness…';
  4. } else {
  5. //get the title from the request
  6.   $mytitle=htmlentities($_REQUEST['title'], ENT_QUOTES, "UTF-8");
  7. //put the google trends graph url together
  8.   $graphurl = 'http://www.google.com/trends/viz?hl=&q=';
  9.   $graphurl .= urlencode($mytitle);
  10.   $graphurl .= '&date=';                        //leave date blank to get the current graph
  11.   $graphurl .= '&graph=hot_img&sa=X';
  12.   echo "<img class=hotGraph width=280 height=190 src='$graphurl'/>";
  13. }

…that outputs the Google trend graph on the url http://domain.com/bob+bowersox.html

I zipped the trends.trismegistos.net program files, but that might be a bit over the top, the download file contains a class that relies on a mysql table being filled every hour with new trends (by cron.php on an apache cron-job), parsing and storing the atom feed of google trends, and listing it as a cross-table in index.php spanning the past 24 hours.

You can also put this in index.php :

  1.   $feed = simplexml_load_file('http://www.google.com/trends/hottrends/atom/hourly');
  2.   $children =  $feed->children('http://www.w3.org/2005/Atom');
  3.   $parts = $children->entry;
  4.   foreach ($parts as $entry) {
  5.      $details = $entry->children('http://www.w3.org/2005/Atom');
  6.       $dom = new domDocument();
  7.      $html=$details->content;
  8.      @$dom->loadHTML($html);
  9.       $anchors = $dom->getElementsByTagName('a');
  10.     foreach ($anchors as $anchor) {
  11.       $url = $anchor->getAttribute('href');
  12.       $urltext = $anchor->nodeValue;
  13.      echo '<a href="'.urlencode($urltext).'.html" target="_blank">'.$urltext.'</a> ';
  14.     }
  15.    }
  16.    unset($dom);
  17.    unset($anchors);
  18.    unset($parts);
  19.    unset($feed);

That lists the current 100 google trends with a link. If you use the .htaccess rewrite rules, the server reroutes all the links to trendinfo.php with descriptive urls.

I hope that helps.

Comments
4 Comments »
Categories
google, php, seo
Tags
google, php, seo, trends
Comments rss Comments rss
Trackback Trackback

seo tricks : the magpie incident

juust | 02/10/2008

Some universities like Southern California, Harvard and Michigan State have their web-guru’s explain to us how rss feeds work with the elegant Magpie parser demo :

Some example on how to use Magpie:

* magpie_simple.php *
Simple example of fetching and parsing an RSS file. Expects to be
called with a query param ‘rss_url=http://(some rss file)’
….

* magpie_debug.php *
Displays all the information available from a parsed feed.

Note : magpie_debug.php is the one to watch for, you can do a google search on :

site:.edu magpie_debug.php

and you get a number of educational facilities that kindly demonstrate the use of the magpie rss parser.

These demo pages have a textbox where you can enter an rss feed url, the magpie demo parses your feed and outputs it as an html-page.

You have to be careful with these programs, though : I actually found one domain (www.scripps.edu) with this remark under the ‘parse rss’ button :

Security Note:
This is a simple example script. If this was a real script we probably wouldn’t allow strangers to submit random URLs, and we certainly wouldn’t simply echo anything passed in the URL. Additionally its a bad idea to leave this example script lying around.

Thank you, you are surely wise like the buddha, I shall try to remember your insight !

….
note: after a while I decided I had had enough fun with magpies and took the blog off-line.

Comments
1 Comment »
Categories
links, seo, seo tips and tricks
Tags
links, seo, seo tips and tricks
Comments rss Comments rss
Trackback Trackback

seo tricks : old wine in new bags…

juust | 26/09/2008

Get some pagerank : this trick would require tedious boring link checking, but since SeoLinx (an extension of SeoQuake) that has become a lot easier. SeoLinx shows the stats of a links target url so you don’t have to go to every page to retrieve the stats. Cool plugin. Let’s put it to some practical use.

the trick : comment on old forum threads

Once you have SeoLinx installed find an ‘old’ forum, register if you haven’t already and make sure you get a signature link. Sometimes you first have to be a member for a week or write ten posts, but once you have a sig-link you get backlinks off the forum.

Then go comment on really old forum threads.

With SeoLinx you can easily spot the juicy old threads. Old threads on for instance DigitalPoint or Webmasterworld are sometimes pagerank 3. In case of the DP post, PR2 with 8 posts at the time of writing.

Pick a forum, and browse to the last page of the threads. Hover over the thread anchor and SeoLinx shows you the pagerank of the thread page. As long as the number of posts is below (10, 16 depending on the forum settings) you can put your comments in and they will appear on the first page of that thread, that has that nice pagerank and juice.

Old wine in new bags can be a sweet thing.

the benefit

A pagerank 3 ‘targetted’ anchor is worth about $9,- a month, $100,- per year. It can take an hour to find a juicy one, but hey, $100,- value for an hours work is well worth the trouble.


I might make this a blog feature, seo tips and tricks of the month.

Comments
2 Comments »
Categories
links, pagerank, seo, seo tips and tricks
Tags
links, pagerank, seo, seo tips and tricks
Comments rss Comments rss
Trackback Trackback

« Previous Entries Next Entries »

Recent Posts

  • geert wilders
  • gone till september
  • socialize me
  • Pagerank sculpting session
  • wish you were here

click me!
rss
Comments rss
Blog Directory
Web Developement Blogs - BlogCatalog Blog Directory
Listed in LS Blogs the Blog Directory and Blog Search Engine
Blog Flux Directory
joopita.com free web directory and search engine
design by jide
sitemap
22260 confirmed spam kills