PDA

View Full Version : IP Address passing


TonysDesigns
03-14-2006, 04:41 AM
Hey people. I currently use a perl script for our contact us form page(seen below). The use from this script comes from an HTML page. I am interested in passing the user's IP address to our form that is emailed to us when the user hits submit. In other words, how can I display the user's Ip address on the "thanks page" AND pass it to our mail we receive?

Here is the code:

#!/usr/bin/perl
use Cwd;
$cgipath='/www1/makeuptalk.com/cgi-bin';
$ftproot=GetFTPRoot($cgipath);
SetIncludePath($cgipath);
require 'municacgi.cgi';
$scripturl="http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}";
$m_pos=rindex($scripturl, "/");
$cgiurl=substr($scripturl, 0, $m_pos);
$cgipath='/www1/makeuptalk.com/cgi-bin';
$ftproot=GetFTPRoot($cgipath);
$cgipath=FTP2System($cgipath);
$WWW_APPNAME="FormPAL";
$_str_valid="Email=EMAIL&";
ParseForm();
if (defined($FORM{'Submit'})||($FORM{'Trigger'}[0] eq "Submit"))
{
ValidateForm($_str_valid);
SendMail("Action1", "@{$FORM{'First Name'}}", "@{$FORM{'Email'}}", "EMAILADDYHERE", $cc, $subject, "@{$FORM{'Subject'}}", "", "");
PostUrl("Action2", 0, "", "http://www.makeuptalk.com/contact/thanks.php");
exit(0);
}
Info();

sub SetIncludePath
{
my($m_cgipath)=shift;

$m_cgipath="$ftproot/$m_cgipath" if ($m_cgipath =~ /^\//);
$m_cgipath=~ s/\\/\//g;
$m_cgipath=~ s/(\/)+/\//g;
pop(@INC);
push(@INC, $_) if ($_ ne '.');
push(@INC, "$m_cgipath");
push(@INC, ".");
$cc = qw(EMAILADDYHERE);
$subject = qw(From_MakeupTalk_Contact_Us_page);

}

sub GetCGIPath
{
my ($m_cgipath)=shift;
my ($m_cwd);
if ($ENV{'PATH_TRANSLATED'} ne "")
{
$m_cwd=$ENV{'PATH_TRANSLATED'};
$m_pos=rindex($m_cwd, "/");
$m_pos=rindex($m_cwd, "\\") if ($m_pos<0);
$m_cwd=substr($m_cwd, 0, $m_pos);
}elsif ($ENV{'SCRIPT_FILENAME'} ne "")
{
$m_cwd=$ENV{'SCRIPT_FILENAME'};
$m_pos=rindex($m_cwd, "/");
$m_pos=rindex($m_cwd, "\\") if ($m_pos<0);
$m_cwd=substr($m_cwd, 0, $m_pos);
}else
{
$m_cwd=getcwd();
}
$m_cwd=~ s/\\/\//g;
$m_cwd=~ s/(\/)+/\//g;
return $m_cwd;
}


sub GetFTPRoot
{
my ($m_cgipath)=shift;
my ($m_cwd);

$m_cwd=GetCGIPath();

$m_cgipath=~ s/(\/)+/\//g;
$m_pos=rindex($m_cgipath, "/");
$m_pos=rindex($m_cgipath, "\\") if ($m_pos<0);
$m_cgipath=substr($m_cgipath, 0, $m_pos) if ($m_pos==(length($m_cgipath)-1));

if (length($m_cgipath)>=length($m_cwd))
{
return "";
}elsif ($m_cwd=~/($m_cgipath)$/)
{
return $`;
}elsif ($m_cwd=~/($m_cgipath)\//)
{
return $`;
}else
{
return $m_cwd;
}
}




Many Thanks

TonysDesigns
03-15-2006, 07:03 AM
bump, anyone?

FishMonger
03-15-2006, 07:48 AM
The user's IP address is stored in the $ENV{'REMOTE_ADDR'} environment variable.
http://hoohoo.ncsa.uiuc.edu/cgi/env.html

The prefered method for sending an email is with the use of one of Perl's email modules. The one I use most often is MIME::Lite.
http://search.cpan.org/~yves/MIME-Lite-3.01/lib/MIME/Lite.pm

TonysDesigns
03-15-2006, 07:50 AM
Hi Fish,

thanks for the response. I really need help with where to put that tid bit of code and how to properly use it on the HTML page to display it.

Can you do that for me? I can toss a few bones to you via paypal if needed.

PM me if interested in customizing my code for me

FishMonger
03-15-2006, 09:48 AM
Is that the formpal script from mumica.com and did you actually pay for it? If the code you posted is representative of the rest of the script, it's going to need more work (fixing) than I'm willing to do, but I'll help add the patch you're requesting.

Add this line to near the top.
$remote_address = $ENV{'REMOTE_ADDR'};
Post the subroutine called SendMail so I can see what adjustments it needs. I also need to see the form you mention and how and where you're displaying the "thanks page". Rather than seeing these sections out of context, it would be best if you could post the entire script as an attachment so I can see what it's doing.