Jump to content

Recommended Posts

advance thank you.


high there i am trying to get the $hits to increment by one,

when the page loads the first 1 goes in but then onwards nothink please help cheers.

my code example cheers.

[code]
<?

if($_GET['cmd']=="update"){

$query_update="update member_topics set hits=$hits+1 where date_added='".$_GET['date_added']."' and

time_added='".$_GET['time_added']."' and user_id='".$_GET['user_id']."'";
$result_query=mysql_query($query_update);

echo $query_update;
}
?>

[/code]

database query result please help
[code]
update member_topics set hits=+1 where date_added='23-07-06' and time_added='10:06:14' and user_id='00002'
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/
Share on other sites

Bit of clarification, please.

If I 'refresh' page X, you don't want the hits to increase. 

If I visit another page on the site and then navigate back to page X, should hits increment?

If I leave your site and come back later to page X, should hits increment? 

If I was away for an hour, or away for a week, would it matter in your answer to my last question.
[quote author=redarrow link=topic=101591.msg402187#msg402187 date=1153690860]
ok hits=hits+1 worked cheers but as always lol...........

if the user resfresh the page that hit will keep going up any idears cheers php only theo.
[/quote]

Duh...  ??? Ofcourse it does. To avoid that you'll have to link the view of a page to the client.

Possible solutions:
1) link the hit to the sessionid or even stored username/id
2) link the hit to a client with a cookie
3) link the hit to a client by ip

Take your pick.
andy was going to use sleep() or set_time_limit()

but the problam is that i wanted to add a function that a user can not refresh the same page.

so that the hits dont increment on a page that there viewing but the page is also the page that they will view other topics.

example a user goto a topic they like the user press the refresh button the user gets a echoed message from that viwing page and database entry.

i thort that i get the users ip while on the page of viewing then let them sleep or echo a message what do youthink works better.

i want to get the user ip

user=$_SERVER['REMOTE_ADDR'];

if the user refresh

send them to the home page.

header("location: index.php");


what i need to know how wili now the user has press refresh.


example only


<?

$user_ip=$_SERVER['REMOTE_ADDR'];

$kept_session=$_SESSION['kept']=$user_ip

if($user_ip == $kept_session ) {

header("location: index.php")

}

?>






I, like Andy, am still a bit confused at what exactly your goal is. But I'm assuming you want to link the page view to the clients' ip...
There's a reason it's the third option and not the first or second, but nevermind.

Let's focus on what YOU want to do (if I understand correctly):

Store the pages a specific ip has already visited, so count won't increase on second visit.

How? Store the data linking an url to several ip's.

Example:
INSERT INTO hits (url,ip) VALUES (**,**)

Include an UNIQUE index on the ip column. Inserting the same ip twice will fail. Add a TIMESTAMP column for garbage collection purposes.

To get the full hit count:
SELECT count(ip) FROM hits WHERE url = *

EDIT:
Pfff... This is getting obnoxious.
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.