Connecting Tech Pros Worldwide Forums | Help | Site Map

Execute PHP script automatically

TJ
Guest
 
Posts: n/a
#1: Jul 17 '05
PHP Gurus,

I'd like to be able to capture the IP address of a visitor to my webpage.
I'm using the following code snippet within my HTML. I do not want the user
to have to push a button or click on something to call the post or get
command to do this. What must I put in the file for this to happen
automatically when someone opens my index.html page? Obviously something
other than form method="post" or get that I have in the file now. How can I
do this?

Thanks in advance!

<form method="post" action="<?php echo $PHP_SELF?>">

<?php
$logged_string = "$REMOTE_ADDR|" . date("j M Y g:i a");
$file = fopen("userIP.log", "a");
fputs($file, $logged_string, strlen($logged_string));
fputs($file, "\r\n");
print("\n");
fclose($file);
?>

</form>


Henk Verhoeven
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Execute PHP script automatically


why don't you write an index.php instead of an index.html and put your
"$logged_string = "$REMOTE_ADDR..." in there?

Henk Verhoeven,
www.metaclass.nl

"TJ" <tgillette1@cox.net> wrote in message
news:gGSCb.4039$JD6.2573@lakeread04...[color=blue]
> PHP Gurus,
>
> I'd like to be able to capture the IP address of a visitor to my webpage.
> I'm using the following code snippet within my HTML. I do not want the[/color]
user[color=blue]
> to have to push a button or click on something to call the post or get
> command to do this. What must I put in the file for this to happen
> automatically when someone opens my index.html page? Obviously something
> other than form method="post" or get that I have in the file now. How can[/color]
I[color=blue]
> do this?
>
> Thanks in advance!
>
> <form method="post" action="<?php echo $PHP_SELF?>">
>
> <?php
> $logged_string = "$REMOTE_ADDR|" . date("j M Y g:i a");
> $file = fopen("userIP.log", "a");
> fputs($file, $logged_string, strlen($logged_string));
> fputs($file, "\r\n");
> print("\n");
> fclose($file);
> ?>
>
> </form>
>
>[/color]



Richard T. Cunningham
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Execute PHP script automatically


You have the code that you need already there, just remove the lines
with the form tags. You might want to put the code at the top of the
page prior to the HTML in case the visitor aborts before the full page
loads...

Richard


On Sat, 13 Dec 2003 23:42:08 -0800, "TJ" <tgillette1@cox.net> wrote:
[color=blue]
>PHP Gurus,
>
>I'd like to be able to capture the IP address of a visitor to my webpage.
>I'm using the following code snippet within my HTML. I do not want the user
>to have to push a button or click on something to call the post or get
>command to do this. What must I put in the file for this to happen
>automatically when someone opens my index.html page? Obviously something
>other than form method="post" or get that I have in the file now. How can I
>do this?
>
>Thanks in advance!
>
><form method="post" action="<?php echo $PHP_SELF?>">
>
> <?php
> $logged_string = "$REMOTE_ADDR|" . date("j M Y g:i a");
> $file = fopen("userIP.log", "a");
> fputs($file, $logged_string, strlen($logged_string));
> fputs($file, "\r\n");
> print("\n");
> fclose($file);
> ?>
>
></form>
>[/color]

Richard T. Cunningham
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Execute PHP script automatically


Oops, I didn't see that it ended with .html ... I have .html parsed on
my system as PHP.

On Sun, 14 Dec 2003 11:44:35 +0100, "Henk Verhoeven"
<news@metaclassREMOVE-THIS.nl> wrote:
[color=blue]
>why don't you write an index.php instead of an index.html and put your
>"$logged_string = "$REMOTE_ADDR..." in there?
>
>Henk Verhoeven,
>www.metaclass.nl
>
>"TJ" <tgillette1@cox.net> wrote in message
>news:gGSCb.4039$JD6.2573@lakeread04...[color=green]
>> PHP Gurus,
>>
>> I'd like to be able to capture the IP address of a visitor to my webpage.
>> I'm using the following code snippet within my HTML. I do not want the[/color]
>user[color=green]
>> to have to push a button or click on something to call the post or get
>> command to do this. What must I put in the file for this to happen
>> automatically when someone opens my index.html page? Obviously something
>> other than form method="post" or get that I have in the file now. How can[/color]
>I[color=green]
>> do this?
>>
>> Thanks in advance!
>>
>> <form method="post" action="<?php echo $PHP_SELF?>">
>>
>> <?php
>> $logged_string = "$REMOTE_ADDR|" . date("j M Y g:i a");
>> $file = fopen("userIP.log", "a");
>> fputs($file, $logged_string, strlen($logged_string));
>> fputs($file, "\r\n");
>> print("\n");
>> fclose($file);
>> ?>
>>
>> </form>
>>
>>[/color]
>
>[/color]

Styx
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Execute PHP script automatically


You dont need to do anything, just add your code to your index file
and it will be executed. Maybe you'll need to rename the file - maybe
to index.php or something else depending on your server configuration.
But what for do you need to capture client's IP by PHP? If that's the
only purpose of your script it would be much efficient solution to use
internal logging of webserver.
Closed Thread