Development PHP error - Its probably an obvious one.

Discussion in 'Software' started by exile, 13 May 2004.

  1. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    When I call the function below i get this error:

    Parse error: parse error, expecting `')'' in /home/wrjou27/public_html/testing/cpanel.php on line 2

    Fatal error: Call to undefined function: addemail() in /home/wrjou27/public_html/testing/svc_emailreg.php on line 398



    PHP:
    <?
    Function 
    AddEmail (emailpasswordquota){

        
    $fp fsockopen("www.wrjournal.net"2082$errno$errstr30);
        if (!
    $fp) {
           echo 
    "$errstr ($errno)<br />\n";
        } else {
           
    $out "GET /frontend/Xskin/mail/doaddpop.html?email=" $email "&domain=wrjournal.net&password=" $password "&quota=" $quota " HTTP/1.0\r\n";
           
    $out .= "Authorization: Basic " base64_encode ($CPANELUSER:$CPANELPASS) & "\r\n";
           
    $out .= "Connection: Close\r\n\r\n";
        
           
    fputs($fp$out);
           while (!
    feof($fp)) {
               
    fgets($fp128);
           }
           
    fclose($fp);
        }


    ?>
     
  2. ellism

    ellism What's a Dremel?

    Joined:
    10 Sep 2003
    Posts:
    348
    Likes Received:
    0
    is email, password, quota strings if so they need to be included in ' ' if they are variables they need a $ prefix.
     
  3. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    what ellism said :)
     
  4. ellism

    ellism What's a Dremel?

    Joined:
    10 Sep 2003
    Posts:
    348
    Likes Received:
    0
    i got somthing right, only started using PHP a week ago.
     
  5. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    hmm.. Okie Dokie. Ill look into that asap. Its been a while since i last coded php. I thought i didnt need the $ for the variables in the function.

    :wallbash: i should have just checked that anyway:wallbash:
     
  6. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    I didnt think that was the problem. When i do that i get:

    Parse error: parse error in /home/wrjou27/public_html/testing/cpanel.php on line 9

    Fatal error: Call to undefined function: addemail() in /home/wrjou27/public_html/testing/svc_emailreg.php on line 398

    Maby you could look at the error then at the code, find a problem...

    (sry if you find me rude, im just a bit anoyed with this.)

    Are any of you really good with php?
     
  7. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    You also missed out an extra curly brace which would finish the definition of the function :)
     
  8. mookie

    mookie very nawty<br><img src="http://mookie.org/i/avatar

    Joined:
    30 Jun 2002
    Posts:
    639
    Likes Received:
    1
    Also, you may want to make sure you call AddEmail() and not addemail() :thumb:
     
  9. Jamie

    Jamie ex-Bit-Tech code junkie

    Joined:
    12 Mar 2001
    Posts:
    8,180
    Likes Received:
    54
    or addEmail in java ..... but it's not .... so I'll shut up :D
     
  10. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    Umm... ya well, you dont CALL in php. If you think you do, please explain more. Even with the } I still get an error. Prahaps someone who knows what there doing could study it?
    PHP:
    <? 
    Function 
    AddEmail ($email$password$quota){ 

        
    $fp fsockopen("www.wrjournal.net"2082$errno$errstr30); 
        if (!
    $fp) { 
           echo 
    "$errstr ($errno)<br />\n"
        } else { 
           
    $out "GET /frontend/Xskin/mail/doaddpop.html?email=" $email "&domain=wrjournal.net&password=" $password "&quota=" $quota " HTTP/1.0\r\n"
           
    $out .= "Authorization: Basic " base64_encode ($CPANELUSER:$CPANELPASS) & "\r\n"
           
    $out .= "Connection: Close\r\n\r\n"
         
           
    fputs($fp$out); 
           while (!
    feof($fp)) { 
               
    fgets($fp128); 
           } 
           
    fclose($fp); 
        } 
    }

    ?> 
     
  11. OneSeventeen

    OneSeventeen Oooh Shiny!

    Joined:
    3 Apr 2002
    Posts:
    3,454
    Likes Received:
    2
    I would replace "&" with "." and possibly a "\r\n" before the HTTP/1.0?
    Oh, and change base64_encode($var:$var) to base64_encode($var . ":" . $var)
    Code:
    <?php
    Function AddEmail ($email, $password, $quota){ 
        $fp = fsockopen("www.wrjournal.net", 2082, $errno, $errstr, 30); 
        if (!$fp) { 
           echo "$errstr ($errno)<br />\n"; 
        } else { 
           $out = "GET /frontend/Xskin/mail/doaddpop.html?email=" . $email . "&domain=wrjournal.net&password=" . $password . "&quota=" . $quota . "\r\nHTTP/1.0\r\n"; 
           $out .= "Authorization: Basic " . base64_encode ($CPANELUSER . ":" . $CPANELPASS) . "\r\n"; 
           $out .= "Connection: Close\r\n\r\n"; 
          
           fputs($fp, $out); 
           while (!feof($fp)) { 
               fgets($fp, 128); 
           } 
           fclose($fp); 
        } 
    } 
    
    ?>
    I'm not as familiar with all of the fsockopen stuff as I want to be, but the only thing I noticed is the use of "&" to concantenate strings. I could be very wrong in this, but if I were to write:
    <?php echo "this" & " this"; ?>
    it would echo out:
    `ha
    And the $out string would have looked similar to:
    Code:
    "GET /frontend/Xskin/mail/doaddpop.html?email=username&domain=wrjournal.net&password=pass&quota=1234 HTTP/1.0
    Authorization: Basic {base64 not processed}
    Connection: Close
    
    ";
    which makes me think the value of $_GET['quota'] might be "1234 HTTP/1.0" but once again, I don't know much about fsockopen.

    The new way should make it look more like:
    Code:
    "GET /frontend/Xskin/mail/doaddpop.html?email=username&domain=wrjournal.net&password=password&quota=1234
    HTTP/1.0
    Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
    Connection: Close
    
    ";
    (and if you base64_Decode(dXNlcm5hbWU6cGFzc3dvcmQ=) you would get "username:password")

    Not sure if this helps any, but my script would just stop running at the base64_encode, and would give garbled data once I fixed that because of "&".

    Oh, and all this asking for help and not really knowing what your doing but trying anyway, is exactly how I learned PHP, so keep up the good work! (not having any errors is a sign of not trying :p)
     
  12. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    well, thats a lot to read. but, i know all my HTTP prot code is correct, iv tested that all, then put it in the location i needed, then added vars. so i know, i dont have to change any.

    But, as you pointed out the & is probably a big problem. I havent coded php in a while. Im used to the & forgot i should use . :wallbash: , ill try that. thx :thumb:
     
  13. exile

    exile What's a Dremel?

    Joined:
    8 Mar 2004
    Posts:
    46
    Likes Received:
    0
    Thx OneSeventeen!
    Final Code:
    PHP:
    <?
    Function 
    AddEmail ($email$password$quota){

        
    $fp fsockopen("www.wrjournal.net"2082$errno$errstr30);
        if (!
    $fp) {
           echo 
    "$errstr ($errno)<br />\n";
        } else {
           
    $out "GET /frontend/Xskin/mail/doaddpop.html?email=$email&domain=wrjournal.net&password=$password&quota=$quota HTTP/1.0\r\n";
          
    $out .= "Authorization: Basic " base64_encode ($CPANELUSER ":" $CPANELPASS) . "\r\n"
           
    $out .= "Connection: Close\r\n\r\n";
        
           
    fputs($fp$out);
           while (!
    feof($fp)) {
               
    fgets($fp128);
           }
           
    fclose($fp);
        }
    }

    ?>
     

Share This Page