Jump to content

HTTP Refer


conker87

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.