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,

Edited by JovanJ
Link to comment
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
Share on other sites

I've tried to add ob_start(); and same error in error_log. Also i tried to change 2083 to 2082 and again same. Do you've any other idea what i can do? Is there some other way in php how i can redirect page after some code lines are finished?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.