unknownproto Posted March 14, 2006 Share Posted March 14, 2006 Hey I need help! See what I want to do is I want users to be able to register and they get a unique link and when people visit that link their counter goes up... when the counter reaches 100 I want it to email me that it has reached 100. The counter can be seen by the user, to see how many click they have got. The link cannot be clicked by the same IP twice and go up.Thanks,UnknownProto Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/ Share on other sites More sharing options...
Steveo31 Posted March 14, 2006 Share Posted March 14, 2006 The IP thing will have to come from either a mysql DB or a text doc. MySQL would be the better choice as making a counter is very simple. Do you have access to a mysql database? Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17212 Share on other sites More sharing options...
unknownproto Posted March 14, 2006 Author Share Posted March 14, 2006 Yes I do. But I would like to do it in a text as it is easier to use. Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17219 Share on other sites More sharing options...
hitman6003 Posted March 14, 2006 Share Posted March 14, 2006 This should get you most of the way...be sure to remove the space between f functions and the rest of their names in the script below...the forum code doesn't like it for some reason.[code]/* the person's url should be along the lines of: http://yourserver.com/counterpage.php?name=1.1.1.1 where 1.1.1.1 is the ip of the person that you are recording the count for conversely you could change that to be whatever you want.*///First, get the person's ip address...$ip = $_SERVER['REMOTE_ADDR'];//Then read your file into an array:$file = file($_GET['name'] . ".txt");//Then use in_array to see if it's in there:if (in_array($ip, $file)) { //if it's in the array, then that person has already been counted. echo "Your ip has already been counted. The current count is: " . count($file); } else { //otherwise, add them, and count them: array_push($file, $ip); echo "Your ip has been recorded. The current count is: " . count($file); //now write the file back to itself $open = f open("ipsforperson.txt", 'w'); f write($open, implode("\n",$file)); f close($open); }[/code]This will automatically create a new file for each new $_GET['name'] that is passed to it. You can add in additional code to check to make sure it already exists. There's lots of other things you can add to it as well. Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17223 Share on other sites More sharing options...
unknownproto Posted March 14, 2006 Author Share Posted March 14, 2006 It does not work! This is what I tried... besides the f function, I removed the spaces [code]<?php/* the person's url should be along the lines of: http://yourserver.com/counterpage.php?name=1.1.1.1 where 1.1.1.1 is the ip of the person that you are recording the count for conversely you could change that to be whatever you want.*///First, get the person's ip address...$ip = $_SERVER['REMOTE_ADDR'];//Then read your file into an array:$file = file($_GET['name'] . ".txt");//Then use in_array to see if it's in there:if (in_array($ip, $file)) { //if it's in the array, then that person has already been counted. echo "Your ip has already been counted. The current count is: " . count($file); } else { //otherwise, add them, and count them: array_push($file, $ip); echo "Your ip has been recorded. The current count is: " . count($file); //now write the file back to itself $open = f open("ipsforperson.txt", 'w'); f write($open, implode("\n",$file)); f close($open);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17238 Share on other sites More sharing options...
unknownproto Posted March 14, 2006 Author Share Posted March 14, 2006 Atchully I got a script that does exactly the same thing... Records the ip, and does not move the counter up againBut now I need it to be personilzed for the account that the user makes in the registration...[code]<?$hitcount= file('counter.txt');print $hitcount[0];if( $_SERVER['REMOTE_ADDR'] !=$hitcount[1] ){$stuff = $hitcount[0] + 1;$ip =$_SERVER['REMOTE_ADDR'];$fp= f open('counter.txt', w);f write($fp,$stuff. ''. $ip);f close($fp);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17240 Share on other sites More sharing options...
txmedic03 Posted March 14, 2006 Share Posted March 14, 2006 Actually, a MySQL database would not be any harder to work with and would carry with it a sleu of benefits. I dare say it would end up being easier to work with a MySQL database than an FFD in this case. Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17255 Share on other sites More sharing options...
unknownproto Posted March 14, 2006 Author Share Posted March 14, 2006 Really? Well I need some help when coding sql with php.... like alot lol Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17256 Share on other sites More sharing options...
unknownproto Posted March 14, 2006 Author Share Posted March 14, 2006 Could anyone give me some more help? Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17568 Share on other sites More sharing options...
txmedic03 Posted March 14, 2006 Share Posted March 14, 2006 Okay first you need to figure out what information needs to be stored for the links. Is it just going to be a user id, link address, link title, number of hits and password (so users can make changes to address title and destination address)? Once you decide this, we can move on to creating your database and tables. Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17588 Share on other sites More sharing options...
Steveo31 Posted March 15, 2006 Share Posted March 15, 2006 $open = f open("ipsforperson.txt", 'w'); f write($open, implode("\n",$file)); f close($open);Wouldn't work. The spaces between "f" and "write", etc are synatx errors. Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17624 Share on other sites More sharing options...
hitman6003 Posted March 15, 2006 Share Posted March 15, 2006 [!--quoteo(post=355154:date=Mar 14 2006, 07:26 PM:name=Steveo31)--][div class=\'quotetop\']QUOTE(Steveo31 @ Mar 14 2006, 07:26 PM) [snapback]355154[/snapback][/div][div class=\'quotemain\'][!--quotec--]The spaces between "f" and "write", etc are synatx errors.[/quote]Yeah, the forum is acting funny...it won't let you post without the spaces there...gives an error...at least for me. Hopefully, he knows to remove them. Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17635 Share on other sites More sharing options...
unknownproto Posted March 15, 2006 Author Share Posted March 15, 2006 Yeah I removed the spaces[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Okay first you need to figure out what information needs to be stored for the links. Is it just going to be a user id, link address, link title, number of hits and password (so users can make changes to address title and destination address)? Once you decide this, we can move on to creating your database and tables.[/quote]Its just going to be the user id Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17674 Share on other sites More sharing options...
txmedic03 Posted March 15, 2006 Share Posted March 15, 2006 Not if you plan on counting the number of clicks...You must at the very least have a user id of some kind and click counter. I would suggest using sessions to disallow multiple clicks. Quote Link to comment https://forums.phpfreaks.com/topic/4886-help/#findComment-17699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.