Donno24 0 Newbie Poster

Hi Everyone,

I was wondering can someone with Ajax experience to have a look at the following PHP script. Its a simple domain checker.
I am using sessions to pass data from page to page but when I get to this domain checker page and I search for a domain it clears the session.

I was thinking if this form was in ajax it would solve my problem. Unfortunately I know nothing of Ajax and I was wondering would someone be so kind to have a look at it for me?

I hope you can help,
Kind Regards,
Paul

<?php

    function checkDomain($domain,$server,$findText){
        // Open a socket connection to the whois server
        $con = fsockopen($server, 43);
        if (!$con) return false;
        
        // Send the requested doman name
        fputs($con, $domain."\r\n");
        
        // Read and store the server response
        $response = ' :';
        while(!feof($con)) {
            $response .= fgets($con,128); 
        }
        
        // Close the connection
        fclose($con);
        
        // Check the response stream whether the domain is available
        if (strpos($response, $findText)){
            return true;
        }
        else {
            return false;   
        }
    }
    
    function showDomainResult($domain,$server,$findText){
       if (checkDomain($domain,$server,$findText)){
          echo "<tr><td>$domain</td><td>AVAILABLE</td></tr>";
       }
       else echo "<tr><td>$domain</td><td>TAKEN</td></tr>";
    }

?>


      <form action="" method="post" name="domain">
        Domain name:
        <table>
          <tr><td><input name="domainname" type="text" /></td></tr>
          <tr><td><input type="checkbox" name="com" checked/>.com</td></tr>
          <tr><td><input type="checkbox" name="couk" checked/>.co.uk</td></tr>
          <tr><td><input type="checkbox" name="net" checked/>.net</td></tr>
          <tr><td><input type="submit" name="submitBtn" value="Check domain"/></td></tr>
        </table>  
      </form>
<?php    
    // The form was submitted
    if (isset($_POST['submitBtn'])){
        $domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
        $d_com      = (isset($_POST['com'])) ? 'com' : ''; 
		$d_couk      = (isset($_POST['couk'])) ? 'couk' : ''; 
		$d_net      = (isset($_POST['net'])) ? 'net' : ''; 
        
        // Check domains only if the base name is big enough
        if (strlen($domainbase)>2){
            echo '<table>';
            if ($d_com != '')  
               showDomainResult($domainbase.".com",'whois.crsnic.net','No match for');
			if ($d_couk != '')  
               showDomainResult($domainbase.".co.uk",'whois.crsnic.net','No match for');
		   if ($d_net != '')  
		   showDomainResult($domainbase.".net",'whois.crsnic.net','No match for');
            echo '</table>';
        }
    }
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.