Use php to capture ip address


i have customer wants use standard php comment form capture user's ip address.

 

i've found code snippet - $ip = $_server['http_client_ip'];   can't work.

 

can see what's wrong code (i'm not experienced php)?  or point me in right direction?

 

here's code:

 

<?php

 

 

$mailto = 'info@empathydesign.co.uk' ;

 

$subject = "empathy design query form" ;

 

 

$formurl = "http://www.empathydesign.co.uk/contactus.shtml" ;

$errorurl = "http://www.empathydesign.co.uk/error.shtml" ;

$thankyouurl = "http://www.empathydesign.co.uk/thankyou.shtml" ;

 

$email_is_required = 1;

$name_is_required = 1;

$company_is_required = 0;

$comments_is_required = 1;

$uself = 0;

$use_envsender = 0;

$use_sendmailfrom = 0;

$use_webmaster_email_for_from = 0;

$use_utf8 = 1;

$my_recaptcha_private_key = '' ;   

 

// -------------------- end of configurable section ---------------

 

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;

$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'content-type: text/plain; charset="iso-8859-1"' : 'content-type: text/plain; charset="utf-8"' ;

 

if (!isset( $use_envsender )) { $use_envsender = 0 ; }

if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {

    ini_set( 'sendmail_from', $mailto );

}

$envsender = "-f$mailto" ;

$fullname = (isset($_post['fullname']))? $_post['fullname'] : $_post['name'] ;

$email = $_post['email'] ;

$company = $_post['company'] ;

$comments = $_post['comments'] ;

$http_referrer = getenv( "http_referer" );

$ip = $_server['http_client_ip'];

 

 

if (!isset($_post['email'])) {

    header( "location: $formurl" );

    exit ;

}

if (($email_is_required && (empty($email) || !preg_match('/@/', $email))) || ($name_is_required && empty($fullname)) || ($comments_is_required && empty($comments))) {

    header( "location: $errorurl" );

    exit ;

}

if ( preg_match( "/[\r\n]/", $fullname ) || preg_match( "/[\r\n]/", $email ) ) {

    header( "location: $errorurl" );

    exit ;

}

if (strlen( $my_recaptcha_private_key )) {

    require_once( 'recaptchalib.php' );

    $resp = recaptcha_check_answer ( $my_recaptcha_private_key, $_server['remote_addr'], $_post['recaptcha_challenge_field'], $_post['recaptcha_response_field'] );

    if (!$resp->is_valid) {

        header( "location: $errorurl" );

        exit ;

    }

}

if (empty($email)) {

    $email = $mailto ;

}

$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;

 

if (function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) {

    $comments = stripslashes( $comments );

}

 

$messageproper =

    "this message sent from:\n" .

    "$http_referrer\n" .

    "------------------------------------------------------------\n" .

    "name of sender: $fullname\n" .

    "sender's company: $company\n" .

    "email of sender: $email\n" .

    "ip of sender: $ip\n\n" .

    "------------------------- comments -------------------------\n\n" .

    $comments .

    "\n\n------------------------------------------------------------\n" ;

 

$headers =

    "from: \"$fullname\" <$fromemail>" . $headersep . "reply-to: \"$fullname\" <$email>" . $headersep .

    $headersep . 'mime-version: 1.0' . $headersep . $content_type ;

 

if ($use_envsender) {

    mail($mailto, $subject, $messageproper, $headers, $envsender );

}

else {

    mail($mailto, $subject, $messageproper, $headers );

}

header( "location: $thankyouurl" );

exit ;

 

?>

i've never heard of variable.  should $_server['remote_addr'].



More discussions in Dreamweaver support forum


adobe

Comments

Popular posts from this blog

Warning, the Safe Path is not accessible vm3 - Joomla! Forum - community, help and support

2.5.28 to 3.4.1---Download of update package failed - Joomla! Forum - community, help and support

Your host needs to use PHP 5.3.10 or higher to run this vers - Joomla! Forum - community, help and support