Need a Perl Script Converted to PHP.

kayzne

Power Member
Dec 26, 2007
705
1,968
Hey,

I need a perl script converted to php with an accompanying MySQL db. Please Bid.

Here's the code:

Main CGI:

Code:
#!/usr/bin/perl
use CGI::Carp 'fatalsToBrowser';
use CGI qw (:standard);

require "variables.pl";

open(ACT, "$file");
flock(ACT, 2);
@act = <ACT>;
flock(ACT, 8);
close(ACT);
$ac = $ENV{'QUERY_STRING'};
$referer = $ENV{'HTTP_REFERER'};
$forward = "";
foreach $line (@act) {
	chop($line);
	@info = split(/\|/, $line);
	if($info[0] eq $ac) {
		&site;		
	}

}
if($forward eq "") {
$forward = "$default";
print "Location: $forward\n\n";
} else { &site; }

sub site {
open(HEAD,"index.html");
flock(HEAD, 2);
@head = <HEAD>;
flock(HEAD, 8);
close(HEAD);
print "Content-type:text/html\n\n";
foreach $temp (@head) {
  $temp =~ s/\<username>/$info[0]/gi;
  $temp =~ s/\<email>/$info[2]/gi;
  $temp =~ s/\<name>/$info[3]/gi;
  $temp =~ s/\<siteheadline>/$info[4]/gi;
  $temp =~ s/\<url>/$info[5]/gi;
  $temp =~ s/\<description>/$info[6]/gi;
  $temp =~ s/\<id>/$info[7]/gi;
  print $temp; }
exit;
}

MEMBER CGI


Code:
#!/usr/bin/perl
$|=1;

use CGI::Carp 'fatalsToBrowser';
use CGI qw (:standard);

require "variables.pl";
$action = param(action);
$user = param(user);
$pass = param(pass);

if($action eq "menu") { &menu; }
elsif($action eq "addmem") { &addmem; }
elsif($action eq "send2") { &send2; }
elsif($action eq "editmember") { &editmember; }
elsif($action eq "editmember2") { &editmember2; }
elsif($action eq "deletemember") { &deletemember; }
else { &main; }

sub main {
print "Content-type:text/html\n\n";
print qq|
<html>
<head>
<title>$program</title>
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="3">
  <tr>
    <td width="100%" bgcolor="#000080"><font face="Arial" color="#FFFFFF"><b>$program</b></font></td>
  </tr>
  <tr>
    <td width="100%">
      <blockquote>
        <p><font face="Arial" size="2">To login to your account please
        fill in your username and password in the boxes below. To create a new account, scroll down and choose your own user name and password</font></p>
        <div align="center">
          <center>
          <form action="$ENV{'SCRIPT_NAME'}" method="POST">
          <table border="0" cellspacing="0" cellpadding="2" width="248">
            <tr>
              <td width="88"><b><font face="Arial" size="2">Username:</font></b></td>
              <td width="148"><input type="text" name="user" size="20"></td>
            </tr>
            <tr>
              <td width="88"><b><font face="Arial" size="2">Password:</font></b></td>
              <td width="148"><input type="password" name="pass" size="20"></td>
            </tr>
            <tr>
              <td width="236" colspan="2">
                <p align="center"><input type="submit" value="Login"></td>
            </tr>
          </table> <input type="hidden" name="action" value="menu">
          </form>
<BR><BR><font face="Arial" size="2">To add your account, please
        fill in the form below. You will need to be a paypal member
and you will need a home page url. If you are not a paypal
member, please sign up here <a href="http://www.paypal.com
" target="new">Click Here</a></font>
<form action="$ENV{'SCRIPT_NAME'}" method="POST">
<table border="0" cellspacing="0" cellpadding="2" width="248">
            <tr>
              <td width="88"><b><font face="Arial" size="2">Username:</font></b></td>
              <td width="148"><input type="text" name="username" size="20"></td>
            </tr>
            <tr>
              <td width="88"><b><font face="Arial" size="2">Password:</font></b></td>
              <td width="148"><input type="password" name="password" size="20"></td>
            </tr>
               <tr>
              <td width="88"><b><font face="Arial" size="2">Name:</font></b></td>
              <td width="148"><input type="text" name="name" size="20"></td>
            </tr>
              <tr>
              <td width="88"><b><font face="Arial" size="2">Email:</font></b></td>
              <td width="148"><input type="text" name="email" size="20"></td>
            </tr>
            <tr>
              <td width="88"><b><font face="Arial" size="2">WebSite Title:</font></b></td>
              <td width="148"><input type="text" name="siteheadline" size="20"></td>
            </tr>
             <tr>
              <td width="88"><b><font face="Arial" size="2">Website URL:</font></b></td>
              <td width="148"><input type="text" name="url" size="20"></td>
            </tr>
            <tr>
              <td width="88"><b><font face="Arial" size="2">Description:</font></b></td>
              <td width="148"><input type="text" name="description" size="20"></td>
            </tr>
             <tr>
              <td width="88"><b><font face="Arial" size="2">PayPal Email:</font></b></td>
              <td width="148"><input type="text" name="id" size="20"></td>
            </tr>
            <tr>
              <td width="236" colspan="2">
                <p align="center"><input type="submit" value="Add"></td>
            </tr>
          </table>
          <input type="hidden" name="action" value="addmem">
          </form>
          </center>
        </div>
      </blockquote>
    </td>
  </tr>
  <tr>
    <td width="100%" bgcolor="#000080">
      <p align="right"><font face="Arial" size="2" color="#FFFFFF">©2001-2003 CGItoolbox.com </font></td>
  </tr>
</table>
<center><FONT FACE=verdana SIZE=1><B>$program written<BR>
by <a href="http://www.hostswan.com/cgi">CGI Toolbox</a></B></FONT></center>
</body>

</html>
|;
exit;
}

