Jump to content

Help


unknownproto

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
Link to comment
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.

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

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.