how to change type of a variable to string?

 
Post new topic   Reply to topic    Aprelium Forum Index -> Perl
View previous topic :: View next topic  
Author Message
littlestar
-


Joined: 23 Aug 2005
Posts: 7

PostPosted: Tue Aug 23, 2005 5:22 am    Post subject: how to change type of a variable to string? Reply with quote

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 View user's profile Send private message
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Tue Aug 23, 2005 10:45 am    Post subject: Re: how to change type of a variable to string? Reply with quote

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 View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Tue Aug 23, 2005 12:38 pm    Post subject: Re: how to change type of a variable to string? Reply with quote

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 View user's profile Send private message Send e-mail
littlestar
-


Joined: 23 Aug 2005
Posts: 7

PostPosted: Wed Aug 24, 2005 3:20 am    Post subject: Reply with quote

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 View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Wed Aug 24, 2005 12:42 pm    Post subject: Reply with quote

littlestar,

Try:

Code:

my $ipaddr = "$ENV{'REMOTE_ADDR'}";


or

Code:

$sql->execute("$ipaddr");

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
littlestar
-


Joined: 23 Aug 2005
Posts: 7

PostPosted: Thu Aug 25, 2005 3:10 am    Post subject: Reply with quote

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 View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Aug 25, 2005 1:14 pm    Post subject: Reply with quote

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 View user's profile Send private message Send e-mail
littlestar
-


Joined: 23 Aug 2005
Posts: 7

PostPosted: Fri Aug 26, 2005 7:51 am    Post subject: Reply with quote

wonderful, it ran sucessful.
how nice of you to help me, thanks aprelium so much...
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Aug 26, 2005 12:59 pm    Post subject: Reply with quote

littlestar,

Glad to know that our reply has helped solving the problem.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Perl All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group