Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    419
    Thanks
    18
    Thanked 26 Times in 26 Posts

    Exclamation Unexpected end of file

    I have no idea where this error is coming from. I've checked every bracket and parenthesis that I could and anything else that could be a problem. I even checked it on an online syntax checker but no errors showed up.

    Also, there's a line of code that doesn't work on windows. I want it to clear the command prompt but it doesn't

    PHP Code:
    passthru('cls'); 
    PHP Code:
    <?php
    if(commandLine())
    {
        
    $loop true;
        
    set_time_limit(0);
    }
    else
    {
        
    $ip = (key_exists('HTTP_X_FORWARDED_FOR'$_SERVER) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
        
    define("ADMIN", ($ip == /* Removed for security reasons */ || $ip == '::1'));
        
    set_time_limit(300);
    }

    $loadTextList false;

    require 
    '../Includes/Database.class.php';
    $sql Database::getInstance();
    $rows getIDs();

    $IDs = array();

    $sites = array(
        
    //Removed for security reasons
    );
    if(
    $loadTextList)
    {
        
    $list file_get_contents('list.txt');
        
    $list explode("\r\n"$list);
        foreach(
    $list as $str)
        {
            
    $sites[] = '~'.$str;
        }
    }
    if(
    commandLine())
        echo 
    "Running site list, please wait...\n\n";
    foreach(
    $sites as $site)
    {
        
    //Loop through once to try and get the ID's closer together
        
    get($site);
    }
    if(
    commandLine())
    {
      do
      {
        
    $count = array(
            
    'total' => count($rows),
            
    'checked' => 0,
            
    'added' => 0,
            
    'exists' => 0,
            
    'skipped' => 0,
        );
        foreach(
    $sites as $site)
        {
            
    $status false;
            echo 
    "--------------------------------------------------\n";
            echo 
    "Checking $site...\n";
            for(
    $i 1$i <= && $status != true$i++)
            {
                echo 
    "[Attempt $i/5] - ";
                if(
    $site{0} == '~')
                    
    $str substr($site1);
                else
                    
    $str get($site);
                if(
    strpos($site/* Removed for security reasons */) > -1)
                {
                    
    #Special stripping for ***
                    
    if(strpos($str'<script type="text/javascript">enableOverride();</script>') > -1)
                        
    $str strbet($str.'</end>''<script type="text/javascript">enableOverride();</script>''</end>');
                    else
                        
    $str '';
                }
                
    $str trim(strip_tags($str));
                
    parse_str($str$id);
                foreach(
    $id as $k => $v)
                {
                    
    $id[$k] = trim(strip_tags($v));
                }
                
    #Check the ID and display results
                
    if(!checkID($id))
                {
                    
    #Not a valid ID
                    
    echo "ID not valid, ";
                    if(
    $i 5)
                        echo 
    "trying again...\n";
                    else
                    {
                        
    $count['skipped']++;
                        echo 
    "moving to next site...\n";
                    }
                }
                elseif(
    count($id) != || $id['somekey3'] == 0)
                {
                    
    #Error getting data
                    
    echo "Error getting data, ";
                    if(
    $i 5)
                        echo 
    "trying again...\n";
                    else
                    {
                        
    $count['skipped']++;
                        echo 
    "moving to next site...\n";
                    }
                }
                elseif(
    key_exists($id['id'], $rows))
                {
                    
    #ID exists
                    
    $status true;
                    
    $count['exists']++;
                    echo 
    "$id[id] Already exists, skipping site...\n";
                }
                else
                {
                    
    #Added
                    
    $sql->insert('userids'$id);
                    
    $status true;
                    
    $count['added']++;
                    echo 
    "$id[id] added! Moving to next site...\n";
                }
            }
            echo 
    "--------------------------------------------------\n\n";
            
    $count['checked']++;
        }
        echo 
    "Finished!\n\n";
        echo 
    "Total ID's added: $count[added]\n";
        echo 
    "Total ID's already added: $count[exists]\n";
        echo 
    "Total sites skipped: $count[skipped]\n";
        echo 
    "Total sites checked: $count[checked]\n";
        echo 
    "Total ID's: $count[total]\n";
        if(
    $loop)
        {
            echo 
    "Looping in 60 seconds...";
            
    sleep(60);
            
    passthru('cls');//Doesn't work (windows), would be nice to get this fixed too
            
    unset($rows);
            
    $rows getIDs();
        }
      }
      while(
    $loop);
    }
    else
    {
        
    $count = array(
            
    'total' => count($rows),
            
    'checked' => 0,
            
    'added' => 0,
            
    'exists' => 0,
            
    'skipped' => 0,
        );
        foreach(
    $sites as $site)
        {
            if(
    $site{0} == '~')
                
    $str substr($site1);
            else
                
    $str get($site);
            if(
    strpos($site/* Removed for security reasons */) > -1)
            {
                
    #Special stripping for ***
                
    $str strbet($str.'</end>''<script type="text/javascript">enableOverride();</script>''</end>');
            }
            
    $str trim(strip_tags($str));
            
    parse_str($str$id);
            foreach(
    $id as $k => $v)
            {
                
    $id[$k] = trim(strip_tags($v));
            }
            
    $IDs[$site] = $id;
        }
        foreach(
    $IDs as $site => $arr)
        {
            
    #Check validity of the link before saving it
            
    if(!checkID($arr))
            {
                
    $IDS[$site]['status'] = 1;
                
    $count['skipped']++;
            }
            elseif(
    count($arr) != || $arr['somekey3'] == 0)
            {
                
    $IDs[$site]['status'] = 0;
                
    $count['skipped']++;
            }
            elseif(!
    key_exists($arr['id'], $rows))
            {
                
    $IDs[$site]['status'] = 3;
                
    $sql->insert('userids'$arr);
                
    $count['added']++;
                
    $count['total']++;
            }
            else
            {
                
    $count['exists']++;
                
    $IDs[$site]['status'] = 2;
            }
        }
    ?>
    <center><button onClick="javascript:location.reload(true);">Refresh</button><br />
    <b><i><?echo count($sites);?> total sites visited.</i></b><br />
    <b><i><?echo $count['total'];?> total ID's logged.</i></b><br />
    <table>
    <?
        
    foreach($IDs as $site => $arr)
        {
            if(
    strpos($site/* Removed for security reasons */) > -1)
            {
                
    $url explode('encoded'$site);
                
    $url $url[0].'...';
            }
            else
            {
                
    $url explode('?'$site);
                
    $url $url[0];
            }
    ?>
    <tr>
        <td><b><font color="blue" /><?if(ADMIN) echo $url; else echo '*Site Hidden*';?>: </font></b></td>
    <?
            
    switch($arr['status'])
            {
                case 
    0:
                    echo 
    '    <td><font color="orange">Error getting data, somekey3 is probably 0.</font></td>';
                break;
                case 
    1:
                    echo 
    '    <td><font color="yellow">ID is not valid!.</font></td>';
                break;
                case 
    2:
                    echo 
    '    <td><font color="red">'.$arr['id'].' already exists!</font></td>';
                break;
                case 
    3:
                    echo 
    '    <td><font color="green">'.$arr['id'].' added to database!</font></td>';
                break;
            }
    ?>
    </tr>
    <?
        
    }
    ?>
    </table>
    <?
    }
    function 
    commandLine()
    {
        return (
    php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']));
    }
    function 
    getIDs()
    {
        global 
    $sql;
        
    $rows $sql->select('id''userids'nullnullnulltruetrue);
        foreach(
    $rows as $i => $arr)
        {
            
    $ids[$arr['id']] = $arr;
        }
        return 
    $ids;
    }
    function 
    checkID($arr)
    {
        
    /* Function hidden for security reasons */
        //Checks if the ID is valid to use
        //Returns boolean
    }
    function 
    get($url$includeHeaders false)
    {
        return @
    file_get_contents($url);
        
    $urlp parse_url($url);
        
    $fp fsockopen($urlp['host'], 80);
        
    $path explode('/'$url4);
        
    $cp count($path);
        
    $path = ($cp >= 4) ? $path[3] : "";
        
    $req "GET /$path HTTP/1.0\r\n";
        
    $req .= "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
        
    $req .= "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
        
    $req .= "Host: $urlp[host]\r\n";
        
    $req .= "Accept-Language: en-us,en;q=0.5\r\n";
        
    $req .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0\r\n";
        
    $req .= "Connection: close\r\n\r\n";
        
    fputs($fp$req);
        
    stream_set_timeout($fp,4);
        
    $res stream_get_contents($fp);
        
    fclose($fp);
        if(
    $includeHeaders)
            return 
    $res;
        
    $res explode("\r\n\r\n"$res2);
        return 
    $res[1];
    }
    function 
    strbet($inputstr$deliLeft$deliRight)
    {
        
    $posLeft strpos($inputstr$deliLeft) + strlen($deliLeft);
        
    $posRight strpos($inputstr$deliRight$posLeft);
        return 
    substr($inputstr$posLeft$posRight $posLeft);
    }
    ?>
    Last edited by Dubz; 11-10-2012 at 09:17 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,331
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    Have you tried commenting out your passthru() line?

    Also we came across a similar tale like this a long time ago and it was the included file that was at fault. Be sure to check that database file too.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    419
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Quote Originally Posted by tangoforce View Post
    Have you tried commenting out your passthru() line?

    Also we came across a similar tale like this a long time ago and it was the included file that was at fault. Be sure to check that database file too.
    The passthru function doesn't return any errors or problems when ran, it just doesn't clear the command prompt as wanted. As for the database file, it is used for other parts of a website panel so I know it's working fine (haven't come across any errors on the site's end). I'll check it again but I'm almost positive it's not the issue.

    Edit:
    I checked the database file and it's working fine, I even checked the main file and it still did not show any sign of a misplaced bracket or any type of thing that could throw it off. As for the error message, I forgot to include it so here it is:

    Parse error: syntax error, unexpected end of file in *file* on line 310 (last line, the '?>')
    Last edited by Dubz; 11-11-2012 at 06:12 AM.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,331
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    Quote Originally Posted by Dubz View Post
    The passthru function doesn't return any errors or problems when ran, it just doesn't clear the command prompt as wanted.
    But that isn't what I asked you. Unless you're going to try things we ask, how can we help you? I know what its supposed to do but sometimes quirky things happen.

    Please edit out the line with comment marks and try again.

    Failing that, you may want to try reencoding the file as ascii or ansii as the file encoding may be screwy. Thats just a guess but its solved a few odd problems for me in the past. You could just copy the text into another file and overwrite the existing file when saving.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,058
    Thanks
    10
    Thanked 96 Times in 94 Posts
    does your cli php.ini allow short open tags ? '<?' , if not change it to allow , else use full tags '<?php' , on some systems the cli uses a different php.ini than apache (at least on linux it does)

    Edit:
    this is a guess by the way but that error message can be associated with short tags?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    Dubz (11-12-2012)

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by firepages View Post
    does your cli php.ini allow short open tags ? '<?' , if not change it to allow , else use full tags '<?php' , on some systems the cli uses a different php.ini than apache (at least on linux it does)

    Edit:
    this is a guess by the way but that error message can be associated with short tags?
    This is a good call right here. Pulling a lint check with short_open_tag disabled pulls syntactical error, whilst pulling a lint and enabling short_open_tag checks out.
    Simply ensure that <?php is used and not <?.

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    419
    Thanks
    18
    Thanked 26 Times in 26 Posts
    I didn't mean for it to sound like I know that it wasn't the problem, even though disabling it didn't change anything, but I had it in the code before and it never had any issues. I don't even know what happened to the script I just run it and it worked fine before but then it just stopped working out of nowhere. I tried copying the data and putting it into a new file but still had no luck.

    As for the '<?' and '<?php' tags, I've never had any problems with them. I use both tags in almost every php script I make (starting with '<?php' at the top) and never had any problems with it before and still don't have any with it.

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,331
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    Yes but as mentioned, have you enabled short tags for cli? - in other words console mode
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #9
    Regular Coder
    Join Date
    Sep 2011
    Posts
    419
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Quote Originally Posted by tangoforce View Post
    Yes but as mentioned, have you enabled short tags for cli? - in other words console mode
    Yes, I've ran multiple scripts before using short tags in the command line and haven't had any issues with them.

    Edit:
    I checked the php.ini and it said that they were disabled, which I don't understand as to why I never had this problem with any of my other scripts that I've ran. I'm testing it now with it enabled (after apache restarts) and I'll post the results.

    Edit:
    It's working now. I'm still confused as to why I haven't come across this error before. Either way, I'm glad I can get this up and running again, it was annoying to not be able to use.
    Last edited by Dubz; 11-12-2012 at 02:57 AM.

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,331
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    While I was on the wrong track previously it just goes to show that thinking something is 'ok' doesn't always mean it is and it's often wise to review your settings when people suggest it. I had wondered about short tags but never realised there was a different setting for cli short tags hence I never put it foward as I also ruled out the idea of it. Just goes to show again that you can think something is good and still be wrong!

    Anyway, gad you've got it sorted and stop using short tags! You'll live to regret it in the future (trust me, I used them all over the place and one day it bit me in the rear when I needed to use php in xml files).
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #11
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,058
    Thanks
    10
    Thanked 96 Times in 94 Posts
    Quote Originally Posted by tangoforce View Post
    ....Anyway, gad you've got it sorted and stop using short tags! You'll live to regret it in the future (trust me, I used them all over the place and one day it bit me in the rear when I needed to use php in xml files).

    I am bad, I still use them... though normally I have control over the environment , think I am still kind of miffed that XML stole them and just being stubborn
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,331
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    Quote Originally Posted by firepages View Post
    I am bad, I still use them... though normally I have control over the environment , think I am still kind of miffed that XML stole them and just being stubborn
    I don't have a problem with xml using short tags but what does annoy me is that php in all its wisdom doesn't check the xml short tag and notice that it says xml right after it You'd think a bunch of guys who can write a language like php would think of that
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    It would be easy to modify the parser to ignore it. But in the same breath, <?phpvalue is also illegal. Languages shouldn't be hardcoding information in order to accommodate another language.

    The CLI without an override will perform a check in order of the default paths for the php.ini:
    Code:
    SAPI directory
    PHPRC global (after 5.2; otherwise this goes after registry key on windows)
    HKLM\Software\PHP\x.y.z
    HKLM\Software\PHP\x.y
    HKLM\Software\PHP\x
    HKLM\Software\PHP
    CLI CWD
    Web Server Directory
    PHP Directory
    %PATH%
    So it will check a number of locations before giving up. Unfortunately, it will grab the *first* php.ini it finds, so if you use a custom php.ini specified in the webserver configurations, it will not necessarily match what the cli will find. You can force it by adding the -c or --php-ini directive to the cli options, as well as -n or --no-php-ini to use the hard coded defaults.

    On the cli, you can determine which php.ini it plans on using by executing a simple php.exe --ini which will include a loaded configuration file directive.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •