Computing.Net > Forums > Programming > Need help using PHP? PLEASE

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need help using PHP? PLEASE

Reply to Message Icon

Name: suspect52732
Date: January 27, 2004 at 09:55:28 Pacific
OS: XP
CPU/Ram: 2.4/512
Comment:

I know html, I dont know PHP. I needed a script to log IP's to a text file, I found a php script that does it. I don't understand HOW to use it. I put this in a text file, it is SUPPOSED to put the logged IP in the IPS.txt file, but it doesn't. This is the exact code of my html file with the PHP embedded. What do I need to do?

<HTML>
<head>


<%


<?
################################################################################
#Antares Fleet Yards Counter Author: M.Tunstall 2002
----------------------
#Features:
#---------
#Variable number of digits in count output
#E-mail update after desired number of hits
#Commented code for ease of modification
#
#SETUP
#-----
#Upload afy_counter.php to your webspace.
#Create logfiles in same directory ie. counter.txt and ips.txt.
#CHMOD both files to 666.
#include afy_counter.php into page you want to count
#
################################################################################
#Version:1.5 - 02/01/2002
#------------------------
#Modified ip fetch code to eliminate server cache ip being recorded instead of user ip.
#
#Version:1.4 - 01/01/2002
#------------------------
#Corrected code error and altered a piece of checking code.
#Added setup instructions.
#
#Version:1.3 - 14/12/2001
#------------------------
#Added IP checking function to allow the option of only recording one hit per user.
#
#Version:1.2 - 13/12/2001
#------------------------
#Added e-mail update after a user defined number of hits.
#
#Version:1.1 - 12/12/2001
#------------------------
#Modified to add leading zeros to make output correct length.
#
#Version:1.0 - 12/12/2001
#------------------------
#Simple counter which only displayed the required number of digits in the output.
#
################################################################################
#This script is free of charge.
#Do not hesitate to suggest this script to your friends.
#If you modify this script and add extra features please send me a copy.
#
# quantum@antaresfleetyards.co.uk
#
#Thanks for using this script.
# www.antaresfleetyards.co.uk
################################################################################
$log="counter.txt"; // counter log file
$ipFile="ips.txt"; // text file that stores IP addresses
// e-mail address to send count update to
$address = "dontmailme@all.com";
$name_website = "www.MYWEBSITE"; // name of the website the counter is counting for
$date_start = "1/12/2001"; // the date when the counter started
$hit_update = 10; // number of hits between e-mail counter updates
$minDigits = 5; // minimum # of digits to display. 0 outputs required #'s only
$countOnce = 0; // set to 1 to count unique IPs only
// set to 0 to count all hits

$mail_update = 0; // 1 enables, 0 disables e-mail update
################################################################################
//DO NOT ALTER ANYTHING BEYOND THIS POINT UNLESS YOU KNOW PHP!!!!!
################################################################################

if (getenv(HTTP_CLIENT_IP)) // obtain client ip if possible
{
$ipadd=getenv(HTTP_CLIENT_IP); // save client ip as $ipadd
}
else // if not able to obtain client ip
{
$ipadd=getenv(REMOTE_ADDR); // get remote address and save as $ipadd
}

if ($countOnce == 1) // if the "countOnce" feature is enabled
{
$fp_ips = fopen($ipFile, "r"); // open the IP address file
while (!feof($fp_ips)) // compare each entry with the user's IP address
{
$ip = fgets($fp_ips, 20); // get an entry from the IP file
if ($ip == $ipadd . "\r\n") // if the user's IP matches
{
$is_old = 1; // set user to old
break;
}
else // if the user's IP doesn't match
{
$is_old = 0; // set the user to new
}
}

fclose($fp_ips); // close the IP address file
if ($is_old == 0) // if the user is not old, add his IP to the IP file
{
$fp_ips = fopen($ipFile, "a"); // reopen the IP address file
fputs($fp_ips, $ipadd . "\r\n"); // add the user's IP address
fclose($fp_ips); // close the IP address file
}
}
else // if the "countOnce" feature is disabled
{
$is_old = 0; // set user to new
}


$open=@fopen($log,'r+'); // open log file in read mode
$counter=@fread($open,filesize($log)); // read count from open file and store in $counter
@fclose($open); // close open log file

if ($is_old == 0) // if the user is not old, increment the counter
{
$counter++; // increment $counter
}


$digits = strlen($counter); // get length of count value and store as digit
$write=fopen($log,'w'); // open log file in write mode
fputs($write,$counter); // write count to open log file
fclose($write); // close open log file


