By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,406 Members | 2,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,406 IT Pros & Developers. It's quick & easy.

Execute PHP script automatically

P: n/a
TJ
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>
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <tg********@cox.net> wrote in message
news:gGSCb.4039$JD6.2573@lakeread04...
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>


Jul 17 '05 #2

P: n/a
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" <tg********@cox.net> wrote:
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>


Jul 17 '05 #3

P: n/a
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"
<ne**@metaclassREMOVE-THIS.nl> wrote:
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" <tg********@cox.net> wrote in message
news:gGSCb.4039$JD6.2573@lakeread04...
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>



Jul 17 '05 #4

P: n/a
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.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.