sub addmem {
@data = param;
foreach $data (@data) {${$data} = param($data);}
unless($username && $password && $email && $name && $siteheadline && $url && $description && $id){
		&plainerror('A Form Field was left blank, please click your browsers back button and try again!'); }
unless($url =~ m/http:\/\//){
&plainerror('Site URL must be in this format "http://www.yoursite.com"'); }

open(FILE, "$file");
flock(FILE, 2);
@file = <FILE>;
flock(FILE, 8);
close(FILE);
foreach $line (@file) {
	chomp($line);
	@temp = split(/\|/,$line);
	if($temp[0] eq $username) { $found = 1; }
}
if($found eq "1") {
	&plainerror("Username Already Used");
}

open(ACCTS,">>$file") || &plainerror("Could not open file ($!)");
flock(ACCTS, 2);
print ACCTS "$username|$password|$email|$name|$siteheadline|$url|$description|$id\n";
flock(ACCTS, 8);
close(ACCTS);
open(AUTO, "signup.txt") || &plainerror("Could not open autoresponder file ($!)!");
	@auto = <AUTO>;
	close(AUTO);
	open(MAIL, "|$sendmail -t") || &plainerror("Could not open sendmail ($!)!");
	print MAIL "To: $email\n";
	print MAIL "From: $adminemail\n";
	print MAIL "Subject: Welcome!\n\n";
	foreach $line (@auto) {
		chop($line);
	$line =~ s/<name>/$name/g;
	$line =~ s/<username>/$username/g;
	$line =~ s/<email>/$email/g;
	$line =~ s/<password>/$password/g;
        $line =~ s/<siteheadline>/$siteheadline/g;
        $line =~ s/<url>/$url/g;
        $line =~ s/<description>/$description/g;
        $line =~ s/<id>/$id/g;
	print MAIL "$line\n";
	}
	close(MAIL);
open(AUTO, "affiliate.txt") || &plainerror("Could not open autoresponder file ($!)!");
	@auto = <AUTO>;
	close(AUTO);
	open(MAIL, "|$sendmail -t") || &plainerror("Could not open sendmail ($!)!");
	print MAIL "To: $adminemail\n";
	print MAIL "From: $adminemail\n";
	print MAIL "Subject: You Have a New Affiliate!\n\n";
	foreach $line (@auto) {
		chop($line);
	$line =~ s/<name>/$name/g;
	$line =~ s/<username>/$username/g;
	$line =~ s/<email>/$email/g;
	$line =~ s/<password>/$password/g;
        $line =~ s/<siteheadline>/$siteheadline/g;
        $line =~ s/<url>/$url/g;
        $line =~ s/<description>/$description/g;
        $line =~ s/<id>/$id/g;
	print MAIL "$line\n";
	}
	close(MAIL);
&plainerror('You have been added! Push Your Back Button to log in or check your email for further instructions');
exit;
}


