For a couple of years I had a 'Contact Us' form which generated a basic text email message to our secretary. The message included the IP address of the sender, which proved very helpful in determing the source of spam.
Recently, I changed the format of the message from text, to HTML, which required that I specify each variable manually. i used '$ipaddress' for the sender IP, but this variable sends the IP address of my server, not that of the sender. What is the correct variable name to use, to report the sender IP?
Thanks
*** Not A Bug *** IP address in contact form
Forum rules
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/forms.html
http://www.wysiwygwebbuilder.com/form_wizard.html
Frequently Asked Questions about Forms
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/forms.html
http://www.wysiwygwebbuilder.com/form_wizard.html
Frequently Asked Questions about Forms
*** Not A Bug *** IP address in contact form
Last edited by MGD4me on Thu Nov 07, 2019 1:29 am, edited 1 time in total.
Re: IP address in contact form
$ipaddres contains the remote address ($_SERVER['REMOTE_ADDR']), not the server address.
See also:
https://www.php.net/manual/en/reserved. ... server.php
See also:
https://www.php.net/manual/en/reserved. ... server.php
Re: IP address in contact form
I don't know if this makes a difference, but the server is running php version 7.0, and when I request a 'phpinfo', $_SERVER['REMOTE_ADDR'] returns it's own server IP address, not the remote address as I would have thought.
However, scrolling through the phpinfo dump, I noticed that the variable $_SERVER['HTTP_X_REAL_IP'] does in fact provide the desired remote address, so I changed the HTML which gets generated for the 'Contact' page from:
$code = str_replace('$ipaddress', $_SERVER['REMOTE_ADDR'], $code); to read:
$code = str_replace('$ipaddress', $_SERVER['HTTP_X_REAL_IP'], $code);
... and now all is well again (for me).
Regards
However, scrolling through the phpinfo dump, I noticed that the variable $_SERVER['HTTP_X_REAL_IP'] does in fact provide the desired remote address, so I changed the HTML which gets generated for the 'Contact' page from:
$code = str_replace('$ipaddress', $_SERVER['REMOTE_ADDR'], $code); to read:
$code = str_replace('$ipaddress', $_SERVER['HTTP_X_REAL_IP'], $code);
... and now all is well again (for me).
Regards
Re: *** Not A Bug *** IP address in contact form
Problem solved !!!
After reviewing PHP info on our web server, I noticed that the reported variable $_SERVER['REMOTE_ADDR'] was incorrect. It should have been displaying the remote IP address of the client, when in fact it was showing the server's own IP address.
After contacting the web host company and reporting the issue, they were able to fix the problem at their end, and my temporary 'patch' to the code is no longer required.
After reviewing PHP info on our web server, I noticed that the reported variable $_SERVER['REMOTE_ADDR'] was incorrect. It should have been displaying the remote IP address of the client, when in fact it was showing the server's own IP address.
After contacting the web host company and reporting the issue, they were able to fix the problem at their end, and my temporary 'patch' to the code is no longer required.