I have a feedback form to collect my visitor's comments on the site. How do I also get information about the IP address. This is my php code

$msg = "E-MAIL SENT FROM $email\n";
$msg .= "Sender's Name: $name\n";
$msg .= "Sender's E-Mail: $email\n";
$msg .= "Sender's Address: $place\n";
$msg .= "Message: $comments\n\n";
$date = date("m/d/Y H:i:s");
$visitor_IP = $GLOBALS['REMOTE_ADDR'];
$_SERVER['REMOTE_ADDR']
if ($REMOTE_ADDR == "") $ip = "no ip";
else $ip = getHostByAddr($REMOTE_ADDR);

I get the first four information but not the date and Ip address. What is wrong with my code. Can anybody help.

Thanks

    You don't mean to tell us that the code you posted actually runs, do you? Because the line:

    $_SERVER['REMOTE_ADDR']

    will generate a parse error.

    The $date assignment should work fine. Echo out $date and see what you get.

    For your remote IP statements use the "$_SERVER['REMOTE_ADDR']" variable. But keep in mind that for any of several reasons it may not be available.

    When developing code use "echo" statements liberally for testing.

    $date = date("m/d/Y H:i:s");
    echo $date . '<br />'; 
    $visitor_IP = $_SERVER['REMOTE_ADDR'];
    echo $visitor_IP . '<br />';

    Then remove them after they've served their purpose.

      As for getting their country, there are several threads on the subject you can find by searching these forums.

        Originally posted by Installer
        You don't mean to tell us that the code you posted actually runs, do you? Because the line:

        $_SERVER['REMOTE_ADDR']

        will generate a parse error.

        Thanks Installer for the code. But your code does not work.

        What i want to know is How Do I get the IP address and country of the visitor e-mailed to me alongwith the other details of the Form.

        I have the following four fields in my Form
        Name:
        E Mail:
        Where are you from :
        Your Comments :

        What I find is that many people do not give their correct E mail address and where they are from. Just to know where my visitor is from, I would like these details also e-mailed to me, without the visitor knowing it. Is this possible and what is the code for that?

        You suggested to echo out the date. When I do that, it does show the date and IP address to the visitor ONLY, but nothing sent to me. This is not how I wanted it.

        I am not sure whether what I am saying makes sense or not. If this is one of those stupid questions, please do not bother to reply. Thanks for all your help.

          Originally posted by bengaluru
          Thanks Installer for the code. But your code does not work.

          What i want to know is How Do I get the IP address and country of the visitor e-mailed to me alongwith the other details of the Form.

          I don't think Installer meant you to just copy and paste that code without thinking about what it does, it just echoes the stuff out so that you could look at it and decide if that's what you're after. I think the idea was for you to do that and then use $_SERVER['REMOTE_ADDR'] when making your email message. Actually, I think something to that effect is in there...

          When developing code use "echo" statements liberally for testing.....Then remove them after they've served their purpose.

            Thanks, Weedpacket.

            bengaluru:
            Yeah, I was giving some programming advice there. Make of it what you will. In your original post you merely asked "What is wrong with my code", which is what I so clumsily responded to.

            In your second post you pose a different problem: how to implement the actual mailing. If you haven't yet, read the manual entries having to do with mail. Then if you still need help, come back here and post again, and I'm sure someone will be able to help you get your code written. Good luck.

            P.S. As for matching the IP to a country, there are a lot of sites on the web with the data you need for that. A Google search ("IP country", for example) will turn up most of them.

              Thanks a lot Guys. In fact I have no problem with the actual mailing. I have got that right and I am receiving the email with all the details that my visitor enters. What I was asking is what additional code I should be using to get the IP address.

              Anyway, thanks for all your help. Take care

                Write a Reply...