sub uauth {
open(UDB, "$file") || &plainerror("Could not open passwd ($!)!");
flock(UDB, 2);
@udb = <UDB>;
flock(UDB, 8);
close(UDB);
$found = 0;
foreach $line (@udb) {
	chop($line);
	@info = split(/\|/,$line);
	if($user eq $info[0] && $pass eq $info[1]) {
		$found = 1;
	}
}
unless($found eq "1") { &plainerror("Invalid logon information."); }
}

sub menu {
&uauth;
open(UDB, "$file") || &plainerror("Could not open passwd ($!)!");
flock(UDB, 2);
@udb = <UDB>;
flock(UDB, 8);
close(UDB);
$found = 0;
foreach $line (@udb) {
	chop($line);
	@info = split(/\|/,$line);
if($info[0] eq $user){
print "Content-type:text/html\n\n";
print qq|<html>
<head>
<title>$program</title>
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="3">
  <tr>
    <td width="100%" bgcolor="#000080"><font face="Arial" color="#FFFFFF"><b>$program</b></font></td>
  </tr>
  <tr>
    <td width="100%">
      <blockquote>
  <center>
           <p align="center"><font face="arial" size="3"><b>$program</b></font></p>
 <p align="center"><font face="arial" size="2"><b>URL to Promote is:<BR>
                <a href="$promote/main.cgi?$user">$promote/main.cgi?$user</a></b></font></p>
                <p align="center"><b><font size="2">Update Form</font></b></p>
                <form method="POST" action="$ENV{'SCRIPT_NAME'}">
                  <table border="0" cellspacing="0" cellpadding="2" width="248">
              <tr>
              <td width="88"><b><font face="Arial" size="2">Password:</font></b></td>
              <td width="148"><input type="password" name="npass" size="20" value="$info[1]"></td>
            </tr>
             <tr>
              <td width="88"><b><font face="Arial" size="2">Email:</font></b></td>
              <td width="148"><input type="text" name="email" size="20" value="$info[2]"></td>
            </tr>
            <tr>
              <td width="88"><b><font face="Arial" size="2">Website Headline:</font></b></td>
              <td width="148"><input type="text" name="siteheadline" size="20" value="$info[4]"></td>
            </tr>
             <tr>
              <td width="88"><b><font face="Arial" size="2">Website URL:</font></b></td>
              <td width="148"><input type="text" name="url" size="20" value="$info[5]"></td>
            </tr>
            <tr>
              <td width="88"><b><font face="Arial" size="2">Description:</font></b></td>
              <td width="148"><input type="text" name="description" size="20" maxlength="150" value="$info[6]"></td>
            </tr>
             <tr>
              <td width="88"><b><font face="Arial" size="2">PayPal Email:</font></b></td>
              <td width="148"><input type="text" name="id" size="20" value="$info[7]"></td>
            </tr>
            <tr>
              <td width="236" colspan="2">
                <p align="center"><input type="submit" value="Submit"></td>
            </tr>
          </table>
                  <input type="hidden" name="action" value="editmember">
                  <input type="hidden" name="pass" value="$pass">
                  <input type="hidden" name="user" value="$user">
                </form>
               <p align="center"><b><font size="2" color="#000000">To DELETE your account,
          press the button below</font></b></p>
        <form method="POST" action="$ENV{'SCRIPT_NAME'}">
         <p align="center"><input type="submit" value="Delete My Account">
  <input type="hidden" name="action" value="deletemember">
                  <input type="hidden" name="pass" value="$pass">
                  <input type="hidden" name="user" value="$user">
</p>
        </form>
</blockquote>
    </td>
  </tr>
  <tr>
    <td width="100%" bgcolor="#000080">
      <p align="right"><font face="Arial" size="2" color="#FFFFFF">©2001-2003 CGItoolbox.com </font></td>
  </tr>
</table>
<center><FONT FACE=verdana SIZE=1><B>$program written<BR>
by <a href="http://www.hostswan.com/cgi">CGI Toolbox</a></B></FONT></center>
</body>

</html>
</body>

</html>
|;
}}
exit;
}