if($minDigits && $digits<$minDigits) // check to see if $digits and $minDigits are desired length
{
$diff = $minDigits - $digits; // check to see how many leading zeros are needed
for($i=0; $i<$diff; $i++) // loop to add required number of zeros
{
$counter = "0".$counter; // add leading zero to $counter
}
$digits = $minDigits; // store $minDigits in $digits
}

if ($counter % $hit_update ==0) // checks if $counter is a multiple of $hit_update
{
if ($mail_update ==1) // checks to see if $mail_update is enabled
{ // e-mails hit count
mail($address, "Log hits from $name_website", "Number of hits from $date_start: $counter");
echo "$counter"; // print count to screen
}
else
{
echo "$counter"; // print count to screen
}
}
else
{
echo "$counter"; // print count to screen
}

################################################################################
#References
#----------
#I didn't write all of this script myself so i feel I must credit those who did.
#If you copy/modify this program please credit those who contributed to this program as well as me.
#
#Based on:
#---------
#Counter.php - Text based counter
#www.dony.com.kg
#webmaster@dony.com.kg
#
#Counter.php - A Graphical Counter
#Jon Thomas
#www.spiderdepot.com
#jthomas@spiderdepot.com
#
#PHP simple text counter + mail notice
#rofus
#rofus@mindless.com
################################################################################
?>


%>
?>


</head>
<body>
</body>
</HTML>



Sponsored Link
Ads by Google

Response Number 1
Name: gpp
Date: January 27, 2004 at 10:00:47 Pacific
Reply:

What happens when you run the script.. are you getting any errors?


0

Response Number 2
Name: jb60606
Date: January 27, 2004 at 10:47:18 Pacific
Reply:

make sure the script has permissions to write to the file.


0

Response Number 3
Name: suspect52732
Date: January 27, 2004 at 11:17:41 Pacific
Reply:

Well, when I run the script. (When I open the webpage) There are no errors, the page loads and displays fine. When I open the IPS.txt which is SUPPOSED to contain the ip logs it displays this
<HTML>
<head>
</head>
<body>
</body>
</html>
I didnt put this in the file, I just created a blank file. However, it still doesn't place the ip's in the IPS.txt file. This is the only part of the program I am concerned with to. I only need to be able to log the IP's. Do you have any more ideas? I don't know anything about PHP, I just cut and pasted it into my html code.


0

Response Number 4
Name: anonproxy
Date: January 27, 2004 at 11:48:23 Pacific
Reply:

"
<%

<?

[entire script]

?>

%>
?>
"

I don't even know if that will parse. Try shortening it to just two tags:

<?php
[entire script]
?>

What does the file counter.txt read? Do you get any email from this script?


0

Response Number 5
Name: suspect52732
Date: January 27, 2004 at 12:00:01 Pacific
Reply:

Well, I tried what you said, and several hundred variants. I still didn't get it. The counter counts the number of visits and no I dont recieve an email. Any other ideas?


0

Related Posts

See More



Response Number 6
Name: SN
Date: January 27, 2004 at 12:06:40 Pacific
Reply:

Yeah forget that script...It's doing more than you need.

<?php
$file="myfile.txt";
$outfile=fopen($file,'w');
$line=$_SERVER['REMOTE_ADDR']."\n";
fputs($outfile,$line);
fclose($outfile);
?>

-SN


0

Response Number 7
Name: SN
Date: January 27, 2004 at 12:08:51 Pacific
Reply:

Whoops, my apologies. 'w' should be 'a', or each address will overwrite the previous one.

(w for write, a for append)

-SN


0

Response Number 8
Name: gpp
Date: January 27, 2004 at 12:57:22 Pacific
Reply:

Dont know if you've changed this or not, but towards the top, mail_update is still set to zero...

$mail_update = 0; // 1 enables, 0 disables e-mail update

it needs to be one in order to reach the mail command.



0

Response Number 9
Name: suspect52732
Date: January 27, 2004 at 13:17:00 Pacific
Reply:

Thank you guys so much for your help. This is the best and most help I have ever recieved from the programming forum. Well, if you are interested in what was wrong, for future reference. I use a free web host (www.angelfire.com) And in an effort to make a few $$$ they diable Perl and CGI, you have to pay for it extra. Thats why these scripts are working. You have helped a great deal though, as I do have another web host that I can use CGI and Perl on. So, thanks so much. You have helped ALOT!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Batch File command to shut down pc i...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Need help using PHP? PLEASE

Help with PHP mail html script www.computing.net/answers/programming/help-with-php-mail-html-script/17196.html

need help with PHP www.computing.net/answers/programming/need-help-with-php/12828.html

Need help using ADO www.computing.net/answers/programming/need-help-using-ado/6436.html