Welcome to Geeklog, Anonymous Friday, December 27 2024 @ 11:52 am EST

Geeklog Forums

IP address retreival


Anonymous

Anonymous
Anyone know how to have someone's ip address recorded and included when they click the contact admin link?
 Quote

Anonymous

Anonymous
// get users IP address $ip = getenv(REMOTE_ADDR); // write IP address in subject line print "<a href=""; print "mailto:youremail@yourdomain.com?subject=$ip""; print ">Click Here to Email Me</a>; I am PHP noob. Sorry if inefficient. later, garry aka admin@xdrop.com
 Quote

Anonymous

Anonymous
Aah crap, forgot a here it is" // get users IP address $ip = getenv(REMOTE_ADDR); // write IP address in subject line print "<a href=""; print "mailto:youremail@yourdomain.com?subject=$ip""; print ">Click Here to Email Me</a>; Like I said! I am PHP noob. lol, later
 Quote

Anonymous

Anonymous
Hey, its stripping slashes. NO wonder! // get users IP address $ip = getenv(REMOTE_ADDR); // write IP address in subject line print "<a href=""; print "mailto:youremail@yourdomain.com?subject=$ip<backslash>""; print ">Click Here to Email Me</a>"; Substitute the <backslash> with a real backslash. later, garry aka admin@xdrop.com
 Quote

Anonymous

Anonymous
what file do i add this to?
 Quote

Status: offline

rawdata

Forum User
Full Member
Registered: 02/17/03
Posts: 236
What his code does is create a link which when clicked will call the visitor's email application software and place your email address in the "To" line and the user's IP in the "Subject" line. To do this more covertly and using Geeklog's contact form, you can do something like this.

Put this function inside /system/lib-custom.php.
Text Formatted Code

function getIP()
{
    if (getenv("HTTP_CLIENT_IP"))
        $ip = getenv("HTTP_CLIENT_IP");
    else if (getenv("HTTP_X_FORWARDED_FOR"))
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    else if (getenv("REMOTE_ADDR"))
        $ip = getenv("REMOTE_ADDR");
    else
        $ip = 'none';
    return $ip;
}
 
Inside profiles.php, find this section of code in the function contactemail:
Text Formatted Code

            $RET = @mail($A['username'] . ' <' . $A['email'] . '>', $subject,
                strip_tags(stripslashes($message)),
                "From: $author <$authoremail>rn" .
                "Return-Path: <$authoremail>rn" .
                "Content-Type: text/plain; charset=$charsetrn" .
                "X-Mailer: GeekLog " . VERSION);
 
If you want to include the sender's IP address on all email sent via the contact form, then replace the above with this code.
Text Formatted Code

                $RET = @mail($A['username'] . ' <' . $A['email'] . '>', $subject,
                    strip_tags(stripslashes($message)),
                    "From: $author <$authoremail>rn" .
                    "Return-Path: $authoremailrn" .
                    "X-Sender-IP: $iprn" .
                    "Content-Type: text/plain; charset=$charsetrn" .
                    "X-Mailer: GeekLog " . VERSION);
 
This inserts the sender's IP address into the "X-Sender-IP" header of emails sent by anyone to anyone. If you want to include the IP address on only for emails sent to Admin or another specific user, then replace the section above with this code instead. Note: The default $uid for Admin is 2. If you changed this, want to use another $uid, or a group of $uid's then just modify the "if" part:
Text Formatted Code

            if ($uid == 2) {
                $ip = getIP();
                $RET = @mail($A['username'] . ' <' . $A['email'] . '>', $subject,
                    strip_tags(stripslashes($message)),
                    "From: $author <$authoremail>rn" .
                    "Return-Path: $authoremailrn" .
                    "X-Sender-IP: $iprn" .
                    "Content-Type: text/plain; charset=$charsetrn" .
                    "X-Mailer: GeekLog " . VERSION);
            }
            else {
                $RET = @mail($A['username'] . ' <' . $A['email'] . '>', $subject,
                    strip_tags(stripslashes($message)),
                    "From: $author <$authoremail>rn" .
                    "Return-Path: <$authoremail>rn" .
                    "Content-Type: text/plain; charset=$charsetrn" .
                    "X-Mailer: GeekLog " . VERSION);
            }
 
*** PLEASE NOTE: All the rn's in the code above should be slash r and slash n. Geeklog keeps stripping off the slashes.
 Quote

Status: offline

rawdata

Forum User
Full Member
Registered: 02/17/03
Posts: 236
Ooops, a line was dropped in the first replace section I posted. It should read like this:
Text Formatted Code

$ip = getIP();
$RET = @mail($A['username'] . ' <' . $A['email'] . '>', $subject,
                    strip_tags(stripslashes($message)),
                    "From: $author <$authoremail>\r\n" .
                    "Return-Path: $authoremail\r\n" .
                    "X-Sender-IP: $ip\r\n" .
                    "Content-Type: text/plain; charset=$charset\r\n" .
                    "X-Mailer: GeekLog " . VERSION);
 
I figured out how to get around GL stripping out the backslashes...use two of them instead of one.
 Quote

Anonymous

Anonymous
Thanks for the well documented code!! You are an asset to this community!! Is there any way to grab the persons WAN address if they are behind a router that uses nat rather then their computer address??
 Quote

Status: offline

rawdata

Forum User
Full Member
Registered: 02/17/03
Posts: 236
I'm not sure whether or where the server stores the WAN IP. Maybe someone who has access to this type of setup knows. I think REMOTE_ADDR will give the router's IP if it's behind a firewall instead of the actual computer.
 Quote

Anonymous

Anonymous
thanks, i will give it a try!!
 Quote

All times are EST. The time is now 11:52 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content