473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Execute PHP script automatically

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
4 9873
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: wj | last post by:
Hi all, I wonder if it is possible to execute PHP-code automatically. Is it for example possible to sent an e-mail every day at lets say 9.00 pm automatically to adresses from a database? ...
2
by: Brian Quigley | last post by:
Hi, is there some code i can use to automatically execute some HTML form code when a page is loaded ? Thanks, Brian
3
by: Tomasz Ludwiniak | last post by:
Hi, I've little problem... I try to execute asp file ( which return XML file ) and use the result it in my asp script : set xml = Server.CreateObject("MSXML2.DOMDocument") xml.async=false...
3
by: Lyle Fairfield | last post by:
MS-SQL Server utilities Enterprise Manager and Query Analyzer will model almost any MS-SQL object as a simple script file with a default ".sql" extension. But how to "run these files? They are...
1
by: Allen | last post by:
I have installed the Updater Application Block, and then I should Deploy the QuickStarts. " Install the QuickStarts After you install the Updater Application Block, you should install the...
4
by: Alex D. | last post by:
Hi guys. this post is related to one from last week but now I have some more info. I am using a treeview in my app, for some reason the treeview is not working ok in firefox-mozilla, but is working...
1
by: Alfred | last post by:
Hi Guys, anyone out there who could help me with my problem? I have created a .bat file that would execute the mssql script and give an .txt file as an output. The script run successfully except...
7
by: tanyali | last post by:
Hi guys, I wanna to execute a php page automatically in the background, or execute it in shell script, and set this script to execute as a cron job. so who knows either of the two questions...
0
by: David | last post by:
- Are there any peculiarities with using curs.executemany(...) vs. multiple How many times are you calling execute vs a single executemany? The python call overhead will add up for thousands of...
1
by: samvb | last post by:
Hello Guys, I have a code that is workin fine from a click of a button. Is it possible to make that script execute automatically on 1st day of each month? Any suggestion wld b great. Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.