Random Elements
If you have a database of information that is larger than you want to display on your site at one time, you will probably want to show a random selection that changes periodically. This is often the case when you are using some part of a large database to provide extra content for one site, while on another site it might be the main content and used in full. At least some of the sites in your Web Empire should have dynamic content updated automatically. This can be very beneficial for your search engine ranking, if done properly.
The search engines love sites that are frequently updated. Blogs that get a new page every day are ranked higher than the same data would be on a static site — there is almost an implicit assumption that the site will continue to be updated and enlarged, and hence deserves higher ranking.
However, if a search engine spider comes to your site and records different information each time — even just minutes apart, it will recognize it as dynamic content, and much of the potential benefit is lost. Also, when a user happens to notice that they can see a different joke or some other content element on each visit, they will keep refreshing the page just to read that part of it — distorting your visitor statistics.
Likewise, if you have a part of a page with ‘today in history’ or similar content that updates daily, the search engines are presumably programmed to recognize that, and give it no extra rank (or very little) for freshness. The exception to this is when the URL to the content itself changes daily — so the search engine sees it as new content, and adds it to the index, giving you more apparent pages than a visitor actually sees.
An example of this technique might be drawn from a database of silent-movie screen stars biographical sketches. If you feature a link with just one on your site, but it changes daily, with an URL like:
www.mysite.com/bio=Charlie_Chaplin
one day and
www.mysite.com/bio=Buster_Keaton
the next, the search engine is more likely to visit frequently, and both those URLs will be in the search engine results.
Of course, you wouldn’t use a page like that on a site devoted to silent movie stars — but you could use it on a site about silent movies, or the roaring 20s, or other related subjects. On another site the biographical sketch may be part of the data for each star, which would also includes a filmography, quotes, photo and other content. You do not want to duplicate the pages on your other site and risk irrelevancy due to duplicate content screening.
When content is inserted into your page, instead of being accessed by its own URL, it is better to update that part of your content every week or two, preferably at irregular intervals. This looks much more like a site being manually updated, and earns the highest freshness rating you can get without actually needing to add new material.
To use this technique with PHP, you just need to generate a couple random numbers. Generally, the RAND() function in PHP uses the server’s time clock to seed a pseudo-random generator which returns a random number in the range you specify:
rand(5,10)
Would return any of the numbers 5, 6, 7, 8, 9, or 10 at apparent random. There is no need to seed the random number generator — but you can — and therin lies the secret of controlling the frequency with which your ‘random’ content is updated. The main use for the ’seed’ is to allow you to get the same random sequence over and over — something scientists often need when randomizing results with multiple trials. We can use this feature to ensure that content gets updated at whatever frequency we want. The trick is to seed the random generator with a number that will only change as often as we want the content to change. We do this by using the current time divided by the amount of time the content should remain unchanged. So, for example, you might use:
$seed = floor(time()/86400);
srand($seed);
$recordnum=rand(1,$maxrecords);
The srand() command seeds the random number generator — it takes an integer value, so we use floor() to round the results of our division down to the nearest integer. The time() function returns a ten digit integer representing the current UNIX time on the server, in seconds. The number 86400 is the number of seconds in one day. Our $seed value stays the same for one day, then changes, so this function would return a different $recordnum each day, between one and the maximum number of records available, which you have presumably already set in $maxrecords.
To have your update occur every seven to ten days, at random intervals, we just add another random number:
$num=rand(7,10) * 86400;
$seed=floor(time()/$num);
Now your Web Empire has frequently updated information, with no further effort on your part — you can go on to work on your next website to add to your Empire. Visitors and search engines will see the data changing fairly frequently, but not so often or so regularly as to appear like it is inserted dynamic content — though that is exactly what it is.
2 Comments
You must be logged in to post a comment.
[…] http://www.andrewjmorris.com/random-elements.htm Filed under: Functions | […]
Pingback :: December 10, 2007 @ 19:12 pm
[…] pages on your site, chosen at random but changing only every week or month. (See my earlier post on Random Elements on how to do that if you don’t already know). Now you have lots of different links, including […]
Pingback :: January 21, 2008 @ 23:43 pm