Gossamer Forum
Home : General : Perl Programming :

Probably a stupid error..

Quote Reply
Probably a stupid error..
Hi guys/gals,

I've come across a bit of a roadblock in one of my recent projects Unsure

Basically, in Gcommunity.. I am loading an IFRAME of the below script;

Code:
#!/usr/local/bin/perl

use strict;
use lib '/var/www/html/sites/www.site.com/admin';
use CGI::Carp qw(fatalsToBrowser);
use CGI;
use DBI;

my $DEBUG = 1;

my $IN = new CGI;

my $s = $IN->param('s');

my $dbh = DBI->connect( "dbi:mysql:dbname;host=localhost",
"user",
"pass",
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::errstr";

my $sql = qq{ SELECT * FROM comm_sessions WHERE sess_id = '$s' };
print STDERR qq{$sql has been run...\n} if $DEBUG > 0;

my $sth = $dbh->prepare( $sql );
$sth->execute();
my $check_sess = $sth->fetchrow_hashref || undef;
print STDERR qq|Command run, grabbed session ID $check_sess->{sess_user_fk}...\n| if $DEBUG > 0;
$dbh->disconnect();

my $cookie;
if ($check_sess->{sess_user_fk}) {
print STDERR qq|Found session: $check_sess->{sess_user_fk}..., writing cookie... \n| if $DEBUG > 0;
$cookie = $IN->cookie( -name => "remotelog", -value => "$check_sess->{sess_user_fk}", -path => '/' );
}

print $IN->header( -cookie => $cookie );
print "a";

Now, the debugging gives the correct info (in the error log, as its going to STDERR);

Quote:
[Tue Feb 01 10:35:43 2005] [error] [client 81.153.50.125] SELECT * FROM comm_sessions WHERE sess_id = 'fe2483116ded732fb37a4e5ee986e5b7' has been run...,
[Tue Feb 01 10:35:43 2005] [error] [client 81.153.50.125] Command run, grabbed session ID 1...,
[Tue Feb 01 10:35:43 2005] [error] [client 81.153.50.125] [Tue Feb 1 10:35:43 2005] session.cgi: DBI::db=HASH(0x828c2e0)->disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting) at /home/andy/web/sites/www.site.com/session.cgi line 32.
[Tue Feb 01 10:35:43 2005] [error] [client 81.153.50.125] Found session: 1..., writing cookie... ,

.. yet the cookie doesn't seem to be generated (I'm looking in the "Environment" part of "Setup").

Can anyone see the stupid mistake? I've been staring at this code for a few hours now... and its really hurting my head Unsure

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Probably a stupid error.. In reply to
BTW, if you run the same script in a browser, it works perfectly, and sets the cookie Unsure

Actual HTML;
<iframe src="http://www.site.com/session.cgi?s=43ffdc3734ea441d841854a2f6715590" width="1" height="1">

URL in browser:
http://www.site.com/session.cgi?s=43ffdc3734ea441d841854a2f6715590

TIA for any ideas/suggestions.

Cheers

Andy

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Probably a stupid error.. In reply to
http://search.cpan.org/~timb/DBI/DBI.pm#finish

Your statement handle has more than one row fetched in buffer. Use selectrow_hashref instead. It'll call finish for you.

~Charlie

Last edited by:

Chaz: Feb 1, 2005, 8:25 AM
Quote Reply
Re: [Andy] Probably a stupid error.. In reply to
Code:
my $sql = qq{ SELECT * FROM comm_sessions WHERE sess_id = '$s' };
print STDERR qq{$sql has been run...\n} if $DEBUG > 0;

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

That would be much better as:

my $sql = 'SELECT * FROM comm_sessions WHERE sess_id = ?';
my $sth = $dbh->prepare($sql);
$sth->execute($s);

as then you prevent some sql injection attacks.

As for it not working in iframe, but working in browser, it might be security related if they are on different domains.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Chaz] Probably a stupid error.. In reply to
Sorry Andy,

I should have prefaced my first response with "I'm not sure about the iframe/cookie problem but the DBI errors can be fixed with...". I ran across this very same problem (cookies & iframes) on another forum but they never got a response to that thread. Someone also posted a similar problem to the CGI::Application mailing list a few months back however I don't think it really relates to your exact problem. It may give you some ideas though: http://www.mail-archive.com/...um.net/msg01831.html. There is a link to a frame FAQ in one of the responses.

Sorry I couldn't offer much help with the real problem :/ Do post back if you find a solution.

~Charlie