Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Need help converting some PHP code

Quote Reply
Need help converting some PHP code
Hi there,

I need to convert some PHP code to a perl / global.

The current code is.

Code:
$query = "select userid, salt from vb_user where username='" . mysql_escape_string($my->username) . "'";
$res = mysql_query($query);
if (mysql_num_rows($res) == 1) {
$row = mysql_fetch_array($res);
$logouthash = md5($row[userid] . $row[salt] . '12345678');
}

I'm running a partially static site (Categories) and a partially dynamic site and would like to have the logout link placed on all pages.

Thanks!
Quote Reply
Re: [shrirch] Need help converting some PHP code In reply to
Hi,

Is this in your GLinks database, or another one?

Cheers

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] Need help converting some PHP code In reply to
Yes, VB is installed in the same database.
Quote Reply
Re: [shrirch] Need help converting some PHP code In reply to
Hi,

Ok, try this:

get_vb_details
Code:
sub {

use Digest::Perl::MD5 'md5_hex';
my $rec = $DB->table('Links')->do_query(qq|select userid, salt from vb_user where username = "$_[0]"|)->fetchrow_hashref;

$rec->{logout_hash} = md5_hex($rec->{userid} . $rec->{salt} . '12345678');

return $rec;

}

Call in GLinks, with:

<%get_vb_details($Username)%>

..then, you should have <%logout_hash%>, and all the other details from the SELECT query.

Hopefully that'll do the job for you :) (untested, as I don't have vB =))

Cheers

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] Need help converting some PHP code In reply to
Thanks, will try it out. The check is in the email. ;)
Quote Reply
Re: [shrirch] Need help converting some PHP code In reply to
I assume that the hashref thingy will contain the username and will escape it to prevent any sql injection via a bad cookie?
Quote Reply
Re: [shrirch] Need help converting some PHP code In reply to
Hi,

Quote:
I assume that the hashref thingy will contain the username and will escape it to prevent any sql injection via a bad cookie?

Nope, it won't - but if you are using the GLinks username format, then that shouldn't even be possible anyway (as the users table gets filtered out)

There is another way of doing it, by making a new set of .def files (database.def, and vb_user.def), and then fill up the def files with the correct table structures, and then use GT::SQL to connect to the table, so you can do stuff like:

my $rec = $NEWDB->table('user')->select( ['userid','salt'],{ username => $_[0] } )->fetchrow_hashref

...although its a little more complex to actually make the .def files =)

Cheers

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] Need help converting some PHP code In reply to
Will give it a shot. THANKS for the clarification.