sub editmember {
&uauth;
@data = param;
foreach $data (@data) {
${$data} = param($data);
}

open(ACCTS,"$file") || &plainerror("Could not open file ($!)");
flock(ACCTS, 2);
@accts = <ACCTS>;
flock(ACCTS, 8);
close(ACCTS);
foreach $line (@accts) {
	chop($line);
	($luser,$lpass,$lemail,$lname,$lsiteheadline,$lurl,$ldescription,$lid) = split(/\|/,$line);
      if($user eq $luser){
   $line = "$luser|$npass|$email|$name|$siteheadline|$url|$description|$id\n";
}
else {
$line = "$line\n";
}
}
open(ACCTS,">$file") || &plainerror("Could not open file ($!)");
flock(ACCTS, 2);
print ACCTS (@accts);
flock(ACCTS, 8);
close(ACCTS);

&plainerror('The member has been edited');
exit;
}

sub deletemember {
&uauth;
@data = param;
foreach $data (@data) {${$data} = param($data);}

open(ACCTS,"$file") || &plainerror("Could not open file ($!)");
flock(ACCTS, 2);
@accts = <ACCTS>;
flock(ACCTS, 8);
close(ACCTS);
foreach $line (@accts) {
	chop($line);
	@tempd = split(/\|/,$line);
      if($user eq $tempd[0]){
   $line = "";
}
else {
$line = "$line\n";
}
}
open(ACCTS,">$file") || &plainerror("Could not open file ($!)");
flock(ACCTS, 2);
print ACCTS (@accts);
flock(ACCTS, 8);
close(ACCTS);

&plainerror('Your have been deleted');
exit;
}

sub plainerror {
 print "Content-type:text/html\n\n";
print qq|
        <HTML><HEAD>
  <title>$program</title>
</head>
<body bgcolor="ffffff">
<table border="0" width="100%" cellspacing="0" cellpadding="3">
  <tr>
    <td width="100%" bgcolor="#000080"><font face="Arial" color="#FFFFFF"><b>$program</b></font></td>
  </tr>
  <tr>
    <td width="100%">
      <blockquote>
 <FONT FACE="Arial" SIZE=2 COLOR=000080><CENTER>$_[0]</CENTER></FONT><HR WIDTH=50%>
</blockquote>
    </td>
  </tr>
  <tr>
    <td width="100%" bgcolor="#000080">
      <p align="right"><font face="Arial" size="2" color="#FFFFFF">©2001-2003 CGItoolbox.com </font></td>
  </tr>
</table><center><FONT FACE=verdana SIZE=1><B>$program written<BR>
by <a href="http://www.hostswan.com/cgi">CGI Toolbox</a></B></FONT></center>
  </BODY></HTML>
|;
exit;
}

Variables.
Code:
#path to sendmail
$sendmail = "/usr/sbin/sendmail";

#Your email address
$adminemail = "yourname\@yoursite.com";

# this is the path to the data.txt file
$file = "/www/yourpath/af/data.txt";

# this is where the script will send the visitor if the
#visitor types in the wrong url
$default = "http://www.yourdomain.com/af/main.cgi?main";

# this is the path to the directory where the scripts are.
$datapath = "/www/yourpath/af/";

# this is the name of your program
$program = "Your Affiliate Program";

# this is the URL to the directory where the scripts are
$promote = "http://www.yourdomain.com/af";

1;
 
I am not sure why you want it to be converted... There is so many differences between the architecture there and the one you want. I saw a couple of security flaws in your perl script. So you want an online form for someone to subscribe to become a member affiliate and login to a kind of portal...

you need it pure PHP or using a framework or as a wordpress extension?
 
I am not sure why you want it to be converted... There is so many differences between the architecture there and the one you want. I saw a couple of security flaws in your perl script. So you want an online form for someone to subscribe to become a member affiliate and login to a kind of portal...

you need it pure PHP or using a framework or as a wordpress extension?

You're right, I need something to work essentially as this script does.

Basically, someone signs up, fills in some data which can be displayed on mydomain.com/theirname page using php.
 
@OP: I could do everything on php from scratch.

If want so, please PM me.

I think, IMO, that converting from perl would take much more time if its just done from scratch.

And as always, that's my 20 bucks :cool:
 
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock