Jump to content

Archived

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

unknownproto

Help

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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...

[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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
$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.

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.