Upgrading from PHP4 to PHP5

  • caravan5
  • Novice
  • Novice
  • caravan5
  • Posts: 20

Post 3+ Months Ago

Sorry in advance for the long post, but don't want to post links to our URL for fear of search engines.

I've just had an email from our hosting company to say our website hosting will be upgraded next wednesday from PHP4 to PHP5 and that we may need to update some elements of our website.

As far as I can see, PHP is only used for the menu system, however, this is obviously a major part of the website's functionality, so I'd like it to remain working after the upgrade.

My problem is: I don't know PHP. I know a bit of javascript so can recognise some of the elements, but that's it.

I need to know what version of PHP is being used on our site and how to upgrade it to PHP5 if necessary.

Can anyone help?

The code used on each page to call the menu script is:

Code: [ Select ]
<?php
        error_reporting(0);
        include_once('menumaker.inc');
        if (class_exists('csukMenuMakerClass'))
        {
        $menu =& new csukMenuMakerClass('sitemap.inc');
        $menu->Display();
        }
?>
  1. <?php
  2.         error_reporting(0);
  3.         include_once('menumaker.inc');
  4.         if (class_exists('csukMenuMakerClass'))
  5.         {
  6.         $menu =& new csukMenuMakerClass('sitemap.inc');
  7.         $menu->Display();
  8.         }
  9. ?>


The menumaker include file:

Code: [ Select ]
<?php
 
/*!
 * \file
 * \brief Menu Making Class
 * \author Colin Guthrie
 *
 * \warning This API will probably change at somepoint in the not too
 * distant future in order to tie in with the Pear menu stuff
 */
 
/*!
 * \brief The Menu Maker Class
 */
class csukMenuMakerClass
{
  var $mSitemap = null;
  var $mBlnInitialised = false;
  var $mStrPrefix = 'csuk';
  var $mIntMenuNum = 1;
 
