Jump to content

1 unique site per user


brentmoeller

Recommended Posts

the code im running is

$result = mysql_query("SELECT count(*) FROM slinks where approval='1'");  
$do = mysql_fetch_row($result);  
$random = mt_rand(0,$do[0] - 1);  
$result = mysql_query("SELECT * FROM slinks LIMIT $random, 1");  

The above is finished off into a iframe

<iframe src="<?php while ($row = mysql_fetch_array($result)){ print $row["url"];}?> "frameborder="0" width="100%" height="100%" name="surfing"id="dframe"></iframe>

resulting in a random site loaded ever time the php file is ran

now all i need to figure out with a little help from the great users at phpfreaks is how i can get the random site to only be ran one time per user.

 

example

click = randomsite1.com

click = randomsite2.com

click = randomsite3.com

click = randomsite4.com

click = randomsite5.com

click = randomsite5.com = <--SKIP done been called so lets move along

click = randomsite6.com

 

 

I guess somehow im going to have to store the urls that are loaded into a variable and compare the variable to the the random site to make sure we dont get a match.

then again i guess i would have to some how figure out how to store the data per unique user as well .

 

Any suggestions would be greatly appreciated

Link to comment
Share on other sites

i dont want the user to randomly get the same website over and over.

Lets say you got the below sites stored in the database slinks the script above is going to randomly select one of those sites and its going to run inside a iframe everytime its ran. the user is going to be running this script over and over getting a random site evertime like how they do it @ stumbleupon.com . everytime you stumble you get a new site to look at. You dont want to stumble the same sites over and over.

 

phpfreaks.com

php.com

yahoo.com

google.com

msn.com

 

So i need to figure out how to keep the user from getting the same site more than one time. sorry the threads title isn't the best description on what i need done:)

Link to comment
Share on other sites

Well, to do that would necessitate some way of keeping track of what sites the each user has 'seen' per visit (session). I suppose you could have a session variable to which you sequentially add 'visited site', then check to see if the random selection is already in the session variable, if so - chose another - if not add it and display it. (A very quick rough idea)

Link to comment
Share on other sites

VERY rough , untested, un-proof-read, psuedo code...

 

<?PHP
session_start();
$visited = array();
if(isset($_SESSIONS['visited'])) {
$visited = $_SESSIONS['visited'];
}
$good = FALSE;
while(!$good) {
/* code for getting random site here */
	$site = some_value;

/* check to see if the site is already in the array */
	if(!in_array($site,$visited)) {

		/* add the site to the end of the array */
			array_push($visited, $site);

		/* update the session variable */
			$_SESSION['visited'] = $visited;

		/* let the while loop know we are done */
			$good = TRUE;
	}
}
/* display the site */
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.