Jump to content

Recommended Posts

I have a little count script that increases every time a user clicks ("reads") an article on my site. Though the counter also increases when there is a refresh and they comment (as the comment form pints to the same page).

 

I've been playing about with referrers, this is what I have at the point of where the increase code is:

 

if (!($_SERVER['HTTP_REFERER'] == "http://www.leagueofvillains.co.uk/?area=$area&id=$id") || !($_SERVER['HTTP_REFERER'] == NULL))
                {
                 $count++;
                }

 

I think that should only increase by one if the Referrer of the page is not itself (a form processed) and if it is not NULL (a refresh) however it doesn't work and continues to increase even during these actions.

 

Anyone see what I'm doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/53489-http-refer/
Share on other sites

I think you want && (and) instead of || (or)

 

"If referer is not myself and referer is not null, then increase count"

 

instead of

 

"If referer is not myself OR referer is not null, the increase count"

 

The second one is always true..

 

I would write it like this:

 

if ($_SERVER['HTTP_REFERER'] !== "http://www.leagueofvillains.co.uk/?area=$area&id=$id" && !empty($_SERVER['HTTP_REFERER']))

Link to comment
https://forums.phpfreaks.com/topic/53489-http-refer/#findComment-264482
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.