T_VARIABLE? What's wrong?

Discussion in 'PHP' started by PK-Host, May 11, 2012.

  1. #1
    This may be a really obvious things but I've spent ages staring at it maybe just needs a new pair of eyes.
    <?php
    function license_check($url, $curl_data){
        $options["CURLOPT_RETURNTRANSFER"] = false;    $options["CURLOPT_HEADER"] = false;    $options["CURLOPT_CONNECTTIMEOUT"] = 10;    $options["CURLOPT_TIMEOUT"] = 10;    $options["CURLOPT_POST"] = 1;    $options["CURLOPT_POSTFIELDS"] = $curl_data;
        $ch = curl_init($url);    curl_setopt_array($ch, $options);    $content = curl_exec($ch);    curl_close($ch);    return $content;}
    $license_key = "";$post_fields = array("key" => $license_key, "registered_domain" => $_SERVER['SERVER_NAME'], "registered_ip" => $_SERVER['SERVER_ADDR'], "registered_directory" => dirname(__FILE__));$license = license_check("http://www.url-to-your-website.com/license.php", $post_fields);$xml = simplexml_load_string($license);
    foreach($xml->attributes() as $key => $value) {    $key = $value;}if($status == "Invalid"){    die($reason);}
    unset($post_fields, $license, $xml, $status, $reason, $license_key, $registered_ip, $registered_domain, $registered_directory);
    ?>
    PHP:
    I get the error

    Parse error: syntax error, unexpected T_VARIABLE in /home/USERNAME/public_html/testing/license_tutorial/index.php on line 6
    PHP:
    Any ideas?

    P.S. sorry abotu formatting digitalpoint seems to screw it up.
     
    Solved! View solution.
    PK-Host, May 11, 2012 IP
  2. e-abi

    e-abi Member

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    38
    #2
    <?php
    
    function license_check($url, $curl_data) {
        $options["CURLOPT_RETURNTRANSFER"] = false;
        $options["CURLOPT_HEADER"] = false;
        $options["CURLOPT_CONNECTTIMEOUT"] = 10;
        $options["CURLOPT_TIMEOUT"] = 10;
        $options["CURLOPT_POST"] = 1;
        $options["CURLOPT_POSTFIELDS"] = $curl_data;
        $ch = curl_init($url);
        curl_setopt_array($ch, $options);
        $content = curl_exec($ch);
        curl_close($ch);
        return $content;
    }
    
    $license_key = "";
    $post_fields = array("key" => $license_key, "registered_domain" => $_SERVER['SERVER_NAME'], "registered_ip" => $_SERVER['SERVER_ADDR'], "registered_directory" => dirname(__FILE__));
    $license = license_check("http://www.url-to-your-website.com/license.php", $post_fields);
    $xml = simplexml_load_string($license);
    foreach ($xml->attributes() as $key => $value) {
        $key = $value;
    }if ($status == "Invalid") {
        die($reason);
    }
    unset($post_fields, $license, $xml, $status, $reason, $license_key, $registered_ip, $registered_domain, $registered_directory);
    ?>
    
    PHP:

    Code looks fine, no errors...
     
    e-abi, May 11, 2012 IP
  3. #3
    Use Netbeans or Eclipse PDT, it shows the php errors immediately.
     
    e-abi, May 11, 2012 IP
  4. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #4
    I figured out what was causing the problem just not 100% sure how to stop it happening again. Basically I copied my tutorial into my php file to check it worked and using Netbeans you can see some invalid characters were entered into the TABS/Indents. These only shown up using Netbeans
     
    PK-Host, May 14, 2012 IP
  5. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #5
    also to mention notepad++ has a great colour-coordinated error handling feature too!




    ROOFIS
     
    ROOFIS, May 15, 2012 IP
  6. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #6
    I do use Notepad++ however the only program to show up the invalid characters was Netbeans. Even notepad didnt show them.
     
    PK-Host, May 15, 2012 IP
  7. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #7
    You need to learn to writer cleaner code. Then when you debug the exact line # will be stated giving you an exact reason for failure.
     
    NetStar, May 20, 2012 IP
  8. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #8
    That would not have made any difference as the PHP engine reports an error at different lines to what actually had the errors on. And writing cleaner code would not have stopped this problem. This was because it was copied from a ANSI web page. Which included some invalid characters.
     
    PK-Host, May 20, 2012 IP
  9. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #9
    Actually writing clean code using proper formatting and indentation allows for your code to be readable by the human eye. And the debugger will report the line number where the error is on or near. If you follow traditional programming practices a semi-colon should indicate the LAST character of code on that current line. Trust me..writing clean code makes it very easy to spot errors.
     
    NetStar, May 20, 2012 IP