  //==========================================================================
  function csukMenuMakerClass($filename, $menuNum = 1)
  {
    if (!file_exists($filename))
      return false;
 
    // File redefines the $sitemap variable
    @include($filename);
 
    $this->mSitemap = $sitemap;
    $this->mIntMenuNum = $menuNum;
 
    $this->mBlnInitialised = true;
  }
 
 
  //==========================================================================
  function FindSection_(&$rSitemap, $matchedChars = 0)
  {
    // Look in current menu
    $rv = false;
 
    if (isset($_SERVER))
      $rq_uri = htmlspecialchars($_SERVER['REQUEST_URI']);
    else if (isset($GLOBALS['HTTP_SERVER_VARS']))
      $rq_uri = htmlspecialchars($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']);
 
    $sitemap_size = count($rSitemap);
    for ($i = 0; $i < $sitemap_size; ++$i)
    {
      if (false !== strpos($rq_uri, $rSitemap[$i]['uri']))
      {
        $uri_len = strlen($rSitemap[$i]['uri']);
 
        if ($uri_len > $matchedChars)
        {
          $matchedChars = $uri_len;
          $rv = array($i);
        }
      }
    }
    unset($rq_uri);
 
    $found_in_sub = -1;
    // Now look in submenus
    for ($i = 0; $i < $sitemap_size; ++$i)
    {
      if (!isset($rSitemap[$i]['submenu'])
          || !is_array($rSitemap[$i]['submenu']))
        continue;
 
      $index = $this->FindSection_($rSitemap[$i]['submenu'], 0);
      if (false !== $index)
      {
        $found_in_sub = $i;
        $rv = $index;
      }
    }
 
    // Are we done yet?
    if ($found_in_sub >= 0)
    {
      !is_array($rv) && $rv = array();
      $rv[] = $found_in_sub;
    }
 
    return $rv;
  }
 
 
  //==========================================================================
  function DisplayR($sitemap = null, $index = null, $level = 1, $id = '',
                    $blnHidden = false)
  {
    if (!$this->mBlnInitialised)
      return '';
 
    // Some first run defaults...
    if (!isset($sitemap))
      $sitemap = $this->mSitemap;
 
    if (!isset($index))
    {
      $index = $this->FindSection_($this->mSitemap);
 
      if (false == $index)
      {
        $index = array();
        $index[0] = 0;
      }
    }
 
    if (empty($id))
      $id = $this->mStrPrefix.'menu'.$level;
 
    $index_count = count($index);
    if ($index_count > 0)
    {
      $current = array_pop($index);
      --$index_count;
    }
    else
    {
      $current = -1;
    }
    $rv = '';
 
    $sitemap_size = count($sitemap);
    $last_menu = $sitemap_size - 1;
    for ($i = 0; $i < $sitemap_size; ++$i)
    {
      $bln_has_submenu = (isset($sitemap[$i]['submenu'])
                          && is_array($sitemap[$i]['submenu'])
                          && count($sitemap[$i]['submenu']) > 0);
 
      $menu_id = $id;
      if ($bln_has_submenu)
      {
        $next_id = $id.((1 == $level % 2) ? chr(ord('a') + $i) : $i);
        $menu_id = $next_id;
      }
 
      $str_class = '';
      if (!$blnHidden && $i == $current)
      {
        $str_class = $this->mStrPrefix.'menucurrent';
      }
      if ($bln_has_submenu)
      {
        $str_class .= $this->mStrPrefix.'menuhaschild';
      }
 
      $rv .= '<li'.
        (!empty($str_class) ? ' class="'.$str_class.'"' : '').
        '>';
 
//       if (0 == $i)
//       {
//         $rv .= '<span class="'.$this->mStrPrefix.'menufirst'.$level.'">';
//       }
//       if ($i == $last_menu)
//       {
//         $rv .= '<span class="'.$this->mStrPrefix.'menulast'.$level.'">';
//       }
 
      $rv .= '<a'.
        (!$blnHidden && 0 == $index_count && $i == $current ? ' class="'.$this->mStrPrefix.'menucurrent"' : '').
        ' href="'.$sitemap[$i]['uri'].'"';
 
      if (isset($sitemap[$i]['long_title']))
      {
        $rv .= ' title="'.$sitemap[$i]['long_title'].'"';
      }
 
      $rv .= '>'.
        $sitemap[$i]['link_title'].
        '</a>';
 
//       if (0 == $i)
//         $rv .= '</span>';
//       if ($i == $last_menu)
//         $rv .= '</span>';
 
      if ($bln_has_submenu)
      {
        $sub = $this->DisplayR($sitemap[$i]['submenu'], $index, $level+1, $next_id,
                               ($blnHidden || ($i != $current)));
 
        if (!empty($sub))
        {
          $rv .= $sub;
        }
      }
 
      $rv .= '</li>';
 
    }
 
    if (!empty($rv))
      $rv = '<ul'.
        ' id="'.$id.'"'.
        ' class="'.$this->mStrPrefix.'menu'.$level.'"'.
        '>'.
        $rv.
        '</ul>';
 
    return $rv;
  }
 
 
  //==========================================================================
 /*!
   * \param blnNoJs  Disables JS event registrations if true
   */
  function Display($blnNoJs = false)
  {
    if (!$this->mBlnInitialised)
      return false;
 
    $num_tabs = count($this->mSitemap);
 
    if ($num_tabs < 1)
      return false;
 
    // Generate the menu.
    echo '<div class="'.$this->mStrPrefix.'menu">';
    echo $this->DisplayR();
    echo '</div>';
 
  }
}
 
?>
  1. <?php
  2.  
  3. /*!
  4.  * \file
  5.  * \brief Menu Making Class
  6.  * \author Colin Guthrie
  7.  *
  8.  * \warning This API will probably change at somepoint in the not too
  9.  * distant future in order to tie in with the Pear menu stuff
  10.  */
  11.  
  12. /*!
  13.  * \brief The Menu Maker Class
  14.  */
  15. class csukMenuMakerClass
  16. {
  17.   var $mSitemap = null;
  18.   var $mBlnInitialised = false;
  19.   var $mStrPrefix = 'csuk';
  20.   var $mIntMenuNum = 1;
  21.  
  22.   //==========================================================================
  23.   function csukMenuMakerClass($filename, $menuNum = 1)
  24.   {
  25.     if (!file_exists($filename))
  26.       return false;
  27.  
  28.     // File redefines the $sitemap variable
  29.     @include($filename);
  30.  
  31.     $this->mSitemap = $sitemap;
  32.     $this->mIntMenuNum = $menuNum;
  33.  
  34.     $this->mBlnInitialised = true;
  35.   }
  36.  
  37.  
  38.   //==========================================================================
  39.   function FindSection_(&$rSitemap, $matchedChars = 0)
  40.   {
  41.     // Look in current menu
  42.     $rv = false;
  43.  
  44.     if (isset($_SERVER))
  45.       $rq_uri = htmlspecialchars($_SERVER['REQUEST_URI']);
  46.     else if (isset($GLOBALS['HTTP_SERVER_VARS']))
  47.       $rq_uri = htmlspecialchars($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']);
  48.  
  49.     $sitemap_size = count($rSitemap);
  50.     for ($i = 0; $i < $sitemap_size; ++$i)
  51.     {
  52.       if (false !== strpos($rq_uri, $rSitemap[$i]['uri']))
  53.       {
  54.         $uri_len = strlen($rSitemap[$i]['uri']);
  55.  
  56.         if ($uri_len > $matchedChars)
  57.         {
  58.           $matchedChars = $uri_len;
  59.           $rv = array($i);
  60.         }
  61.       }
  62.     }
  63.     unset($rq_uri);
  64.  
  65.     $found_in_sub = -1;
  66.     // Now look in submenus
  67.     for ($i = 0; $i < $sitemap_size; ++$i)
  68.     {
  69.       if (!isset($rSitemap[$i]['submenu'])
  70.           || !is_array($rSitemap[$i]['submenu']))
  71.         continue;
  72.  
  73.       $index = $this->FindSection_($rSitemap[$i]['submenu'], 0);
  74.       if (false !== $index)
  75.       {
  76.         $found_in_sub = $i;
  77.         $rv = $index;
  78.       }
  79.     }
  80.  
  81.     // Are we done yet?
  82.     if ($found_in_sub >= 0)
  83.     {
  84.       !is_array($rv) && $rv = array();
  85.       $rv[] = $found_in_sub;
  86.     }
  87.  
  88.     return $rv;
  89.   }
  90.  
  91.  
  92.   //==========================================================================
  93.   function DisplayR($sitemap = null, $index = null, $level = 1, $id = '',
  94.                     $blnHidden = false)
  95.   {
  96.     if (!$this->mBlnInitialised)
  97.       return '';
  98.  
  99.     // Some first run defaults...
  100.     if (!isset($sitemap))
  101.       $sitemap = $this->mSitemap;
  102.  
  103.     if (!isset($index))
  104.     {
  105.       $index = $this->FindSection_($this->mSitemap);
  106.  
  107.       if (false == $index)
  108.       {
  109.         $index = array();
  110.         $index[0] = 0;
  111.       }
  112.     }
  113.  
  114.     if (empty($id))
  115.       $id = $this->mStrPrefix.'menu'.$level;
  116.  
  117.     $index_count = count($index);
  118.     if ($index_count > 0)
  119.     {
  120.       $current = array_pop($index);
  121.       --$index_count;
  122.     }
  123.     else
  124.     {
  125.       $current = -1;
  126.     }
  127.     $rv = '';
  128.  
  129.     $sitemap_size = count($sitemap);
  130.     $last_menu = $sitemap_size - 1;
  131.     for ($i = 0; $i < $sitemap_size; ++$i)
  132.     {
  133.       $bln_has_submenu = (isset($sitemap[$i]['submenu'])
  134.                           && is_array($sitemap[$i]['submenu'])
  135.                           && count($sitemap[$i]['submenu']) > 0);
  136.  
  137.       $menu_id = $id;
  138.       if ($bln_has_submenu)
  139.       {
  140.         $next_id = $id.((1 == $level % 2) ? chr(ord('a') + $i) : $i);
  141.         $menu_id = $next_id;
  142.       }
  143.  
  144.       $str_class = '';
  145.       if (!$blnHidden && $i == $current)
  146.       {
  147.         $str_class = $this->mStrPrefix.'menucurrent';
  148.       }
  149.       if ($bln_has_submenu)
  150.       {
  151.         $str_class .= $this->mStrPrefix.'menuhaschild';
  152.       }
  153.  
  154.       $rv .= '<li'.
  155.         (!empty($str_class) ? ' class="'.$str_class.'"' : '').
  156.         '>';
  157.  
  158. //       if (0 == $i)
  159. //       {
  160. //         $rv .= '<span class="'.$this->mStrPrefix.'menufirst'.$level.'">';
  161. //       }
  162. //       if ($i == $last_menu)
  163. //       {
  164. //         $rv .= '<span class="'.$this->mStrPrefix.'menulast'.$level.'">';
  165. //       }
  166.  
  167.       $rv .= '<a'.
  168.         (!$blnHidden && 0 == $index_count && $i == $current ? ' class="'.$this->mStrPrefix.'menucurrent"' : '').
  169.         ' href="'.$sitemap[$i]['uri'].'"';
  170.  
  171.       if (isset($sitemap[$i]['long_title']))
  172.       {
  173.         $rv .= ' title="'.$sitemap[$i]['long_title'].'"';
  174.       }
  175.  
  176.       $rv .= '>'.
  177.         $sitemap[$i]['link_title'].
  178.         '</a>';
  179.  
  180. //       if (0 == $i)
  181. //         $rv .= '</span>';
  182. //       if ($i == $last_menu)
  183. //         $rv .= '</span>';
  184.  
  185.       if ($bln_has_submenu)
  186.       {
  187.         $sub = $this->DisplayR($sitemap[$i]['submenu'], $index, $level+1, $next_id,
  188.                                ($blnHidden || ($i != $current)));
  189.  
  190.         if (!empty($sub))
  191.         {
  192.           $rv .= $sub;
  193.         }
  194.       }
  195.  
  196.       $rv .= '</li>';
  197.  
  198.     }
  199.  
  200.     if (!empty($rv))
  201.       $rv = '<ul'.
  202.         ' id="'.$id.'"'.
  203.         ' class="'.$this->mStrPrefix.'menu'.$level.'"'.
  204.         '>'.
  205.         $rv.
  206.         '</ul>';
  207.  
  208.     return $rv;
  209.   }
  210.  
  211.  
  212.   //==========================================================================
  213.  /*!
  214.    * \param blnNoJs  Disables JS event registrations if true
  215.    */
  216.   function Display($blnNoJs = false)
  217.   {
  218.     if (!$this->mBlnInitialised)
  219.       return false;
  220.  
  221.     $num_tabs = count($this->mSitemap);
  222.  
  223.     if ($num_tabs < 1)
  224.       return false;
  225.  
  226.     // Generate the menu.
  227.     echo '<div class="'.$this->mStrPrefix.'menu">';
  228.     echo $this->DisplayR();
  229.     echo '</div>';
  230.  
  231.   }
  232. }
  233.  
  234. ?>


And the sitemap include file is here:

Code: [ Select ]
<?php
 
$str_link_base = '';
$sitemap = array(
  array('link_title' => 'Home Page',
        'uri' => $str_link_base.'/index.php'
    ),
  array('link_title' => 'About us',
        'uri' => $str_link_base.'/about_us/index.php'
    ),
  array('link_title' => 'Tourer Caravan Insurance',
        'uri' => $str_link_base.'/tourer_caravan_insurance/index.php',
        'submenu' => array(
          array('link_title' => 'Benefits',
                'uri' => $str_link_base.'/tourer_caravan_insurance/index.php'
            ),
          array('link_title' => 'Savings and Discounts',
                'uri' => $str_link_base.'/tourer_caravan_insurance/savings_discounts.php'
            ),
          array('link_title' => 'Security &amp; Storage',
                'uri' => $str_link_base.'/tourer_caravan_insurance/security_storage.php',
                'submenu' => array(
                  array('link_title' => 'Security',
                        'uri' => $str_link_base.'/tourer_caravan_insurance/security_storage.php'
                    ),
                  array('link_title' => 'Tracking Devices',
                        'uri' => $str_link_base.'/tourer_caravan_insurance/security_storage_2.php'
                    )
                  )
            ),
          array('link_title' => 'Downloads',
                'uri' => $str_link_base.'/tourer_caravan_insurance/brochure_policy.php'
            ),
          array('link_title' => 'Top Tips',
                'uri' => $str_link_base.'/tourer_caravan_insurance/top_tips.php'
            )
          )
    ),
array('link_title' => 'Motorhome Insurance',
        'uri' => $str_link_base.'/motorhome_insurance/index.php',
        'submenu' => array(
          array('link_title' => 'Benefits',
                'uri' => $str_link_base.'/motorhome_insurance/index.php'
            ),
          array('link_title' => 'Savings and Discounts',
                'uri' => $str_link_base.'/motorhome_insurance/savings_discounts.php'
            ),
          array('link_title' => 'Security &amp; Storage',
                'uri' => $str_link_base.'/motorhome_insurance/security_storage.php',
                'submenu' => array(
                  array('link_title' => 'Security',
                        'uri' => $str_link_base.'/motorhome_insurance/security_storage.php'
                    ),
                  array('link_title' => 'Tracking Devices',
                        'uri' => $str_link_base.'/motorhome_insurance/security_storage_2.php'
                    )
                  )
            ),
          array('link_title' => 'Downloads',
                'uri' => $str_link_base.'/motorhome_insurance/brochure_policy.php'
            ),
          array('link_title' => 'Top Tips',
                'uri' => $str_link_base.'/motorhome_insurance/top_tips.php'
            )
          )
    ),
  array('link_title' => 'Trailer Tent Insurance',
        'uri' => $str_link_base.'/trailer_tent_insurance/index.php'
    ),
  array('link_title' => 'Folding Camper Insurance',
        'uri' => $str_link_base.'/folding_camper_insurance/index.php'
    ),
  array('link_title' => 'Static Caravan Insurance',
        'uri' => $str_link_base.'/holiday_home_insurance/index.php'
    ),
  array('link_title' => 'Car & Home Insurance',
        'uri' => $str_link_base.'/car_and_home/index.php'
    ),
  array('link_title' => 'News',
        'uri' => $str_link_base.'/news/index.php'
    ),
  array('link_title' => 'Contact us',
        'uri' => $str_link_base.'/contact/index.php'
    )
  );
 
 
 
?>
  1. <?php
  2.  
  3. $str_link_base = '';
  4. $sitemap = array(
  5.   array('link_title' => 'Home Page',
  6.         'uri' => $str_link_base.'/index.php'
  7.     ),
  8.   array('link_title' => 'About us',
  9.         'uri' => $str_link_base.'/about_us/index.php'
  10.     ),
  11.   array('link_title' => 'Tourer Caravan Insurance',
  12.         'uri' => $str_link_base.'/tourer_caravan_insurance/index.php',
  13.         'submenu' => array(
  14.           array('link_title' => 'Benefits',
  15.                 'uri' => $str_link_base.'/tourer_caravan_insurance/index.php'
  16.             ),
  17.           array('link_title' => 'Savings and Discounts',
  18.                 'uri' => $str_link_base.'/tourer_caravan_insurance/savings_discounts.php'
  19.             ),
  20.           array('link_title' => 'Security &amp; Storage',
  21.                 'uri' => $str_link_base.'/tourer_caravan_insurance/security_storage.php',
  22.                 'submenu' => array(
  23.                   array('link_title' => 'Security',
  24.                         'uri' => $str_link_base.'/tourer_caravan_insurance/security_storage.php'
  25.                     ),
  26.                   array('link_title' => 'Tracking Devices',
  27.                         'uri' => $str_link_base.'/tourer_caravan_insurance/security_storage_2.php'
  28.                     )
  29.                   )
  30.             ),
  31.           array('link_title' => 'Downloads',
  32.                 'uri' => $str_link_base.'/tourer_caravan_insurance/brochure_policy.php'
  33.             ),
  34.           array('link_title' => 'Top Tips',
  35.                 'uri' => $str_link_base.'/tourer_caravan_insurance/top_tips.php'
  36.             )
  37.           )
  38.     ),
  39. array('link_title' => 'Motorhome Insurance',
  40.         'uri' => $str_link_base.'/motorhome_insurance/index.php',
  41.         'submenu' => array(
  42.           array('link_title' => 'Benefits',
  43.                 'uri' => $str_link_base.'/motorhome_insurance/index.php'
  44.             ),
  45.           array('link_title' => 'Savings and Discounts',
  46.                 'uri' => $str_link_base.'/motorhome_insurance/savings_discounts.php'
  47.             ),
  48.           array('link_title' => 'Security &amp; Storage',
  49.                 'uri' => $str_link_base.'/motorhome_insurance/security_storage.php',
  50.                 'submenu' => array(
  51.                   array('link_title' => 'Security',
  52.                         'uri' => $str_link_base.'/motorhome_insurance/security_storage.php'
  53.                     ),
  54.                   array('link_title' => 'Tracking Devices',
  55.                         'uri' => $str_link_base.'/motorhome_insurance/security_storage_2.php'
  56.                     )
  57.                   )
  58.             ),
  59.           array('link_title' => 'Downloads',
  60.                 'uri' => $str_link_base.'/motorhome_insurance/brochure_policy.php'
  61.             ),
  62.           array('link_title' => 'Top Tips',
  63.                 'uri' => $str_link_base.'/motorhome_insurance/top_tips.php'
  64.             )
  65.           )
  66.     ),
  67.   array('link_title' => 'Trailer Tent Insurance',
  68.         'uri' => $str_link_base.'/trailer_tent_insurance/index.php'
  69.     ),
  70.   array('link_title' => 'Folding Camper Insurance',
  71.         'uri' => $str_link_base.'/folding_camper_insurance/index.php'
  72.     ),
  73.   array('link_title' => 'Static Caravan Insurance',
  74.         'uri' => $str_link_base.'/holiday_home_insurance/index.php'
  75.     ),
  76.   array('link_title' => 'Car & Home Insurance',
  77.         'uri' => $str_link_base.'/car_and_home/index.php'
  78.     ),
  79.   array('link_title' => 'News',
  80.         'uri' => $str_link_base.'/news/index.php'
  81.     ),
  82.   array('link_title' => 'Contact us',
  83.         'uri' => $str_link_base.'/contact/index.php'
  84.     )
  85.   );
  86.  
  87.  
  88.  
  89. ?>


Thanks in advance
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

PHP 5 is usually backwards compatible with PHP 4, that is a PHP5 parser can handle most PHP4 elements in PHP code. The exact code (symbols) that you're using aren't necessarily a specific version, the elements that are in the code could be supported by a PHP5 parser and not by a PHP4 parser, or vice versa. The parser is what your host is talking about.

For example in your code at the beginning of your menu class you have some variables that are declared with "var". The newer way to do it, is to declare them with "public", "private", "protected", etc... but when your host upgrades the PHP parser to PHP5, they will still work. Another example is in PHP 4 there is a function called strpos(), but in PHP 5 there is strpos() and stripos() (which is a case-insensitive version of the same function). Right now stripos() wouldn't work on your hosts server, but it will work when they upgrade to PHP5.

From what I can see, everything will work fine the way it is when your host upgrades. I could have missed something, but if it did break it wouldn't be too much of a problem to fix.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: Bill_Thompson and 69 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.