...

View Full Version : Unexpected end of file



Dubz
11-10-2012, 09:09 PM
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



passthru('cls');




<?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 <= 5 && $status != true; $i++)
{
echo "[Attempt $i/5] - ";
if($site{0} == '~')
$str = substr($site, 1);
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) != 3 || $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($site, 1);
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) != 3 || $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', null, null, null, true, true);
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('/', $url, 4);
$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", $res, 2);
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);
}
?>

tangoforce
11-10-2012, 10:21 PM
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.

Dubz
11-11-2012, 06:04 AM
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.


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 '?>')

tangoforce
11-11-2012, 01:08 PM
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.

firepages
11-11-2012, 01:38 PM
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)


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

Fou-Lu
11-11-2012, 04:20 PM
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)


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 <?.

Dubz
11-12-2012, 02:20 AM
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.

tangoforce
11-12-2012, 02:43 AM
Yes but as mentioned, have you enabled short tags for cli? - in other words console mode

Dubz
11-12-2012, 02:52 AM
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.


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.


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.

tangoforce
11-12-2012, 04:26 AM
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).

firepages
11-12-2012, 04:46 AM
....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 ;)

tangoforce
11-12-2012, 04:58 AM
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 :eek: You'd think a bunch of guys who can write a language like php would think of that :rolleyes:

Fou-Lu
11-12-2012, 05:16 PM
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:


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum