Jump to content

Update if unique user and unique id?


itrends

Recommended Posts

Hey all, hope you can help, I have some issues that I can't seem to work out now :(

 

I have a site which lists some links on a page.

Each link gets parsed to "/out.php?entryid=x"

When they do this, my out.php updates the number of times that has been viewed

It then pushes them on to the appropriate link.

 

To prevent "gaming" of the link count, I want to try and use the IP or a session or something that will mean users can not inflate the count of any one link by more than 1.

 

E.g.

I come to site

I click link one

The count for link 1 increases by 1

I visit the site.

 

I come back

I click link two

The count for link 2 increases by 1

I visit the site

 

I come back

I click link one again

The count for link 1 does NOT increase

I visit the site.

 

etc

 

Any help on how I can edit my out.php to at least have some basics of this would be fantastic!

 

Really looking forward to your replies.

 

Regards,

David

 

Here is my current out.php code:

 

 

//Adds to the click count for a particular link
mysql_query("UPDATE listings SET views = views + 1 WHERE entryid = '{$_GET['entryid']}'");

//Retrieves information
$data = mysql_query("SELECT * FROM listings WHERE entryid = '{$_GET['entryid']}'") or die(mysql_error());
$info = mysql_fetch_array( $data );

//redirects them to the link they clicked
header( "Location:" .$info['url'] );

 

 

 

Link to comment
Share on other sites

Obviously you will have to set up a log table to do the counting. With each count you can store the IP address and SessionID values, and discard duplicates or just have your query which eventually analyses the results ignore them. (If you keep them you can still check to see who tried to cheat.)

 

If you use the SessionID though, it is too easy to get around, as closing the browser window will allow people to get a new value. So that does not help a lot.

 

If you don't though, then you might get different people using the same server, or some other method which means they have the same IP address, who are only counted once, which is also no good.

 

Which I think brings you to cookies as the next best idea, but these can be deleted as well.

 

I don't think there is an absolute way of resolving this. Depends on how prudent you want to be.

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Don't need to be too prudent, just enough to stop basic refreshing / multiple click counting.

 

I have no count table. It just increments the count by +1 when clicked.

 

Problem I have is that I am not a great programmer, so i have no clue how to even start putting this together in code, I had a hard enough time putting the tracking code and other bits together.

 

If someone can help me come up with the code solution I would be eternally greatful :) Using cookies, sessions or whatever, just something that works :)

 

I don't ask much ;) lol

Link to comment
Share on other sites

OK then, you are almost where you want to be, but you will need a table to contain the SessionIDs. I can see no way around that. Oddly I am working on this part of my site today as well.

 

Here is some code I use.

 

$sql = "INSERT INTO log (page, params, userkey, session, ip, date)

VALUES('$_SERVER[sCRIPT_NAME]', '$pageparams', ".nz($_SESSION['userkey'], 0).", '".session_id()."',

'$_SERVER[REMOTE_ADDR]', CURRENT_TIMESTAMP())";

mysql_query($sql);

 

This simply adds a row every time a user comes to a page. You would modify this just to hold x and the session_id() value I guess. Maybe the date too. And obviously create the log table.

 

I've just had another idea though... hang on...

 

 

Link to comment
Share on other sites

At the moment, I don't mind if the user can close their browser, open it, come back, and incease the count, I just don't want multiple clicks in the same session.

 

As such, can we just set a cookie first time they click something

If that "session" or "random user id" or "ip" or whatever, clicks again and there is already a session / cookie present, it will not record the click?

 

Who knows, lol.

 

I will await your second thing that you said to wait for :)

Link to comment
Share on other sites

Seeing as we are going to be relying on the session_id, we can approach this from the other way. We can have the Session remember which pages it has been to.

 

In your referral code you would do this:

 

Start the session, which I assume you do already.

 

Check to see if a variable $_SESSION['pages_visited'] is set, otherwise create it: $_SESSION['pages_visited'] = Array();

 

Check to see if x is in the array.

If ($_SESSION['pages_visited'][x]) 

If it is, then do not run the query which increments viewings. If not, then run the query, and add x to the array:

$_SESSION['pages_visited'][x] = True;

I think this should work.

 

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.