Convert script from perl to php
Hi everybody,
I need a help to convert from perl to php the following script:
#!/usr/bin/perl
use DBI;
use User::pwent;
require 'cookie.lib';
# Get the input
if($ARGV[0] eq ""){
$buffer=$ENV{'QUERY_STRING'};
if($buffer eq ""){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
}
else {
$buffer=$ARGV[0];
}
$buffer=~ s/\\//;
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/'/?/g;
$FORM{$name} = $value;
}
$buffer=`cat mysql.conf`;
@pairs = split(/\n/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$nome_bd=$FORM{"nome_bd"};
$nome_server=$FORM{"nome_server"};
$login=$FORM{"login"};
$pass=$FORM{"pass"};
$linha_conn = "DBI:mysql:$nome_bd:$nome_server:3306";
$dbh=DBI->connect($linha_conn,$login,$pass,{ RaiseError => 1, AutoCommit => 1 });
print "Content-type: text/html\n";
$cookie = GetCookies ('Maputo');
$COOKIE = $Cookies{'Maputo'};
print "\n";
$sth=$dbh->prepare("select ID from USER where COOKIE='$COOKIE'");
$sth->execute;
@row = $sth->fetchrow_array();
$ID=$row[0];
$sth->finish;
if($row[0] eq ""){
$sth->finish;
$dbh->disconnect;
exit;
}
$sth->finish;
$mostra_dados=0;
if($FORM{'INSERT'} eq "ok"){
&verifica_dados;
if($erro_dados == 0){
if($FORM{'ID'} ne ""){
&actualiza_dados;
}
else {
&insere_dados;
}
$mostra_dados=1;
&formulario;
}
else {
&formulario;
}
}
else {
&formulario;
}
$dbh->disconnect;
exit;
########################################################
# CORRIGE DADOS #
########################################################
sub formulario{
print <
Maputo Admin
EOM
if($FORM{'ID'} eq ""){
print <Add User
EOM
}
else {
print <Edit User
EOM
}
if($erro_dados == 1){
print <Please correct the fields with *
EOM
}
print <
EOM
}
else {
print <
Info updated
EOM
}
print <