 |
|
| Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more. |
|
 |

07-15-2011, 12:54 PM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
Adding IP to a PHP Form
How can i add the visitors ip to this php email form?
Code:
<?php
$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
session_start();
if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {
mail("admin@site.com","Title of the Form","Form content:
Name and last name: " . $_POST['field_1'] . "
Country: " . $_POST['field_2'] . "
");
include("confirm.html");
}
else {
echo "Invalid Captcha String.";
}
?>
I know add can just add this
$ip=@$REMOTE_ADDR;
echo "<b>IP Address= $ip</b>";
But where am i gonna add it to and how can i make the form email it with the other content?
This is the processor.php of the email form which is embedded in an html page.
Last edited by Website; 07-15-2011 at 01:02 PM.
|

07-15-2011, 06:22 PM
|
|
Junior Member
|
|
Join Date: 05-26-07
Posts: 9
|
|
Here is the code
PHP Code:
$ip = $_SERVER['REMOTE_ADDR'];
//Then add that to the mail()
mail("admin@site.com","Title of the Form","Form content:
Name and last name: " . $_POST['field_1'] . "
Country: " . $_POST['field_2'] .
" IP : $ip" //<-----
);
Also see
PHP form to email explained
|

07-15-2011, 06:41 PM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
Nice. Thank you.
Do you think we can also add like browser, useragent, computername, location etc. info too?
I mean like all the info we can get from the submitter.
Last edited by Website; 07-15-2011 at 07:07 PM.
|

07-15-2011, 06:57 PM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
As the previous example...
I put this code
$browser = $_SERVER['HTTP_USER_AGENT'];
right under the ip get code.
and this code
"User Agent: $browser" in the mail code. Right next to ip.
But now it doesnt even send any email. And doesnt give any error either.
|

07-15-2011, 07:52 PM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
Well i dont mean to flood but i cant delete my old message. So i have to write another one.
------------------------
I think i found a very nice code for this problem. It gives you full featured computer info of a submitter.
Code:
<script type="text/javascript">
/*
Script Name: Your Computer Information
Author: Harald Hope, Website: http://TechPatterns.com/
Script Source URI: http://TechPatterns.com/downloads/browser_detection.php
Version: 1.2.4
Copyright (C) 3 April 2010
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt
This script requires the Full Featured Browser Detection and the Javascript Cookies scripts
to function.
You can download them here.
http://TechPatterns.com/downloads/browser_detection_php_ar.txt
http://TechPatterns.com/downloads/javascript_cookies.txt
Please note: this version requires the php browser_detection script version 5.3.3 or
newer, because of the new full return of arrays $moz_array and $webkit_array as keys
10 and 11, and $webkit_array key 7, and use of the new array key 14, true_msie_version.
*/
/*
If your page is XHMTL 1 strict, you have to
put this code into a js library file or your
page will not validate
*/
function client_data(info)
{
if (info == 'width')
{
width_height_html = '<h4 class="right-bar">Current Screen Resolution</h4>';
width = (screen.width) ? screen.width:'';
height = (screen.height) ? screen.height:'';
// check for windows off standard dpi screen res
if (typeof(screen.deviceXDPI) == 'number') {
width *= screen.deviceXDPI/screen.logicalXDPI;
height *= screen.deviceYDPI/screen.logicalYDPI;
}
width_height_html += '<p class="right-bar">' + width + " x " +
height + " pixels</p>";
(width && height) ? document.write(width_height_html):'';
}
else if (info == 'js' )
{
document.write('<p class="right-bar">JavaScript is enabled.</p>');
}
else if ( info == 'cookies' )
{
expires ='';
Set_Cookie( 'cookie_test', 'it_worked' , expires, '', '', '' );
string = '<h4 class="right-bar">Cookies</h4><p class="right-bar">';
if ( Get_Cookie( 'cookie_test' ) )
{
string += 'Cookies are enabled</p>';
}
else {
string += 'Cookies are disabled</p>';
}
document.write( string );
}
}
</script>
<div class="float-left-01">
<h3 class="h-right-bar">Your Computer</h3>
<?php
$os = '';
$os_starter = '<h4 class="right-bar">Operating System:</h4><p class="right-bar">';
$os_finish = '</p>';
$full = '';
$handheld = '';
// change this to match your include path/and file name you give the script
include('browser_detection.php');
$browser_info = browser_detection('full');
// $mobile_device, $mobile_browser, $mobile_browser_number, $mobile_os, $mobile_os_number, $mobile_server, $mobile_server_number
if ( $browser_info[8] == 'mobile' )
{
$handheld = '<h4 class="right-bar">Handheld Device:</h4><p class="right-bar">';
if ( $browser_info[13][0] )
{
$handheld .= 'Type: ' . ucwords( $browser_info[13][0] );
if ( $browser_info[13][7] )
{
$handheld = $handheld . ' v: ' . $browser_info[13][7];
}
$handheld = $handheld . '<br />';
}
if ( $browser_info[13][3] )
{
// detection is actually for cpu os here, so need to make it show what is expected
if ( $browser_info[13][3] == 'cpu os' )
{
$browser_info[13][3] = 'ipad os';
}
$handheld .= 'OS: ' . ucwords( $browser_info[13][3] ) . ' ' . $browser_info[13][4] . '<br />';
// don't write out the OS part for regular detection if it's null
if ( !$browser_info[5] )
{
$os_starter = '';
$os_finish = '';
}
}
// let people know OS couldn't be figured out
if ( !$browser_info[5] && $os_starter )
{
$os_starter .= 'OS: N/A';
}
if ( $browser_info[13][1] )
{
$handheld .= 'Browser: ' . ucwords( $browser_info[13][1] ) . ' ' . $browser_info[13][2] . '<br />';
}
if ( $browser_info[13][5] )
{
$handheld .= 'Server: ' . ucwords( $browser_info[13][5] . ' ' . $browser_info[13][6] ) . '<br />';
}
$handheld .= '</p>';
}
switch ($browser_info[5])
{
case 'win':
$os .= 'Windows ';
break;
case 'nt':
$os .= 'Windows<br />NT ';
break;
case 'lin':
$os .= 'Linux<br /> ';
break;
case 'mac':
$os .= 'Mac ';
break;
case 'iphone':
$os .= 'Mac ';
break;
case 'unix':
$os .= 'Unix<br />Version: ';
break;
default:
$os .= $browser_info[5];
}
if ( $browser_info[5] == 'nt' )
{
if ($browser_info[6] == 5)
{
$os .= '5.0 (Windows 2000)';
}
elseif ($browser_info[6] == 5.1)
{
$os .= '5.1 (Windows XP)';
}
elseif ($browser_info[6] == 5.2)
{
$os .= '5.2 (Windows XP x64 Edition or Windows Server 2003)';
}
elseif ($browser_info[6] == 6.0)
{
$os .= '6.0 (Windows Vista)';
}
elseif ($browser_info[6] == 6.1)
{
$os .= '6.1 (Windows 7)';
}
elseif ($browser_info[6] == 'ce')
{
$os .= 'CE';
}
}
elseif ( $browser_info[5] == 'iphone' )
{
$os .= 'OS X (iPhone)';
}
// note: browser detection now returns os x version number if available, 10 or 10.4.3 style
elseif ( ( $browser_info[5] == 'mac' ) && ( strstr( $browser_info[6], '10' ) ) )
{
$os .= 'OS X v: ' . $browser_info[6];
}
elseif ( $browser_info[5] == 'lin' )
{
$os .= ( $browser_info[6] != '' ) ? 'Distro: ' . ucwords($browser_info[6] ) : 'Smart Move!!!';
}
// default case for cases where version number exists
elseif ( $browser_info[5] && $browser_info[6] )
{
$os .= " " . ucwords( $browser_info[6] );
}
elseif ( $browser_info[5] && $browser_info[6] == '' )
{
$os .= ' (version unknown)';
}
elseif ( $browser_info[5] )
{
$os .= ucwords( $browser_info[5] );
}
$os = $os_starter . $os . $os_finish;
$full .= $handheld . $os . '<h4 class="right-bar">Current Browser / UA:</h4><p class="right-bar">';
if ($browser_info[0] == 'moz' )
{
$a_temp = $browser_info[10];// use the moz array
$full .= ($a_temp[0] != 'mozilla') ? 'Mozilla/ ' . ucwords($a_temp[0]) . ' ' : ucwords($a_temp[0]) . ' ';
$full .= $a_temp[1] . '<br />';
$full .= 'ProductSub: ';
$full .= ( $a_temp[4] != '' ) ? $a_temp[4] . '<br />' : 'Not Available<br />';
$full .= ($a_temp[0] != 'galeon') ? 'Engine: Gecko RV: ' . $a_temp[3] : '';
}
elseif ($browser_info[0] == 'ns' )
{
$full .= 'Browser: Netscape<br />';
$full .= 'Full Version Info: ' . $browser_info[1];
}
elseif ( $browser_info[0] == 'webkit' )
{
$a_temp = $browser_info[11];// use the webkit array
$full .= 'User Agent: ';
$full .= ucwords($a_temp[0]) . ' ' . $a_temp[1];
$full .= '<br />Engine: AppleWebKit v: ';
$full .= ( $browser_info[1] ) ? $browser_info[1] : 'Not Available';
}
elseif ( $browser_info[0] == 'ie' )
{
$full .= 'User Agent: ';
$full .= strtoupper($browser_info[7]);
// $browser_info[14] will only be set if $browser_info[1] is also set
if ( array_key_exists( '14', $browser_info ) && $browser_info[14] )
{
$full .= '<br />(compatibility mode)';
$full .= '<br />Actual Version: ' . number_format( $browser_info[14], '1', '.', '' );
$full .= '<br />Compatibility Version: ' . $browser_info[1];
}
else
{
$full .= '<br />Full Version Info: ';
$full .= ( $browser_info[1] ) ? $browser_info[1] : 'Not Available';
}
}
else
{
$full .= 'User Agent: ';
$full .= ucwords($browser_info[7]);
$full .= '<br />Full Version Info: ';
$full .= ( $browser_info[1] ) ? $browser_info[1] : 'Not Available';
}
echo $full . '</p>';
?>
<script type="text/javascript">
client_data('width');
</script>
<h4 class="right-bar">JavaScript</h4>
<script type="text/javascript">
client_data('js');
</script>
<noscript>
<p class="right-bar">JavaScript is disabled</p>
</noscript>
<script type="text/javascript">
client_data('cookies');
</script>
</div>
Can anybody tell me how can i add this to my php email processer form?
Example can be seen at
http://techpatterns.com/downloads/ph..._detection.php
|

07-17-2011, 06:04 AM
|
|
Junior Member
|
|
Join Date: 07-17-11
Posts: 13
|
|
Why are you making your life complicated? Just use PHP in order to get users info in the form.
PHP Code:
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
// here add the info you need from customer as a different variables $ip, $browser and so on and take the info from the form
$message="User ip: ".$ip." User browser ".$browser;
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
|

07-17-2011, 06:19 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
You da man. Thank you.
|

07-17-2011, 06:39 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
Well now what do you put between the values when you want to add more info in message code?
$message="User ip: ".$ip." User browser ".$browser;
say i want to add these inquiries also...
$HTTP_COOKIE_VARS["users_resolution"]
$_SERVER['HTTP_REFERER']
$_ENV[COMPUTERNAME]
|

07-17-2011, 06:57 AM
|
|
Junior Member
|
|
Join Date: 07-17-11
Posts: 13
|
|
Quote:
Originally Posted by Website
Well now what do you put between the values when you want to add more info in message code?
$message="User ip: ".$ip." User browser ".$browser;
say i want to add these inquiries also...
$HTTP_COOKIE_VARS["users_resolution"]
$_SERVER['HTTP_REFERER']
$_ENV[COMPUTERNAME]
|
first get the values in new variables
$resolution=$HTTP_COOKIE_VARS["users_resolution"];
$pcname=$_ENV[COMPUTERNAME];
$serv=$_SERVER['HTTP_REFERER'] ;
and the have to include it in the mail
$message="User ip: ".$ip." User browser ".$browser." Resolution ".$resolution." Computer name ".$pcname." Server ".$serv;
|

07-17-2011, 07:16 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
Perfect. What informations i can get from them? Because i couldnt get the resolution. This is a form which is embedded in an html page.
|

07-18-2011, 05:13 AM
|
 |
Contributing Member
|
|
Join Date: 07-05-11
Location: philippines
Posts: 312
|
|
|
Please note that $_SERVER['HTTP_USER_AGENT'] sometimes does not work because some browsers does not send it's info. You may encounter a PHP notice from it..
|

07-18-2011, 05:17 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
Then what is the best code to get the user agent?
|

07-18-2011, 05:27 AM
|
 |
Contributing Member
|
|
Join Date: 07-05-11
Location: philippines
Posts: 312
|
|
JavaScript would do, you can put it inside a hidden field before submitting your form.
HTML Code:
<input type="hidden" name="user_agent" id="ua" />
Code:
<script type="text/javascript">
document.getElementByid('ua').value = navigator.userAgent;
</script>
|

07-18-2011, 05:33 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
I cant use java... it has to be php.
|

07-18-2011, 08:26 AM
|
|
Contributing Member
Latest Blog: None
|
|
Join Date: 03-02-11
Posts: 94
|
|
|
Its javascript, not java and you use it to transfer data to php...
|

07-18-2011, 08:27 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
So what is my php code and how can i put it in there?
|

07-18-2011, 08:31 AM
|
|
Contributing Member
Latest Blog: None
|
|
Join Date: 03-02-11
Posts: 94
|
|
You're going to want to use something like this:
Code:
<form action="myPhpFile.php" method="post">
<input type="hidden" name="user_agent" id="ua" />
</form>
Then you grab the data in php using
Code:
$_POST['user_agent']
|

07-18-2011, 08:33 AM
|
 |
Contributing Member
Latest Blog: None
|
|
Join Date: 11-15-10
Posts: 315
|
|
|
This is getting too complicated. I dont even know where to put these codes in my email form.
Its ok. Thx anyways.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 11:51 PM.
Powered by vBulletin Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP
|
|
|