Could you look at this code

From: Date: Fri, 22 Sep 2000 04:04:02 +0000
Subject: Could you look at this code
Groups: php.general 
Request: Send a blank email to php-general+get-17279@lists.php.net to get a copy of this message
Would it be to much to ask if people could look at this code and tell me how I could make it more friendly and maybe more compressed. Would functions work better to do all of this. This script is to run at root on the command line called by cron #!/usr/local/bin/php <?php //defalt ip address $ip = "207.204.234.45"; $hostname = "localhost"; $username = ""; $password = ""; $dbName = ""; $db = MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); mysql_select_db($dbName ,$db); //Search database for new subscripers $query = "SELECT * FROM pcustomers "; $result = mysql_query ($query) or die("Error in query"); while($myrow = mysql_fetch_array($result)) { //Select a new ip address for subscriber $query1 = "SELECT ip FROM ipaddress LIMIT 1"; $result1 = mysql_query ($query1) or die("Error in query"); while($myrow1 = mysql_fetch_array($result1)) { $ipaddress = $myrow1["ip"]; } //set varabals for eash subscriber $domainname = $myrow["domaname"]; $account = $myrow["account"]; $sdomaname = $myrow["sdomaname"]; $name = $myrow["name"]; $company = $myrow["company"]; $street = $myrow["street"]; $city = $myrow["city"]; $state = $myrow["state"]; $zip = $myrow["zip"]; $country = $myrow["country"]; $hphone = $myrow["hphone"]; $wphone = $myrow["wphone"]; $fax = $myrow["fax"]; $email = $myrow["email"]; $username = $myrow["username"]; $password = $myrow["password"]; $frontpage = $myrow["frontpage"]; $terms = $myrow["terms"]; $id = $myrow["id"]; $plan = $myrow["plan"]; $wantdatabase = $myrow["wantdatabase"]; $databasename = $myrow["databasename"]; $signdate = $myrow["signdate"]; if ($account =="NewDomain") { //If new account is Economy do this if ($plan=="Economy"){ $ipn = "-i $ip"; $host = " -n www"; $dom = " -d $domainname"; $mb = " -q 25"; $user = " -u 2"; $cgi =" -c"; $ssl =" -l"; $ftp = " -f:"; $ee = " -e"; $webd =" -w"; $fullyqualified ="-d www.$domainname"; $username = " -u $name"; $userspasswd = " -p $password"; $quotainMB = " -q 10"; $siteadmi = " -a "; $string = "$ipn $host $dom $mb $usr $cgi $ssl $ftp $ee $webd"; $string2 = "$fullyqualified $username $userpasswd $quotainMB $siteadmi"; if ($frontpage=="YES") $fp = " -x"; $string = $string . $fp; $string2 = $string2 . $fp; } //If new account is Basic do this //Basic Account if ($plan== "Basic"){ $ipn = "-i $ip"; $host = " -n www"; $dom = " -d $domainname"; $mb = " -q 50"; $user = " -u 4"; $cgi =" -c"; $ssl =" -l"; $ftp = " -f:"; $ee = " -e"; $webd =" -w"; $fullyqualified ="-d www.$domainname"; $username = " -u $name"; $userspasswd = " -p $password"; $quotainMB = " -q 10"; $siteadmi = " -a "; $string = "$ipn $host $dom $mb $usr $cgi $ssl $ftp $ee $webd"; $string2 = "$fullyqualified $username $userpasswd $quotainMB $siteadmi"; if ($frontpage=="YES") $fp = " -x"; $string = $string . $fp; $string2 = $string2 . $fp; } //If new account is Delux do this // Deluxe Account if ($plan== "Deluxe"){ $ipn = "-i $ip"; $host = " -n www"; $dom = " -d $domainname"; $mb = " -q 75"; $user = " -u 8"; $cgi =" -c"; $ssl =" -l"; $ftp = " -f:"; $ee = " -e"; $webd =" -w"; $fullyqualified ="-d www.$domainname"; $username = " -u $name"; $userspasswd = " -p $password"; $quotainMB = " -q 10"; $siteadmi = " -a "; $string = "$ipn $host $dom $mb $usr $cgi $ssl $ftp $ee $webd"; $string2 = "$fullyqualified $username $userpasswd $quotainMB $siteadmi"; if ($frontpage=="YES") $fp = " -x"; $string = $string . $fp; $string2 = $string2 . $fp; } //If new account is Commerce do this // Commerce Account if ($plan== "Commerce"){ //If database is out of ip address set this defalt for now If ($ipaddress == ""){ $ipaddress = "207.204.234.67"; } $ipn = "-i $ipaddress"; $host = " -n www"; $dom = " -d $domainname"; $mb = " -q 100"; $user = " -u 10"; $cgi =" -c"; $ssl =" -l"; $ftp = " -f:"; $ee = " -e"; $webd =" -w"; $ssi = " -s"; $shell=" -t"; $fullyqualified ="-d www.$domainname"; $username = " -u $name"; $userspasswd = " -p $password"; $quotainMB = " -q 10"; $siteadmi = " -a "; $string = "$ipn $host $dom $mb $usr $cgi $ssl $ftp $ee $webd $ssi $shell"; $string2 = "$fullyqualified $username $userpasswd $quotainMB $siteadmi"; // Store used ip address in usedipaddress along with domain name and date $query2="INSERT INTO usedipaddress VALUES ('NULL','$ipaddress', '$domainname','NULL')"; $result2 = mysql_query ($query2) or die("Error in query"); if ($frontpage=="YES") $fp = " -x"; $string = $string . $fp; $string2 = $string2 . $fp; } //If new account is Professional do this // Professional Account if ($plan== "Professional"){ //If database is out of ip address set this defalt for now If ($ipaddress == ""){ $ipaddress = "207.204.234.67"; } $ipn = "-i $ipaddress"; $host = " -n www"; $dom = " -d $domainname"; $mb = " -q 150"; $user = " -u 20"; $cgi =" -c"; $ssl =" -l"; $ftp = " -f:"; $ee = " -e"; $webd =" -w"; $ssi = " -s"; $shell=" -t"; $fullyqualified ="-d www.$domainname"; $username = " -u $name"; $userspasswd = " -p $password"; $quotainMB = " -q 10"; $siteadmi = " -a "; $string = "$ipn $host $dom $mb $usr $cgi $ssl $ftp $ee $webd $ssi $shell"; $string2 = "$fullyqualified $username $userpasswd $quotainMB $siteadmi"; // Store used ip address in usedipaddress along with domain name and date $query2="INSERT INTO usedipaddress VALUES ('NULL','$ipaddress', '$domainname','NULL')"; $result2 = mysql_query ($query2) or die("Error in query"); if ($frontpage=="YES") $fp = " -x"; $string = $string . $fp; $string2 = $string2 . $fp; } //If new account is Exclusive do this // Exclusive Account if ($plan== "Exclusive"){ //If database is out of ip address set this defalt for now If ($ipaddress == ""){ $ipaddress = "207.204.234.67"; } $ipn = "-i $ipaddress"; $host = " -n www"; $dom = " -d $domainname"; $mb = " -q 200"; $user = " -u 30"; $cgi =" -c"; $ssl =" -l"; $ftp = " -f:"; $ee = " -e"; $webd =" -w"; $ssi = " -s"; $shell=" -t"; $fullyqualified ="-d www.$domainname"; $username = " -u $name"; $userspasswd = " -p $password"; $quotainMB = " -q 10"; $siteadmi = " -a "; $string = "$ipn $host $dom $mb $usr $cgi $ssl $ftp $ee $webd $ssi $shell"; $string2 = "$fullyqualified $username $userpasswd $quotainMB $siteadmi"; // Store used ip address in usedipaddress along with domain name and date $query2="INSERT INTO usedipaddress VALUES ('NULL','$ipaddress', '$domainname','NULL')"; $result2 = mysql_query ($query2) or die("Error in query"); if ($frontpage=="YES") $fp = " -x"; $string = $string . $fp; $string2 = $string2 . $fp; } //Delete any used ip address from the database $query3="DELETE FROM ipaddress WHERE (ip = '$ipaddress')"; $result3 = mysql_query ($query3) or die("Error in query"); // Run the script to update the server echo "<br>"; echo ("system /usr/sbin/cobalt/addvsite $string"); echo "<br>"; echo ("system /usr/sbin/cobalt/adduser $string2"); echo "<br>"; echo "<br>"; } } ?> NorthWestHost Your web host provider www.northwesthost.com

« previous php.general (#17279) next »