Parse error: syntax error, unexpected ';', expecting T_CATCH

Discussion in 'PHP' started by mark103, Sep 23, 2010.

  1. #1
    Hi guys,

    I have a problem with the script. There is a parse error in line 7 which it end of the line. I need your help to make them get correct, as I am not a programmer and know very little PHP.


    Here it is the code:


    <?php
    
    try
    {
        include_once('HideUrlConfig.php');
    }
    ?>
    
    PHP:

    Parse error: syntax error, unexpected $end, expecting T_CATCH in /home/username/public_html/mysite.com/myscript.php on line 6


    What do I needs to change it with?
     
    mark103, Sep 23, 2010 IP
  2. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    <?php
    
    try
    {
        include_once('HideUrlConfig.php');
    }catch(Exception $E){}
    ?>
    PHP:
    You need add exception
     
    guardian999, Sep 23, 2010 IP
  3. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks guardian999, so I want to add the error message in the catch exception that if the server is gone down?

    I want to add the error message which something is like "the server is down at the moment, please try again later"


    Thanks,
    Mark
     
    mark103, Sep 23, 2010 IP
  4. Internet Monk

    Internet Monk Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    try {
    
        include_once('HideUrlConfig.php');
        
    } catch (Exception $e) {
    
        echo "The server is down. Please try again later ..";
        
    }
    PHP:
     
    Internet Monk, Sep 23, 2010 IP
  5. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Thanks Internet Monk, so how could I get rid of the 404 not found that says in the webpage:


    I only wants to display the message by the catch expection:



    Here it is the source code:

    
    <?php
    try
    {
    $homepage = file_get_contents('http://www.myanothersite.com/script1.php');
    echo $homepage;
    }catch(Exception $E){}
        echo "The server is down. Please try again later ..";
    ?>
    
    PHP:
     
    mark103, Sep 23, 2010 IP
  6. Internet Monk

    Internet Monk Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    if ($homepage = @file_get_contents("http://www.domain.com")) {
    
        echo $homepage;
    
    } else {
    
        echo "The server is down. Please try again later ..";
    
    }
    PHP:
     
    Internet Monk, Sep 23, 2010 IP
  7. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #7
    Thanks, but it still showing the message like below...


    So I only want to display the message without "Not Found

    The requested URL /script1.php was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."


    Which I means that I only want to displaying the message:


    Here it is the update php that I am using:

    
    <?php
    if ($homepage = @file_get_contents("http://www.mysite.com/script1.php")) {
        echo $homepage;
    
    } else {
        echo "The server is down. Please try again later ..";
    }
    ?>
    
    PHP:

    Any idea?
     
    mark103, Sep 23, 2010 IP
  8. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #8
    Please can someone help?
     
    mark103, Sep 24, 2010 IP
  9. daljit

    daljit Well-Known Member

    Messages:
    312
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #9
    i dont sure this will work but some time i also have a problem like this. if your editor is not high lighted the syntax because of space between <?php ?> tags.So write the code like this
    <?php
    try
    {
    include_once('HideUrlConfig.php');
    }
    ?>
    i hope this will work for you
     
    daljit, Sep 24, 2010 IP
  10. sunlcik

    sunlcik Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Paste your HideUrlConfig.php code pls.
     
    sunlcik, Sep 24, 2010 IP
  11. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #11
    Use curl. It's a swiss-army-knife :p

    <?php
    if (!function_exists('curl_init')) {
    	echo 'Curl is not enabled.';
    	exit();
    }
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://localhost/test.php');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_TIMEOUT, 94);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 94);
    $res = curl_exec($ch);
    $info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    // HTTP Code checking
    if ($info == 200) {
    	echo 'Everything is fine.';
    	echo $res;// this is the URL content
    } else if ($info == 404) {
    	echo 'The server is down. Please try again later ..';
    } else {
    	echo 'The server has '.$info.' error. Please try again later ..';
    }
    ?>
    PHP:
     
    xrvel, Sep 26, 2010 IP