RE: [PHP] Could you look at this code

From: Date: Wed, 27 Sep 2000 05:28:47 +0000
Subject: RE: [PHP] Could you look at this code
Groups: php.general 
Request: Send a blank email to php-general+get-17646@lists.php.net to get a copy of this message
For a start, stop being so long winded about getting the variable names from the database, use extract Eg: extract(mysql_fetch_array($result)); instead of $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"]; ... Also, from a brief look you've duplicated the following repeatedly $ipn = "-i $ip"; $host = " -n www"; $dom = " -d $domainname"; $cgi =" -c"; $ssl =" -l"; $ftp = " -f:"; $ee = " -e"; $webd =" -w"; $fullyqualified ="-d www.$domainname"; $username = " -u $name"; $userspasswd = " -p $password"; Why not only set these once (I've just done a brief run though, you'll have to look more carefully) Then only change the "real" variables such as $quotainMB = " -q 10"; Also I'd personally use a switch statement, but thats coding style more than anything. Its a little unclear from the pasted code to go any deeper at the moment, but that should give you a start. -----Original Message----- From: Richard Kurth [mailto:rkurth@pacifier.com] Sent: September 22, 2000 12:04 PM To: Php Subject: [PHP] Could you look at this code 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#17646) next »