Jump to content

$result problem


JovanJ

Recommended Posts

Hi,

 

I am making some subdomain script which creates subdomain and also copy some files to folder of that subdomain but...

I've one problem with $result statement. My code looks like this (part of the code):

function subd($host,$port,$ownername,$passw,$request) {
    
      $sock = fsockopen('localhost',2082);
      if(!$sock) {
        print('Socket error');
        exit();
      }
    
      $authstr = "$ownername:$passw";
      $pass = base64_encode($authstr);
      $in = "GET $request\r\n";
      $in .= "HTTP/1.0\r\n";
      $in .= "Host:$host\r\n";
      $in .= "Authorization: Basic $pass\r\n";
      $in .= "\r\n";
    
      fputs($sock, $in);
      while (!feof($sock)) {
        $result .= fgets ($sock,128);
      }
      fclose( $sock );
    
      return $result;
    }
    
    foreach($doms as $dom) {
      $lines = explode(';',$dom);
      if (count($lines) == 2) {
    
        $domain = trim($lines[0]);
        $subd = trim($lines[1]);
      }
      else {
    
        $domain = getVar('domain', DOMAIN);
        $subd = trim($lines[0]);
      }

      $dir = 'public_html/' . $subd; // the Document Root folder for subdomain
      $request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd&dir=$dir";
      $cpanelhost = "mysite.com";
      $result = subd($cpanelhost,2083,$cpaneluser,$cpanelpass,$request);
      $show = strip_tags($result);
      echo $show;

$cpanel_skin - is cpanel skin, set as 'x3'

$cpaneluser - username of cpanel login

$cpanelpassword - password of cpanel password

 

The problem is when I've code as above, subdomain is created fine, but it returns me page 'Server is not responding' and also there is an error in my error_log file "Cannot modify header information - headers already sent by " (There is a redirect header, because of that there is error in error_log).. When i remove :

      $result = subd($cpanelhost,2083,$cpaneluser,$cpanelpass,$request);

Error in error_log is still there, but server is not showing me error page and also subdomain is not created. Does any one have some idea how i can avoid server to show me error page and to redirect it somehow?

 

I forgot to mention, "Cannot modify header information - headers already sent by ", it says outpage happens on line 25, and on that line there is just a open tag for php... <?php ... nothing else :)

 

Cheers,

Link to comment
https://forums.phpfreaks.com/topic/278338-result-problem/
Share on other sites

For the "Cannot modify header information" error, you can't put a header() anywhere in the code after text has been printed out. You can try to resolve that by adding ob_start() to the top of the script to buffer the output (after the first <?php).

 

As for the rest of the code, you seem to be using 2083, which is the SSL port for cPanel, when you call the function, but I don't see that being used anywhere inside the function (you connect to 2082, the standard HTTP port). Not saying it's the problem, just pointing it out.

Link to comment
https://forums.phpfreaks.com/topic/278338-result-problem/#findComment-1431995
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.