View previous topic :: View next topic |
Author |
Message |
littlestar -
Joined: 23 Aug 2005 Posts: 7
|
Posted: Tue Aug 23, 2005 5:22 am Post subject: how to change type of a variable to string? |
|
|
I'm learning Perl, and I have this question, please support for me.
in database, I have a table with a field is ipaddr(type is varchar)
in Perl, I get ipaddress of my computer and select data from database with this ipaddress.... but have error.
It can't compare data between valid of ipaddress and valid in database.
Can I change type of ipaddress which I get to string? and how to change type?
please help me, thanks so much. |
|
Back to top |
|
|
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Tue Aug 23, 2005 10:45 am Post subject: Re: how to change type of a variable to string? |
|
|
littlestar wrote: | I'm learning Perl, and I have this question, please support for me.
in database, I have a table with a field is ipaddr(type is varchar)
in Perl, I get ipaddress of my computer and select data from database with this ipaddress.... but have error.
It can't compare data between valid of ipaddress and valid in database.
Can I change type of ipaddress which I get to string? and how to change type?
please help me, thanks so much. |
I dont getcha :S
You want to return your results into an array or variables? _________________
|
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Tue Aug 23, 2005 12:38 pm Post subject: Re: how to change type of a variable to string? |
|
|
littlestar,
Please post here your source code and let us know in what line you get the error message (and of course what error message Perl reports). _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
littlestar -
Joined: 23 Aug 2005 Posts: 7
|
Posted: Wed Aug 24, 2005 3:20 am Post subject: |
|
|
I'm so sorry. Last time, I didn't post my source code.
There is some thing which I want to say
#-------------------------------------------------------------------
use strict;
use lib ".";
require "CGI.pl";
use vars qw(
$vars
);
# Check whether or not the user is logged in and, if so, set the $::userid
use Test::Constants;
Test->login(LOGIN_OPTIONAL);
my $ipaddr = $ENV{'REMOTE_ADDR'};
# print $ipaddr; --> output: 192.168.5.113
my $dbh = Test->dbh;
$sql = $dbh->prepare("SELECT * FROM language WHERE ipaddr = ?");
$sql->execute($ipaddr);
#this query can't select, it has error :
#Insecure dependency in parameter 1 of DBI::db=HASH(0x91bbd4c)
#->prepare method call while running with -T switch at Bugzilla/DB.pm line 60
#-----------------------------------------------------
#if I use this how, it's OK.
#$ipaddr = '192.168.5.113';
#$sql = $dbh->prepare("SELECT * FROM language WHERE ipaddr = ?");
#$sql->execute($ipaddr);
#------------------------------------------------------
# Return the appropriate HTTP response headers.
my $cgi = Test->cgi;
print $cgi->header();
# Generate and return the UI (HTML page) from the appropriate template.
my $template = Test->template;
$template->process("index.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Wed Aug 24, 2005 12:42 pm Post subject: |
|
|
littlestar,
Try:
Code: |
my $ipaddr = "$ENV{'REMOTE_ADDR'}";
|
or
Code: |
$sql->execute("$ipaddr");
|
_________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
littlestar -
Joined: 23 Aug 2005 Posts: 7
|
Posted: Thu Aug 25, 2005 3:10 am Post subject: |
|
|
thanks aprelium so much, I tried all your way but ..... I can't still
it still has error like last time. I must do how |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Thu Aug 25, 2005 1:14 pm Post subject: |
|
|
littlestar,
According to our "expert" Perl coder, the error you get is caused by the use of tainted mode in Perl:
Code: |
Insecure dependency in parameter 1 of DBI::db=HASH(0x91bbd4c)
->prepare method call while running with -T switch at Bugzilla/DB.pm line 60
|
You've used the -T switch in Perl interpreter declaration or this switch is enabled in one of the Perl package files.
Tainted mode means that Perl is careful with any data coming from the outside world (usually user input).
For more information about this topic, please read http://gunther.web66.com/FAQS/taintmode.html or search for "tainted mode" in Google.
To untaint a variable, the only method is to use regular expressions to extract some parts of it and to recombine these parts into a new variable.
So in your code here, you should do something like that:
Code: |
# IP matching
$ipaddr =~ /[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/;
$ipaddr = $&;
|
See http://www.dartmouth.edu/web/cgi/untaint.html for more information and a sample code. _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
littlestar -
Joined: 23 Aug 2005 Posts: 7
|
Posted: Fri Aug 26, 2005 7:51 am Post subject: |
|
|
wonderful, it ran sucessful.
how nice of you to help me, thanks aprelium so much... |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Fri Aug 26, 2005 12:59 pm Post subject: |
|
|
littlestar,
Glad to know that our reply has helped solving the problem. _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
|