wmguk Posted July 10, 2009 Share Posted July 10, 2009 Hey, I have a small script, which runs a whois check and then shows domain names available to register, it allows you to select those names, and add them to cart, and then when you view cart it needs to show a purchase button... So far most of this works, however for some reason I cannot get it to add all the domain names in to the order details... Can this be done? MAIN PAGE <?php // Start the session session_start(); $cart = $_SESSION['cart']; require("whois_config.php"); require("tlds.php"); $action=$_POST[action]; if(!$action) {$action=$_GET[action];} $domainname=$_POST[domainname]; if(!$domainname) {$domainname=$_GET[domainname];} $stld=$_POST[stld]; if(!$stld) {$stld=$_GET[stld];} function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return 'Cart: 0 items'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; $domainname=$_POST[domainname]; if(!$domainname) {$domainname=$_GET[domainname];} return 'Cart: <a href="cart.php?action=view&domainname='.$domainname.'">'.count($items).' item'.$s.'</a>'; } }?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Wicked Websites, Websites that work!</title> <link href="../wicked-websites_domains.css" rel="stylesheet" type="text/css"> </head> <body> <span class="admintext"><? echo writeShoppingCart(); ?><a href="clear.php?action=checkit&domainname=<? echo $domainname; ?>&stld=all">| Clear Cart</a></span> <? if (!$action) { ?> <form method="POST" ACTION="index.php" method="POST"> <table width="700" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td align="center"> <input type="text" name="domainname" value="domain" size="40"> <select size="1" name="stld"> <? $i=0; while ($i < $tlds) { $x=$i+1; if($i=='0') {echo "<option value=".$x.">".$tld[$i+1]."</option>";} else {echo "<option value=".$x.">".$tld[$i+1]."</option>";} $i++; } if ($allow_all=="true") {echo "<option value='all' selected>all</option>";} ?> </table> <input type="hidden" name="action" value="checkit"> <input type=submit Value="Search"> </font> </form> <? } else if ($action=="checkit") { // Lets do the lookup // Set up the screen ?> <br><br> <? // Check domain length if (strlen($domainname)<3) { ?> <b>Domain name MUST be 3 or more characters long</b> <label></label> <form> <input type='button' value='<< Back' onClick='history.go(-1)'> </form> </body></html> <? die; } if (strlen($domainname)>63) { ?> <b>Domain name to long. Domain MUST be under 63 characters long</b> <form> <input type='button' value='<< Back' onClick='history.go(-1)'> </form></body></html> <? die; } if(ereg("^-|-$",$domainname)) { ?> <b>Domain cannnot start with a hyphen or contain double hyphens.</B> <form> <input type='button' value='<< Back' onClick='history.go(-1)'> </form></body></html> <? die; } if ($tld[$stld]<>".name") { if(!ereg("([a-z]|[A-Z]|[0-9]|-){".strlen($domainname)."}",$domainname)) { ?> <b>Illegal characters in domain name - domain can only be alpha numeric characters</b> <form> <input type='button' value='<< Back' onClick='history.go(-1)'> </form></body></html> <? die; } } if ($tld[$stld]==".name") { if(!ereg(".",$domainname)) { ?> <b>name domains must contain a '.', example 'fred.smith.name'.</b> <form> <input type='button' value='<< Back' onClick='history.go(-1)'> </form></body></html> <? die; } } ?> <table width="700" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <? if ($writelog=="true") { // Do we write to the log? $time=time(); $searchtime = date("D d M Y @ H:i:s",$time); $ip = getenv("REMOTE_ADDR"); $hip = @gethostbyaddr($ip); $ip = str_pad($ip, 15, " "); $hip = str_pad($hip, 35, " "); $ldom = $domainname.$tld[$stld]; $ldom = str_pad($ldom, 35, " "); $logit = $searchtime." | ".$ip." | ".$hip." | ".$ldom." |"; if ($stld=="all") $logit = $logit."ALL"; $logit = $logit."\n"; $fp = fopen($logfile,"a+"); fputs($fp, $logit); fclose($fp); } if ($stld=="all") { // User want to check ALL tlds // Let's output the table if ($reglink<>"") echo "<td> </td>"; ?> <td class="adminheader">Domain Name</td> <td class="adminheader">Available?</td> <td class="adminheader">Details</td> </tr> <tr> <? if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; list($name, $cost) = explode(":", $item); echo $name; } $i=0; while ($i < $tlds) { $domname=$domainname.$tld[$i+1]; $anic=$nic[$i+1]; $arep=$rep[$i+1]; $cost=$costs[$i+1]; $ns = fsockopen($anic,43); fputs($ns,"$domname\r\n"); $result = ''; while(!feof($ns)) $result .= fgets($ns,128); fclose($ns); if (eregi($arep,$result)) { echo"<td><a href=cart.php?action=add&id=$domname&domainname=$domainname&cost=$cost>Register</a></td>"; echo"<td class='admintext'>$domname</td>"; echo"<td class='admintext'>Yes</td>"; echo"<td class='admintext'>".$cost."</td>"; echo"</tr><tr>"; } else { if ($reglink<>"") {echo "<td> </td>";} $stlds=$i+1; if ($allow_link=="true") {$alink="http://".$domname; echo"<td class='red'><a href='$alink' TARGET='_blank'>$domname</a></td>"; } else { echo"<td>$domname</td>"; } echo"<td><span class='red'>Taken</span></td>"; echo"<td class='red'><a href='index.php?action=details&domainname=$domainname&stld=$stlds'>Show Details</a></td>"; echo"</tr><tr>"; } $i++; } //END OF CRAP } //END HERE } else { // Single tld lookup // Lets output the table if ($reglink<>"") echo "<td> </td>"; ?> <td class="adminheader">Domain Name</td> <td class="adminheader">Available?</td> <td class="adminheader">Details</td> </tr> <tr> <? $arep=$rep[$stld]; $cost=$costs[$stld]; $domname=$domainname.$tld[$stld]; $wnic=$nic[$stld]; $ns = fsockopen($wnic,43); fputs($ns,"$domname\r\n"); $result = ''; while(!feof($ns)) $result .= fgets($ns,128); fclose($ns); if (eregi($rep[$stld],$result)) { if ($reglink<>"") {$sendlink=$reglink."?domname=".$domname; echo "<td><a href=cart.php?action=add&id=$domname&domainname=$domainname&cost=$cost>Register</a></td>"; } echo"<td>$domname</td>"; echo"<td>Yes</td>"; echo"<td>$cost</td>"; echo"</tr><tr>"; } else { if ($reglink<>"") {echo "<td> </td>";} if ($allow_link=="true") {$alink="http://".$domname; echo"<td><a href='$alink' TARGET='_blank'>$domname</a></td>"; } else { echo"<td>$domname</td>"; } echo"<td>Taken</td>"; echo"<td><a href='index.php?action=details&domainname=$domainname&stld=$stld'>Show Details</a></td>"; echo"</tr><tr>"; } } echo"</table> <p> <form method=POST ACTION='index.php' method='POST'> <input type=submit Value='New Search'> </form>"; if (!$return_link=="") { echo "<a href='".$return_link."'>".$return_text."</a><br>"; } ?> </p> <? } else if ($action=="details") { $domname=$domainname.$tld[$stld]; $wnic=$nic[$stld]; $ns = fsockopen($wnic,43); fputs($ns,"$domname\r\n"); $result = ''; echo "<pre>"; while(!feof($ns)) echo fgets($ns,128); fclose($ns); ?> </pre> <form> <input type='button' value='<< Back' onClick='history.go(-1)'> </form> <? } ?> </html> </body> CART PAGE <link href="../wicked-websites_domains.css" rel="stylesheet" type="text/css"><? // Start the session session_start(); $cart = $_SESSION['cart']; $action = $_REQUEST['action']; $id = $_REQUEST['id']; $cost = $_REQUEST['cost']; $domainname = $_REQUEST['domainname']; // Include MySQL class //require_once('inc/mysql.class.php'); // Include database connection //require_once('inc/global.inc.php'); // Include functions //require_once('inc/functions.inc.php'); if ($action=="add") { if ($cart) { $cart .= ','.$id.":".$cost; } else { $cart = $id.":".$cost; } $_SESSION['cart'] = $cart; header("location:index.php?action=checkit&domainname=".$domainname."&stld=all"); } elseif ($action=="view") { $domainname = $_REQUEST['domainname']; function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return 'Cart: 0 items'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return 'Cart: <a href="cart.php?action=view">'.count($items).' item'.$s.'</a>'; } }?> <span class="admintext"><? echo writeShoppingCart(); ?><a href="clear.php?action=checkit&domainname=<? echo $domainname; ?>&stld=all">| Clear Cart</a><br><br> <? $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; list($name, $cost) = explode(":", $item); echo $name." - ".$cost."<br>"; $total += $cost ; $pname = $name ; } echo $total; ?> <form action="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/476243854168807" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"> <input name="item_name_1" type="hidden" value="Purchase <?php echo $pname; ?>"/> <input name="item_description_1" type="hidden" value="<?php echo $pname; ?>"/> <input name="item_quantity_1" type="hidden" value="1"/> <input name="item_price_1" type="hidden" value="<?php echo $total; ?>"/> <input name="item_currency_1" type="hidden" value="GBP"/> <input name="_charset_" type="hidden" value="utf-8"/> <input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=476243854168807&w=117&h=48&style=white&variant=text&loc=en_US" type="image"/> </form><?php } echo "<br><br><a href=index.php?action=checkit&domainname=".$domainname."&stld=all>Add More</a>"; } else { } ?> </span> Link to comment https://forums.phpfreaks.com/topic/165478-loop-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.