Forum Moderators: coopster

Message Too Old, No Replies

Scripting random meta tag keywords on pages from a list

Possible with out a database?

         

sauce

9:51 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



I'm trying to update all the meta tag keywords for a 3000 page site using a php script I wrote but I hit few bugs...

The script looks like this:

<?
$meta = array (
1=>"meta1",
2=>"meta2,
3=>"meta3",
4=>"meta4",
5=>"meta5",
6=>"meta6",
7=>"meta7",
8=>"meta8",
9=>"meta9",
10=>"meta10",etc They go up to 50

?>

Here is where it calls the tags:

<?php
$random_number=rand(1, count($meta));
$random_meta=$meta[$random_number];
echo("$random_meta, $random_meta, $random_meta, $random_meta, $random_meta, $random_meta, $random_meta, $random_meta");
?>

Here is what is currently displays : meta1, meta1, meta1, meta1, meta1, meta1, meta1, meta1,

then I refresh the page it displays: meta3, meta3, meta3, meta3, meta3, meta3, meta3, meta3,

My question is how can I make them random by page instead of everytime the page loads it pulls random results... I want it to pull random meta tage from this list but I want them to be the same everytime the page reloads... with each page having a adifferent set of 8 random meta keyowrd from this list.

Ex....

Page 1 everytime you refresh the page:

meta3, meta1, meta32, meta11, meta47, meta24, meta9, meta50

Page 2 everytime you refresh the page:

meta22, meta15, meta12, meta41, meta1, meta8, meta17, meta44

and so on...

Do i need a database to do this? Or can I just call them similar as above.

Thx.

sauce

sned

10:07 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



Is there a certain number of meta tag keywords per page? As you have the script now .. it will only return 1 keyword. You need to put that in a loop to get multiple keywords:

$random_meta_string = '';
for($x = 0; $x < 50; $x++){
$random_number=rand(1, count($meta));
$random_meta_string .= ' ' . $meta[$random_number];
}
echo $random_meta_string;

This will get you a string of 50 random meta keywords.

-sned

sauce

10:14 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



Cool! I added the loop and it works now...

Now is there anyway to have the random keywords not change when the page is refreshed or revisited?