Forum Moderators: coopster

Message Too Old, No Replies

How to only send unique outgoing visitors

         

ashish2005

7:58 pm on May 11, 2009 (gmt 0)

10+ Year Member



Ok, I have just set up a traffic trade like thing with my website. There is a link say "A" which does not change and is something like mysite.com/goto.php?id=1

That id = 1 queries the mysql and gets a random url out of all the urls under the id 1 . Now I want that random url to be selected in such a way that it is not repeated again when the url is clicked again.

How do I do it? Is it with the help of cookies?

rocknbil

3:08 am on May 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either that, or sessionID, or set one cookie, and somewhere in a database add the entries that have been viewed by this user. Example one:

Check for a cookie with the name for this purpose first. if found, use this as the visitor's "id." If not, set a new one.

- Collect a "list" of URL id's to pull from.

select id from url_list . . .
array_push($url_list,$id)....

- Get any already-viewed id's from the database for this user . . .

select url_id from sessionviews where user='$sessionid"....
array_push($user_urls,$id)....

(Note: I use url_id because this should be numeric, it would be quite a bit slower matching on a full url - text - value.)

- Before doing anything, check if the length of $user_urls == the length of $url_list. If they are the same, you've completed the loop. Delete all entries from the database matching this user id, unset $user_urls, and pick a new random ID. Enter the new id in the database, display the url.

- If the two arrays are NOT the same length, remove all the "viewed" id's in $user_urls from the $url_list array, which makes only un-viewed ones available in $url_list. Randomly pick one, enter it's id into the database, display the url.

Example 2:

- Just like above, get your available URL ID's into an array.

- Check the cookie, except in this case your cookie value should be a delimited list, adding ID's as they are viewed:

URLVIEWS=325343344356456544645,2,4,7,8;

Explode the cookie on the commas;
$user_urls = explode(',',$cookie);

- Shift the first item off the array. This is your user id.
$uid = array_shift($user_urls);

- What's left in $user_urls is the url_id's already viewed. The same rules apply: if the length of $user_urls == $url_list, you're done with the loop, unset it and pic a new random.

- If the two arrays are NOT the same length, remove all the $user_urls from $url_list, and pick a random from what's left in $url_list.

- In either case, re-set the cookie that includes the same user ID and new URL ID, display the URL.

The advantage to this way is there's no need for a database, but there are limitations to cookie lengths so if you have thousands of URL's it may fail.

Probably better ways to do it, but these will work.

ashish2005

5:00 am on May 13, 2009 (gmt 0)

10+ Year Member



I am quite a newbie in this. I tried to put all the url ids in an array. And I get something like this in the array

Array ( [0] => 533 ) Array ( [0] => 534 ) Array ( [0] => 535 ) Array ( [0] => 536 ) Array ( [0] => 537 ) Array ( [0] => 606 ) Array ( [0] => 607 ) Array ( [0] => 768 )

ashish2005

12:13 pm on May 27, 2009 (gmt 0)

10+ Year Member



anyone? please help me out here.

eelixduppy

1:12 pm on May 27, 2009 (gmt 0)



How are you putting them in an array? Doesn't seem like you are doing it correctly as you are getting multiple arrays here. Please post the relevant code.

ashish2005

9:20 am on May 29, 2009 (gmt 0)

10+ Year Member



This is how I tried to put the urls in the arrays

while($row = mysql_fetch_array($sql)) {
$urls = $row['url'];
$id = $row['id'];
$url_list = array();
array_push($url_list,$id);
}

eelixduppy

2:16 pm on May 29, 2009 (gmt 0)



Try taking this line out of the loop and put it before...

$url_list = array();
while(...

You are resetting the value of the array with each iteration.