Question about PHP error

Discussion in 'PHP' started by REMOTE_ADDR, May 6, 2010.

  1. #1
    Hi, I am new user and I'm sorry if I abrogated your rules...

    I have PHP script, which creates subdomain on cpanel.

    
    
    <?
    
    define('CPANELUSER','here username');
    
    define('CPANELPASS','here password');
    
    define('INPUT_FILE','domainslist.txt');
    
    define('CPANEL_SKIN','skinname');
    
    define('DOMAIN','rootdomain');
    
    
    function getVar($name, $def = '') {
      if (isset($_REQUEST[$name]) && ($_REQUEST[$name] != ''))
        return $_REQUEST[$name];
      else 
        return $def;
    }
    
    $cpaneluser=getVar('cpaneluser', CPANELUSER);
    $cpanelpass=getVar('cpanelpass', CPANELPASS);
    $cpanel_skin = getVar('cpanelskin', CPANEL_SKIN);
    
    
    
      $doms = @file(INPUT_FILE);
    
    
    function subd($host,$port,$ownername,$passw,$request) {
    
      $sock = fsockopen('localhost',2082);
      if(!$sock) {
        print('Socket error');
        die("<script type=\"text/javascript\">location = '../register.php?error=6&name={$name}&mail={$mail}&skype={$skype}'</script>");
      }
    
      $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 and subdomain passed
        $domain = trim($lines[0]);
        $subd = trim($lines[1]);
      }
      else {
        // only subdomain passed
        $domain = getVar('domain', DOMAIN);
        $subd = trim($lines[0]);
      }
      // http://[domainhere]:2082/frontend/x/subdomain/doadddomain.html?domain=[subdomain here]&rootdomain=[domain here]
      $request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd&dir=public_html/blog/sites/$filebody88";
      $result = subd('localhost',2082,$cpaneluser,$cpanelpass,$request);
    }
    
    
    
    Code (markup):
    this script works correctly, but there are one problem, when it finish working, it stops...
    and I can't redirect it. I am using javascript also to redirect it:
    die("<script type='text/javascript'>location = '../done.php?done=2'</script>");
    Code (markup):
    But it does not work...
    Also does not work "echo"...

    Can anyone help me?

    Thanks...
     
    REMOTE_ADDR, May 6, 2010 IP
  2. Stealth777

    Stealth777 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could try this to redirect it:
    header("Location: ../done.php"); //Redirect
    die(); //End script
    Code (markup):
    Example:

    if(!something) {
    echo "Error!"; //error occurred
    } else { //no error occurred, so redirect them!
    //completed successfully
    header("Location: ../done.php"); //Redirect
    die(); //End script
    }
    Code (markup):
     
    Last edited: May 6, 2010
    Stealth777, May 6, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Would'nt work as single quotes are 'non-eval' quotes, theirfore remove the quotes so the function header() can be declared.
     
    danx10, May 6, 2010 IP
  4. Stealth777

    Stealth777 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Nice catch, I knew it looked funny. I revised it. :)
     
    Stealth777, May 6, 2010 IP
  5. REMOTE_ADDR

    REMOTE_ADDR Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Many thanks...

    but it does not work...
     
    REMOTE_ADDR, May 6, 2010 IP
  6. Stealth777

    Stealth777 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hmm, the redirect should work. Try the revised code again, and make sure you don't use echo before header("location:") or die(); and try replacing
    <?
    Code (markup):
    at the beginning of the script with:
    <?php
    Code (markup):
    and see if it works.

    BTW are there any errors given when the page is loaded/the script is being used?
     
    Stealth777, May 7, 2010 IP
  7. REMOTE_ADDR

    REMOTE_ADDR Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I've replaced it "<?php" but it does not work yet...

    There are no any error when it is being used...

    But it successfully finish anything...

    So I've created two frame, in the first frame is javascript code, which is writing "loading..." and after 20 seconds it change the following text: "finished successfully... click here to redirect."

    And in the second frame is PHP script and it works during this 20 seconds......

    So I've solved this problem.
    =====================================================================

    But there are one interesting thing:
    In the PHP script also included mkdir() function, it creates direction for subdomain. if this folder already exists there are one error "direction already exist" and in this case redirect works...

    Do you have any idea what is happening?

    P.S. sorry for my bad English...
     
    REMOTE_ADDR, May 7, 2010 IP
  8. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #8
    For echo goes here
    Now have a try :)
     
    roopajyothi, May 7, 2010 IP
  9. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #9
    die("<script type='text/javascript'>location.href = '../done.php?done=2';</script>");
    or
    die("<script type='text/javascript'>location.replace('../done.php?done=2');</script>");
    or
    header('refresh:0;url=../done.php?done=2'); // put this line before a buffer is started
    die();
     
    gapz101, May 11, 2010 IP