Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Extra info from form mail such as IP etc?
Old 01-15-2008, 09:14 AM Extra info from form mail such as IP etc?
Ultra Talker

Posts: 316
Trades: 0
Does anyone know how to add other information to the mail you receive from a web form on your page such as the senders IP address, location, browser and screen res etc?

I've seen some of those on other forms but am not sure how to extract them and use on mine.

Thanks.
Joe3000 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-15-2008, 09:34 AM Re: Extra info from form mail such as IP etc?
Novice Talker

Posts: 14
Name: Nathan Randle
Trades: 0
Here are all the variables you need...
$_SERVER['REMOTE_ADDR'] gives the IP
$_SERVER['HTTP_X_FORWARDED_FOR'] gives the IP if they're going through a proxy (otherwise you'll get the ISP's IP).
$_SERVER['HTTP_USER AGENT'] gives the full browser user agent info which include browser name and version.

Screen res is a bit more difficult although I believe you can get that through Javscript. For location you'll need a third party web service to convert the IP to a geographic location. Even then it's not completely accurate.
Dolbz is offline
Reply With Quote
View Public Profile
 
Old 01-15-2008, 09:59 AM Re: Extra info from form mail such as IP etc?
Ultra Talker

Posts: 316
Trades: 0
Thanks!

Where abouts do I put them?

I tried it like this to no avail:

PHP Code:
<?php
@extract($_POST);
$name stripslashes($name);
$email stripslashes($email);
$subject stripslashes($subject);
$text stripslashes($text);
mail('yah@gmail.com',$subject,$text,"From: $name <$email>");
header("location:mailsent.htm");
$_SERVER['REMOTE_ADDR'];
$_SERVER['HTTP_X_FORWARDED_FOR'];
$_SERVER['HTTP_USER AGENT'];
?>
Joe3000 is offline
Reply With Quote
View Public Profile
 
Old 01-15-2008, 10:10 AM Re: Extra info from form mail such as IP etc?
Novice Talker

Posts: 14
Name: Nathan Randle
Trades: 0
Code:
<?php
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes($subject);
$text = stripslashes($text);

$text .= "\n\nIP Address: " . $_SERVER['REMOTE_ADDR'] . " or Proxy: " . $_SERVER['HTTP_X_FORWARDED_FOR'];
$text .=  "\n\nUser Agent: " . stripslashes($_SERVER['HTTP_USER AGENT']);
mail('yah@gmail.com',$subject,$text,"From: $name <$email>");
header("location:mailsent.htm");?>
Try that...
Dolbz is offline
Reply With Quote
View Public Profile
 
Old 01-15-2008, 10:37 AM Re: Extra info from form mail such as IP etc?
Ultra Talker

Posts: 316
Trades: 0
Thank you.

It gave me the IP but not the proxy or User Agent:

IP Address: 123.456.789.123 or Proxy:

User Agent:
Joe3000 is offline
Reply With Quote
View Public Profile
 
Old 01-15-2008, 10:44 AM Re: Extra info from form mail such as IP etc?
Novice Talker

Posts: 14
Name: Nathan Randle
Trades: 0
Woops. missed an underscore between 'user' and 'agent' so it should read... $_SERVER['HTTP_USER_AGENT']

The proxy isn't being filled in because I'm assuming you're not behind a proxy or if you are it's not adding the HTTP_X_FORWARDED_FOR header to the HTTP request.
If you don't want a blank field like that change the following from....
PHP Code:
$text .= "\n\nIP Address: " $_SERVER['REMOTE_ADDR'] . " or Proxy: " $_SERVER['HTTP_X_FORWARDED_FOR']; 
to...
PHP Code:
$text .= "\n\nIP Address: " $_SERVER['REMOTE_ADDR'];
if (
$_SERVER['HTTP_X_FORWARDED_FOR']) {
    
$text .= " or Proxy Reports: " $_SERVER['HTTP_X_FORWARDED_FOR'];

Dolbz is offline
Reply With Quote
View Public Profile
 
Old 01-15-2008, 10:56 AM Re: Extra info from form mail such as IP etc?
Ultra Talker

Posts: 316
Trades: 0
Thanks. It now appears to be working:

User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

Cheers!
Joe3000 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Extra info from form mail such as IP etc?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40035 seconds with 12 queries