MereCatfish Posted April 18, 2006 Share Posted April 18, 2006 Hi,Just wondering if I could get some help with a problem.I run a webring, which counts the amount of times a link is clicked. The user clicks it, the db value has 1 added to it. Then the user is redirected to the URL they wanted. Obviously, this allows people to continually refresh to get to the top.So I decided to try to use cookies to see if a user has clicked the link today. If they have, the click will not be recorded. I cannot see why the clicks continue to be recorded. Here is my code:[code]<?php# Connect to MySQL server$conn = mysql_connect($host,$dbusername,$dbpassword) or die(mysql_error());# Select the databasemysql_select_db("$database", $conn) or die(mysql_error());$array = mysql_fetch_array(mysql_query("SELECT url, clicks FROM sites WHERE id='$id'")); if(isset($_COOKIE['$array[url]'])){ header("Location: $array[url]"); exit; } else { $clicks = $array[clicks] + 1; mysql_query("UPDATE sites SET clicks='$clicks' WHERE id='$id'"); setcookie("$array[url]", "halocewebring", time()+3600*24); header("Location: $array[url]"); }?>[/code]Thanks for your time. Link to comment https://forums.phpfreaks.com/topic/7692-cookies-detect-if-a-user-has-clicked-a-link-today/ Share on other sites More sharing options...
shocker-z Posted April 18, 2006 Share Posted April 18, 2006 if(isset($_COOKIE['$array[url]'])){needs to beif(isset($_COOKIE[$array['url']])){orif(isset($_COOKIE["$array[url]"])){using ' will print the variable how u wrote it so it is checking for a cookie called $array[url]RegardsLiam Link to comment https://forums.phpfreaks.com/topic/7692-cookies-detect-if-a-user-has-clicked-a-link-today/#findComment-28086 Share on other sites More sharing options...
MereCatfish Posted April 18, 2006 Author Share Posted April 18, 2006 [!--quoteo(post=365927:date=Apr 18 2006, 09:08 AM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Apr 18 2006, 09:08 AM) [snapback]365927[/snapback][/div][div class=\'quotemain\'][!--quotec--]if(isset($_COOKIE['$array[url]'])){needs to beif(isset($_COOKIE[$array['url']])){orif(isset($_COOKIE["$array[url]"])){using ' will print the variable how u wrote it so it is checking for a cookie called $array[url]RegardsLiam[/quote]Still didn't make a difference :(. Link to comment https://forums.phpfreaks.com/topic/7692-cookies-detect-if-a-user-has-clicked-a-link-today/#findComment-28152 Share on other sites More sharing options...
shocker-z Posted April 18, 2006 Share Posted April 18, 2006 $array = mysql_fetch_array(mysql_query("SELECT url, clicks FROM sites WHERE id='$id'"));try$query=mysql_query("SELECT url, clicks FROM sites WHERE id='$id'") or die(mysql_error());$array = mysql_fetch_array($query);just want to check the statement is runnign properly... Link to comment https://forums.phpfreaks.com/topic/7692-cookies-detect-if-a-user-has-clicked-a-link-today/#findComment-28175 Share on other sites More sharing options...
MereCatfish Posted April 18, 2006 Author Share Posted April 18, 2006 Yeah, that didn't make a difference either :|I am absolutely stumped, I can't see why it isn't working... Link to comment https://forums.phpfreaks.com/topic/7692-cookies-detect-if-a-user-has-clicked-a-link-today/#findComment-28222 Share on other sites More sharing options...
MereCatfish Posted April 19, 2006 Author Share Posted April 19, 2006 Alright, it is definitely having a problem finding the cookie. I can see the cookie set on my computer, but replacing the if code with...[code] if(isset($_COOKIE["$array[url]"])){ echo("you have da cookie lolz"); exit; } else {[/code]redirects to the site, which means header("Location: $array[url]"); would happen, which is in the else. Link to comment https://forums.phpfreaks.com/topic/7692-cookies-detect-if-a-user-has-clicked-a-link-today/#findComment-28478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.