Jump to content


Photo

Help


  • Please log in to reply
13 replies to this topic

#1 unknownproto

unknownproto
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 March 2006 - 12:34 AM

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

#2 Steveo31

Steveo31
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSan Jose, CA

Posted 14 March 2006 - 01:30 AM

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?

#3 unknownproto

unknownproto
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 March 2006 - 01:41 AM

Yes I do. But I would like to do it in a text as it is easier to use.

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 14 March 2006 - 02:02 AM

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.

/*
    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);
    
}

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.



#5 unknownproto

unknownproto
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 March 2006 - 03:08 AM

It does not work!

This is what I tried... besides the f function, I removed the spaces

<?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);
}
?>


#6 unknownproto

unknownproto
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 March 2006 - 03:20 AM

Atchully I got a script that does exactly the same thing... Records the ip, and does not move the counter up again

But now I need it to be personilzed for the account that the user makes in the registration...

<?
$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);
}
?>


#7 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 14 March 2006 - 04:30 AM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#8 unknownproto

unknownproto
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 March 2006 - 04:31 AM

Really? Well I need some help when coding sql with php.... like alot lol

#9 unknownproto

unknownproto
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 March 2006 - 10:29 PM

Could anyone give me some more help?

#10 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 14 March 2006 - 11:12 PM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#11 Steveo31

Steveo31
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSan Jose, CA

Posted 15 March 2006 - 12:26 AM

$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.

#12 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 15 March 2006 - 01:02 AM

[!--quoteo(post=355154:date=Mar 14 2006, 07:26 PM:name=Steveo31)--][div class=\'quotetop\']QUOTE(Steveo31 @ Mar 14 2006, 07:26 PM) View Post[/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.

#13 unknownproto

unknownproto
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 15 March 2006 - 03:37 AM

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

#14 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 15 March 2006 - 05:32 AM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users