Execute PHP script automatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TJ

    Execute PHP script automatically

    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_AD DR|" . date("j M Y g:i a");
    $file = fopen("userIP.l og", "a");
    fputs($file, $logged_string, strlen($logged_ string));
    fputs($file, "\r\n");
    print("\n");
    fclose($file);
    ?>

    </form>


  • Henk Verhoeven

    #2
    Re: Execute PHP script automatically

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

    Henk Verhoeven,


    "TJ" <tgillette1@cox .net> wrote in message
    news:gGSCb.4039 $JD6.2573@laker ead04...[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_AD DR|" . date("j M Y g:i a");
    > $file = fopen("userIP.l og", "a");
    > fputs($file, $logged_string, strlen($logged_ string));
    > fputs($file, "\r\n");
    > print("\n");
    > fclose($file);
    > ?>
    >
    > </form>
    >
    >[/color]



    Comment

    • Richard T. Cunningham

      #3
      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
      >automaticall y 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_AD DR|" . date("j M Y g:i a");
      > $file = fopen("userIP.l og", "a");
      > fputs($file, $logged_string, strlen($logged_ string));
      > fputs($file, "\r\n");
      > print("\n");
      > fclose($file);
      > ?>
      >
      ></form>
      >[/color]

      Comment

      • Richard T. Cunningham

        #4
        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@metaclass REMOVE-THIS.nl> wrote:
        [color=blue]
        >why don't you write an index.php instead of an index.html and put your
        >"$logged_strin g = "$REMOTE_ADDR.. ." in there?
        >
        >Henk Verhoeven,
        >www.metaclass.nl
        >
        >"TJ" <tgillette1@cox .net> wrote in message
        >news:gGSCb.403 9$JD6.2573@lake read04...[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_AD DR|" . date("j M Y g:i a");
        >> $file = fopen("userIP.l og", "a");
        >> fputs($file, $logged_string, strlen($logged_ string));
        >> fputs($file, "\r\n");
        >> print("\n");
        >> fclose($file);
        >> ?>
        >>
        >> </form>
        >>
        >>[/color]
        >
        >[/color]

        Comment

        • Styx

          #5
          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.

          Comment

          Working...