windows to openbsd transition has caused script to not work
Posted: Thu Mar 15, 2007 9:04 pm
Hello,
I recently wrote a php script to parse an external xml file, and organise its content into news posts, "archiving" older posts by putting them on separate pages. You can see how this works by visiting my website, http://petergeoghegan.com. This is my first real php script. The code is as follows:
This works fine on my windows 2003/iis server, but I can't seem to get it to work properly on my Open BSD server. The first headline of the home page will print, but nothing any further down then that. I'm using the version of php that is available as an Open BSD package. In keeping with Open BSD's ethos, this version of php has a non-standard php.ini file that restricts various things in the interest of security, which is the cause of the problem, I suspect. I imagine it would take me a long time to isolate this cause any further, so I'd appreciate it if someone pointed me in the right direction,
Regards,
Peter Geoghegan
I recently wrote a php script to parse an external xml file, and organise its content into news posts, "archiving" older posts by putting them on separate pages. You can see how this works by visiting my website, http://petergeoghegan.com. This is my first real php script. The code is as follows:
Code: Select all
<?PHP
$news = fopen("news.xml", "rb");
$usable = fread($news,4096);
fclose($news);
$parser = xml_parser_create('UTF-8');
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $usable, $vals, $index);
xml_parser_free($parser);
// change this variable, "$postsperpage" , to adjust the number of posts you'd like to see per page
$postsperpage = 5;
//first, to determine the total number of posts and pages in the xml file/mirrored array
$numberofposts = count($index[TITLE]);
if ($numberofposts > $postsperpage){
$numberofpagesflat = round($numberofposts / $postsperpage );}
else{
$numberofpagesflat = 1;}
$belessthen = $numberofposts / $postsperpage;
if ($numberofpagesflat < $belessthen){
// above if is evaluated as true, even if it shouldn't. Why?
$numberofpagesflat ++;}
//news item printing loop
if (empty($_GET["post"]) or $_GET["post"] > $numberofpagesflat)
$newsitem = $postsperpage;
else
$newsitem = $_GET["post"] * $postsperpage;
for ($increment = $newsitem - $postsperpage; $increment < $newsitem and $increment < $numberofposts; $increment++)
{
echo "<p><big>{$vals[$index[TITLE][$increment]][value]}</big></p>\n";
echo "<p><date>{$vals[$index[DATEPOSTEDBY][$increment]][value]}</date></p>\n";
// use incrementation to mark all relevant arrays for printing as part of the body tag, then print them.
$bodyincrement = $increment * 2;
$start = $index[BODY][$bodyincrement];
$end = $index[BODY][$bodyincrement + 1];
//While loop prints all body segment arrays together
while ( $start <= $end){
if ($vals[$start][type] == "open" and empty($vals[$start][attributes][HREF])){
echo '<';
echo mb_strtolower($vals[$start][tag]);
echo '>';
echo $vals[$start][value];
}
elseif ($vals[$start][type] == "close" ){
echo $vals[$start][value];
echo '</';
echo mb_strtolower($vals[$start][tag]);
echo '>';}
elseif ($vals[$start][type] == "cdata"){
echo $vals[$start][value];}
elseif ($vals[$start][type] == "complete" and empty($vals[$start][attributes]))
{
echo '<';
echo mb_strtolower($vals[$start][tag]);
echo '>';
echo $vals[$start][value];
echo '</';
echo mb_strtolower($vals[$start][tag]);
echo '>';
}
elseif($vals[$start][type] == "complete" and !empty($vals[$start][attributes][HREF])){
echo '<';
echo mb_strtolower($vals[$start][tag]);
echo ' href="';
echo $vals[$start][attributes][HREF];
echo '">';
echo $vals[$start][value];
echo '</';
echo mb_strtolower($vals[$start][tag]);
echo '>';
}
elseif($vals[$start][type] == "open" and !empty($vals[$start][attributes][HREF])){
echo '<';
echo mb_strtolower($vals[$start][tag]);
echo ' href="';
echo $vals[$start][attributes][HREF];
echo '">';
}
elseif($vals[$start][type] == "complete" and $vals[$start][tag] == "IMG"){
echo '<';
echo mb_strtolower($vals[$start][tag]);
echo ' src="';
echo $vals[$start][attributes][SRC];
echo '" alt="';
echo $vals[$start][attributes][ALT];
echo '"/>';
}
else
{
echo $vals[$start][value];}
$start ++;
}
if ($increment < ($newsitem -1) and $increment < ($numberofposts - 1 )){
$psuedorandom = rand(1, 3);
echo '<p align="center"><img src="images/seperator';
echo $psuedorandom;
echo '.png" alt="*" align="middle"/></p>';
}}
//news archive printing loop
if ($numberofposts > $postsperpage){
echo "<p>News archive: ";
$switch = 0;
for ($tracker = 1; $tracker <= $numberofpagesflat; $tracker++)
{
// this first if isn't relevant, so long you opt not to have an archive bit built at all by using a master if statement. it is left here in case you change your mind
if ($numberofposts <= $postsperpage){
echo "1 ";
$tracker = $numberofpagesflat;
}
elseif ($_GET["post"] == $tracker){
echo "$tracker ";
}
elseif (empty($_GET["post"]) and $switch == 0)
{
echo "1 ";
$switch++;
}
else{
echo '<a href="?page=home&post=';
echo $tracker;
echo '">';
echo $tracker;
echo '</a> ';
}
}
echo "</p>";
}
?>Regards,
Peter Geoghegan