How get ip using the contact form?
#1 30-10-2012 
  • Registered
  • 0
  • 1
Hello guys!!
I have a custom contact form page and I want to display the ip of the person attached with email!
anybody can help me edit the php code, thanks!

[Image: attachment.php?aid=27585]
[Image: attachment.php?aid=27586]

My code!
PHP Code:
<?php
define
('IN_MYBB'1);
require 
"./global.php";
define('THIS_SCRIPT''contact.php');

global 
$headerinclude$header$theme$footer$templates$lang;

$lang->load('member');
$lang->load('messages');
$lang->load('datahandler_user');

add_breadcrumb("Contact US""contact.php");

$subject htmlspecialchars_uni(trim($mybb->input['subject']));
$message htmlspecialchars_uni(trim($mybb->input['message']));

if(!
$mybb->user['uid'])
{
    
$name htmlspecialchars_uni(trim($mybb->input['name']));
    
$email htmlspecialchars_uni(trim($mybb->input['email']));

    
$usertemplate '<tr>
<td width="40%" class="trow1"><strong>{$lang->full_name}</strong></td>
<td width="60%" class="trow1"><input type="text" class="textbox" size="50" name="name" value="{$name}" /></td>
</tr>
<tr>
<td width="40%" class="trow2"><strong>{$lang->email_address}</strong></td>
<td width="60%" class="trow2"><input type="text" class="textbox" size="50" name="email" value="{$email}" /></td>
</tr>'
;

    
$usertemplate str_replace("\'""'"addslashes($usertemplate));

    eval(
"\$usertemplate = \"" $usertemplate "\";");
}
else
{
    
$name $mybb->user['username'];
    
$email $mybb->user['email'];

    eval(
"\$usertemplate = \"" $templates->get('changeuserbox') . "\";");
}

if(
$mybb->input['action'] == 'do_email' && $mybb->request_method == 'post')
{
    
verify_post_check($mybb->input['my_post_key']);

    if(empty(
$name))
    {
        
$errors[] = $lang->userdata_missing_username;
    }
    elseif(
strpos($name'<') !== false || strpos($name'>') !== false || strpos($name'&') !== false || my_strpos($name'\\') !== false || strpos($name';') !== false || strpos($name',') !== false)
    {
        
$errors[] = $lang->userdata_bad_characters_username;
    }

    if(empty(
$email))
    {
        
$errors[] = $lang->userdata_missing_email;
    }
    elseif(!
validate_email_format($email))
    {
        
$errors[] = $lang->userdata_invalid_email_format;
    }

    if(empty(
$subject))
    {
        
$errors[] = $lang->error_no_email_subject;
    }

    if(empty(
$message))
    {
        
$errors[] = $lang->error_no_email_message;
    }

    if(
$mybb->settings['captchaimage'] == && function_exists("imagepng") && !$mybb->user['uid'])
    {
        require_once 
MYBB_ROOT.'inc/class_captcha.php';
        
$post_captcha = new captcha;

        if(
$post_captcha->validate_captcha() == false)
        {
            
// CAPTCHA validation failed
            
foreach($post_captcha->get_errors() as $error)
            {
                
$errors[] = $error;
            }
        }
        else
        {
            
$hide_captcha true;
        }
    }

    if(
count($errors) == 0)
    {
        if(
$mybb->settings['mail_handler'] == 'smtp')
        {
            
$from $email;
        }
        else
        {
            
$from $name ' <' $email '>';
        }
        
my_mail($mybb->settings['adminemail'], '[' $mybb->settings['bbname'] . ' ' $pages['name'] . '] ' $subject$message$from''''false'text'''$email);

        
redirect($mybb->settings['bburl'], $lang->redirect_emailsent);
    }
    else
    {
        
$errors inline_error($errors);
    }
}

if(
$mybb->settings['captchaimage'] == && function_exists('imagepng') && !$mybb->user['uid'])
    {
        
$correct false;
        require_once 
MYBB_ROOT.'inc/class_captcha.php';
        
$post_captcha = new captcha(false"post_captcha");

        if(
$mybb->input['previewpost'] || $hide_captcha == true && $post_captcha->type == 1)
        {
            
// If previewing a post - check their current captcha input - if correct, hide the captcha input area
            // ... but only if it's a default one, reCAPTCHAs must be filled in every time due to draconian limits
            
if($post_captcha->validate_captcha() == true)
            {
                
$correct true;

                
// Generate a hidden list of items for our captcha
                
$captcha $post_captcha->build_hidden_captcha();
            }
        }

        if(!
$correct)
        {
            if(
$post_captcha->type == 1)
            {
                
$post_captcha->build_captcha();
            }
            else if(
$post_captcha->type == 2)
            {
                
$post_captcha->build_recaptcha();
            }

            if(
$post_captcha->html)
            {
                
$captcha $post_captcha->html;
            }
        }
    }

$template '<html>
<head>
<title>' 
$pages['name'] . '</title>
{$headerinclude}
</head>
<body>
{$header}
{$errors}
<form action="' 
$_SERVER['REQUEST_URI'] . '" method="post">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<table border="0" cellspacing="' 
$theme['borderwidth'] . '" cellpadding="' $theme['tablespace'] . '" class="tborder">
<thead>
<tr>
<td colspan="2" class="thead">
<strong>' 
$pages['name'] . '</strong>
</td>
</tr>
</thead>
<tbody>
{$usertemplate}
<tr>
<td width="40%" class="trow1"><strong>{$lang->email_subject}</strong></td>
<td width="60%" class="trow1"><input type="text" class="textbox" size="50" name="subject" value="{$subject}" /></td>
</tr>
<tr>
<td valign="top" width="40%" class="trow2"><strong>{$lang->email_message}</strong></td>
<td width="60%" class="trow2"><textarea cols="50" rows="10" name="message">{$message}</textarea></td>
</tr>
{$captcha}
</tbody>
</table>
<br />
<input type="hidden" name="action" value="do_email" />
<div align="center"><input type="submit" class="button" value="{$lang->send_email}" /></div>
</form>
{$footer}
</body>
</html>'
;

$template str_replace("\'""'"addslashes($template));

add_breadcrumb($pages['name']);

eval(
"\$page = \"" $template "\";");

output_page($page);

?>
(This post was last modified: 21-07-2014 10:49 AM by leefish.)

#2 30-10-2012 
You want to get the IP address of a stranger? To be honest, I am not really sure how to do that, and even if I did, I think it is a bit intrusive.

I understand you probably want it for banning purposes if spammed, but then you should be using a better captcha if you are being hit by bots/spammers.
The site don't jive? PRESS F5 Flower

#3 30-10-2012 
Fixed on mybb Big Grin
The site don't jive? PRESS F5 Flower



Sorry, that is a members only option