Hello, my site sees a lot of visits to the first page after the "cover", but very few beyond that page. I want to randomize the first inward link, and keep track, so if the reader decides to click "next", it won't load the same page. How do I do this, an external php script? (I've not done one of those yet.)

Thanks, and Season's Greetings

Jess

Put all the links in an array, use rand function to get a random link!

I get that, but I don't want any redundancy in the links. Your suggestion might offer the same page twice or more times in a row.

I get that, but I don't want any redundancy in the links. Your suggestion might offer the same page twice or more times in a row.

You'll need to keep track of the visited links via the client session. You can add it directly to PHP's built in session, or save visited links in a db.

eg:

// links array
$links = array(...);

// get users visited links to an array
$visited_links = explode('|', $_SESSION['visited_links']);

// remove visited links from links array
foreach($visited_links as $visited_link) {
unset($links[array_search($visited_link, $links)]);
}

// get a random link from unvisited links
$link = $links[rand(0, count($links)-1)];

// add the selected link to visited array
$visited_links[] = $link;

// save visited links to user session as | separated string
$_SESSION['visited_links'] = implode('|', $visited_links);

:) Exactly !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.