0

I have a little news widget that was working in PHP 5.2 but is not working in PHP 5.3. When you click on the the link for the showArticle.php the URL reflects the proper XML file name but it does not pass the first if statement on the showArticle.php file. Here is the code for the news widget:

<?php
if (PHP_VERSION>='5')
 require_once('domxml-php4-to-php5.php');
function extractText($array){
if(count($array) <= 1){
    //we only have one tag to process!
    for ($i = 0; $i<count($array); $i++){
        $node = $array[$i];
        $value = $node->get_content();
    }
    return $value;
} 

}   
?>
<?php
$dh = opendir('./xml/');

$fileCount = 0;
while ($file = readdir($dh) and $fileCount < 3){
if (eregi("^..?$", $file)) {
    continue;
}
$open = "./xml/".$file;
$xml = domxml_open_file($open);

//we need to pull out all the things from this file that we will need      
to 
//build our links
$root = $xml->root();
$stat_array = $root->get_elements_by_tagname("status");
$status = extractText($stat_array);

$ab_array = $root->get_elements_by_tagname("abstract");
$abstract = extractText($ab_array);

$h_array = $root->get_elements_by_tagname("headline");
$headline = extractText($h_array);

$img_array = $root->get_elements_by_tagname("image");
$image = extractText($img_array);

$lead_array = $root->get_elements_by_tagname("para-intro");
$para["intro"] = extractText($lead_array);

if ($status != "live"){
    continue;
}
echo "<div class=\"col-md-12 newsbox\"><img style=\"margin-bottom:  10px;\" width=\"100%\" src=\"images/news/".$image."\"><div class=\"newsboxtext\"><a href=\"http://paneilldesign.com/NDPsite/showArticle.php?file=".$file. "\"><h2 class=\"mainheadline2\"> ".$headline . "</h2></a><a href=\"showArticle.php?file=".$file . "\"><button  style=\"margin-top:5px;\" type=\"button\" class=\"btn btn-sm btn-default\">+ Read More</button></a></div><hr class=\"linedivider\">
</div>";




$fileCount++;
}
?>

This is the code for the showArticle.php

<?php session_start(); ?>
<?php
if (PHP_VERSION>='5')
 require_once('domxml-php4-to-php5.php');

function extractText($array){
   if(count($array) <= 1){
    //we only have one tag to process!
    for ($i = 0; $i<count($array); $i++){
        $node = $array[$i];
        $value = $node->get_content();
    }
    return $value;
    } 

 }  


 //pull in the XML file
if ($file == ""){

echo "<h2>You didn't choose a file to edit!</h2>";
echo "<a href=\"ndpnews.php\">Go back to index and choose a file</a>";
} else {

$open = "./xml/" . $file;
$xml = domxml_open_file($open);
$root = $xml->root();

$id = $root->get_attribute("id");

$h_array = $root->get_elements_by_tagname("headline");
$headline = extractText($h_array);

$stat_array = $root->get_elements_by_tagname("status");
$status = extractText($stat_array);


$a_array = $root->get_elements_by_tagname("author");
$author = extractText($a_array);

$e_array = $root->get_elements_by_tagname("email");
$email = extractText($e_array);

$ab_array = $root->get_elements_by_tagname("abstract");
$abstract = extractText($ab_array);

$kl_array = $root->get_elements_by_tagname("keywords");
$keywords = extractText($kl_array);

$img_array = $root->get_elements_by_tagname("image");
$image = extractText($img_array);

$lead_array = $root->get_elements_by_tagname("para-intro");
$para["intro"] = extractText($lead_array);

$second_array = $root->get_elements_by_tagname("para-main");
$para["main"] = extractText($second_array);

$con_array = $root->get_elements_by_tagname("para-conclusion");
$para["con"] = extractText($con_array);

$logo_array = $root->get_elements_by_tagname("logo");
$logo = extractText($logo_array);

$dt_array = $root->get_elements_by_tagname("dateandtime");
$dateandtime = extractText($dt_array);

    $wh_array = $root->get_elements_by_tagname("where");
$where = extractText($wh_array);

$ph_array = $root->get_elements_by_tagname("phone");
$phone = extractText($ph_array);

$web_array = $root->get_elements_by_tagname("website");
$website = extractText($web_array);

$map_array = $root->get_elements_by_tagname("map");
$map = extractText($map_array);

$pagetitle_array = $root->get_elements_by_tagname("pagetitle");
$pagetitle = extractText($pagetitle_array);


?>
tokked13
  • 3
  • 5
  • 1
    Do you mean it fails at `if ($file == "")`? My suspicion here is that your old PHP 5.2 had [register_globals enabled](http://php.net/manual/en/security.globals.php) so `?file=` was passing right into `$file`. But now that is not enabled on 5.3, and you need to be using `$_GET['file']` to retrieve the file from the URL parameter. – Michael Berkowski Aug 31 '15 at 16:56
  • Always when developing and testing code, turn on display_errors. I would expect PHP to complain about an undefined variable `$file`. At the top of your script, before `session_start()` add `error_reporting(E_ALL); ini_set('display_errors', 1);` But add it _inside_ the first `` with `session_start()`, _not inside its own_ `` block. – Michael Berkowski Aug 31 '15 at 17:00
  • Sweet! that worked. Thank you so much for your help! – tokked13 Aug 31 '15 at 17:30

0 Answers0