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

LVL 2
Shamsul KamalJunior TechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Shamsul KamalJunior TechAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.