Perl talking with MySQL

I have been working on this for a long time, and with not really knowing Perl
it’s been extremely difficult.

It does seem to be connecting to MySQL because there has not been any of those errors.

I can’t seem to search the database for the value needed.

A short PHP header sends the information the perl script processes.

Is there anyone that can help fix this perl code. I can even send a little by paypal if it’s not to much.
The script is working now as long as I don’t try to use the mysql but I would have to hand code each
new setup if I add morepeople to it.

I only have 5 people using the setup, so it’s not critical, but I have been getting asked by others that would like to use it for their web site. Before I do that I would like it to stream line it to use a database. Database already exists and can already have data entered by a form page.

PHP code that is already in use.


<?php $ip = $_SERVER['REMOTE_ADDR']; // Client IP address if(isset($_POST['referer'])) { $l_sReferer = trim($_POST['referer']); } elseif (isset($_SERVER['HTTP_REFERER'])) { $l_sReferer = base64_encode($_SERVER['HTTP_REFERER']); } else { $l_sReferer = ""; } $id = '1-YS25UHRN3N9D'; // Client id $pg = '1'; // 1=email, 2=text, 3=email/text $url = ""; // back-end url echo ''; ?>

I have tried many different samples of code, tried changing the declaration and param but still can not get it to search the database and retrieve the information on the user.

The database has
username: user-email-address
subscr_id: 1-YS25UHRN3N9D
phone: 123456789/domain-to-send-text

########## Perl code…

#!/usr/bin/perl -w
use warnings;
use strict;
use CGI qw/param/;
use POSIX qw/strftime/;
use DBI;
use diagnostics;

print “ContentType: text/html\n\n”;

my $host = “remote_host”;
my $database = “dbase”;
my $tablename = “tname”;
my $user = “user”;
my $pw = “pw”;

Obtain items from web page.

my $id = param(“id”);
my $ip = param(“ip”);
my $pg = param(“pg”);

this seems to have problem

my $username = param(“username”);
my $subscr_id = param(“subscr_id”);
my $file = “_iptrace.txt”;
my $filea = “/tmp/”;
my $fileb = $subscr_id;
my $filec = “.txt”;
my $filed = “/tmp/invalid_id_iptrace.txt”;
my $phone;


1 = email

2 = phone

3 = both

my $message = param(“pg”);

Is not working. Needs to be changed/removed etc…

my $dbh = DBI->connect(‘DBI:mysql:$database, $host’,’$user’,’$pw’)

or die “Connection Error: $DBI::errstr\n”;

my $sql = “SELECT subscr_id,username FROM $tabelname WHERE subscr_id = 1”;

my $sth = $dbh->prepare($sql);


or die “SQL Error: $DBI::errstr\n”;

my @row = $sth->fetchrow_array();

print “subscr_id\n”;

$sth = $dbh->finish();

if ($id eq 'subscr_id') {

#if we have a match open the file to write.
open(FILE, ‘>’."/tmp/$subscr_id$file");

lets put the time in the file.

print FILE strftime("%A %B %d, %Y - %I:%M %p %Z\n", localtime(time) );

put the IP address and web page visited.

print FILE " – IP Address: $ENV{REMOTE_ADDR}\n\t Accessed your page: $ENV{HTTP_REFERER}\n------\n";
print FILE " – Here is the information we found:\n------\n";

#close the file. Finished with the first part

Run the IP2Location script.

system("./ $ENV{REMOTE_ADDR} json city>>/tmp/$subscr_id$file");

Lets send an email and or text with all the information.

Send email

    if($message == 1) {

system(“mail -s ‘Web Page visited’ $username < /tmp/$subscr_id$file”);
# Send text
if($message == 2) {
system(“mail -s ‘Web Page visited’ $filea$fileb < /tmp/$subscr_id$file”);

Send email and text message

if($message == 3) {
system(“mail -s ‘Web Page visited’ $username < /tmp/$subscr_id$file”);
system(“mail -s ‘Web Page visited’ $filea$fileb < /tmp/$subscr_id$file”);
print “Content-type: text/javascript\n\n”;
print “\n”;


# “To Do” send a page or popup if the id is not valid.
$filed = “/tmp/invalid_id_iptrace.txt”;
open (FILED, ‘>’."$filed") or die $!;
print FILED strftime("%A %B %d, %Y - %I:%M %p %Z\n", localtime(time) );
print FILED " – IP Address: $ip\n\t Access Page: $ENV{HTTP_REFERER} \n From id: $id with :pg as $pg\n------\n";
print FILED " – Database ID: $subscr_id \n------\n";
system(“mail -s ‘Page visited Unknown’ [email protected] < $filed”);
print “Content-type: text/javascript\n\n”;
print “\n”;

#end of script

Sponsor our Newsletter | Privacy Policy | Terms of Service