• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 978
  • Last Modified:

How to change from php fopen to CuRL ?

Hi,

I would like to request an assistant,

I actually want to convert this code to cURL since some server do not support fopen .

$path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/subdomain/index.html";

The full code are as attached.

Appreciates if anybody can helps.

Thank you,

Regards,
Sham
class cpsubdomain{ 
  //declare public variables 
  var $cpuser;    // cPanel username 
  var $cppass;        // cPanel password 
  var $cpdomain;      // cPanel domain or IP 
  var $cpskin;        // cPanel skin. Mostly x or x2. 
   
  //defining constructor 
  function cpsubdomain($cpuser,$cppass,$cpdomain,$cpskin='x'){ 
    $this->cpuser=$cpuser; 
    $this->cppass=$cppass; 
    $this->cpdomain=$cpdomain; 
    $this->cpskin=$cpskin; 
 
  } 
   
 
  //function for creating subdomain 
   
  function createSD($esubdomain){ 
      
      include('config.php');
      
      //checking whether the subdomain is exists 
      $subdomain=$esubdomain.".".$this->cpdomain; 
      $path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/subdomain/index.html"; 
	    $f = fopen($path,"r"); 
	    if (!$f) { 
	      return('Can\'t open cPanel'); 
	    } 
	
	    //check if the account exists 
	    while (!feof ($f)) { 
	      $line = fgets ($f, 1024); 
	      if (ereg ($subdomain, $line, $out)) { 
	       
	      $subdomainexist = "<br><font color = red>'<b>$esubdomain</b>' $subdomainexist</font>";
	      return $subdomainexist;
	      } 
	    } 
	    fclose($f); //close the file resource 
	     
	     
	    //subdomain does not already exist. So proceed to creating it 
	    $path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/subdomain/doadddomain.html?domain=".$esubdomain."&rootdomain=".$this->cpdomain; 
	    $f = fopen($path,"r"); 
	    if (!$f) { 
	      return('Can\'t open cPanel.'); 
	    } 
	
	    //check if the subdomain added 
	    while (!feof ($f)) { 
	      $line = fgets ($f, 1024); 
	      if (ereg ("has been added.", $line, $out)) {
	      
	      $returnsuccess = "<br>'<b>'$esubdomain'</b>' $subdomaincreated" ;
	      return $returnsuccess ;
	     // echo "$esubdomain Subdomain created successfully"; 
	      
	      } 
	    } 
	    fclose($f); //close the file resource 
	    //return success message 
		$returnerror = "<br><font color = red>$subdomainproblem <b>'$esubdomain'</b>.</font>";
        return $returnerror ;
     
	} //end of function

Open in new window

0
smksa
Asked:
smksa
  • 2
1 Solution
 
emphamyCommented:
i am working on converting this code for you, its fairly easy, just want to make sure though that your new host does support curl?
0
 
smksaAuthor Commented:
Hi emphamy,

Thanks for the helps.

Yes, my host support curl , i just check it.

Really appreciates your helps.

Thank you,

Regards,
Sham
0
 
emphamyCommented:
here is a sample code that is really easy to follow =)
<?php
$domain = 'test';
$teststring = 'test';
 
$urlString = "domain=". urlencode($domain) . "&";
$urlString .= "teststring=". urlencode($teststring);
 
$url = "http://www.someurl.com/page.php";
 
$ch = curl_init($url);                                       
curl_setopt ($ch, CURLOPT_POST, 1);                           
curl_setopt ($ch, CURLOPT_POSTFIELDS, $urlString);            
curl_setopt ($ch, CURLOPT_TIMEOUT, 10);                       
																
curl_setopt ($ch, CURLOPT_HEADER, 0);                           
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
 
$result = curl_exec ($ch);                                      
curl_close($ch);                                               
if(is_array($result))
	$output = implode(",",$result);
else	
	$output = $result;
 
echo $output;
 
?>

Open in new window

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now