Hi Monks, I have a script that will be run on a local machine that will update a MySQL database hosted on a website but I do not want to have the database details in the local script as it will obviously be a bit of a security issue. I understand how to use "includes" in PHP for instance to allow me to get the necessary info to a webpage etc but I do not know how to do this in Perl, can anyone enlighten me? Current script (ugly as it may be!) that works fine on a local database is below. In this script I do pull info from a local "config.ini" file as well and I need to get similar info but from a secure area in a website that I will login to and uses sessions to authenticate etc.
use strict; use IO::Socket; use POSIX; use Config::Simple; use DBD::mysql; for(;;){ # Reading configuration parameters from the config.ini file my $cfg = new Config::Simple(); $cfg->read('config.ini'); my $host = $cfg->param("pbx"); my $port = $cfg->param("port"); print "Connecting to the PBX $host on port $port\n"; my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => $port,P +roto => "tcp",) or die "Cannot connect to PBX at address: $host port: $port: $!"; while (<$sock>) { s/^\0+//; # Remove leading null characters print $_; chomp ($_); #$_ =~ s/^[^ ]+//; if ($_ =~m"/") { &TXTout; &DBconnect; } } #Close While loop sub TXTout { my ($year, $mon, $day); $year = strftime '%Y', localtime; $mon = substr ($_, 1,2); $day = substr ($_, 4,2); my $file = "$year"."-"."$mon"."-"."$day".".log"; if (-f $file){ open (my $fh,'>>', $file); print $fh "$_\n"; close $file; } else { open (my $fh,'>', $file); print $fh "$_\n"; close $file; } }# End of filePrint routine sub DBconnect { # MySQL Connection parameters # MySQL Connection parameters my $dbuser= "user"; my $dbpassword= "password"; my $dbhost= "host"; my ($line, $mon, $day, $stime, $pm, $hrs, $mins, $sec, $callp, $leaddi +git, $callno, $speed, $callp2, $transf, $acccode, $sysid, $tester); $mon = substr ($_, 1,2); $day = substr ($_, 4,2); $stime = substr($_, 7,5); $pm = substr($_, 12,1); $hrs = substr($_, 14,2); $mins = substr($_, 17,2); $sec = substr($_, 20,2); $callp = substr($_, 23,4); $leaddigit = substr($_, 29,3); $callno = substr($_, 33,26); $speed = substr($_, 60,1); $callp2 = substr($_, 61,5); $transf = substr($_, 67,5); $acccode = substr($_, 72,12); $sysid = substr($_, 85,3); $tester = strftime( "%Y",localtime(time)); if ($acccode == ""){$acccode = 0} # Establish the connection which returns a DB handle my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) + or die $DBI::errstr; # Prepare the SQL statement my $stmt1 = qq(INSERT INTO import (month,day,time,PM,hrs,mins,sec,call +ingparty,leaddigit,calledno,speeddialind,calledparty,transferext,acco +untcode,sysid,year) VALUES('$mon','$day','$stime','$pm','$hrs','$mins +','$sec','$callp','$leaddigit','$callno','$speed','$callp2','$transf' +,'$acccode','$sysid','$tester');") or die $DBI::errstr; # Send the statement to the server my $rv1 = $dbh->do($stmt1) or die $DBI::errstr; # Close the database connection $dbh->disconnect or die $DBI::errstr; } #Close DBconnect subroutine #close the socket close $sock or die "close: $!"; print "socket closed"; print "<br />"; }

In reply to SOLVED!! "Include" parameters from website by bajangerry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.