Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Weird Problem


Stealth1

Recommended Posts

Posted

Can someone tell me why I would get this error?

 

Error: getimagesize(/store/images/products/fp-racing-levers/FP Racing Tactical Leverl.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php

 

The directory and file do exist so I can't figure out why it's giving me this error.

Posted

try to rename the image name from FP Racing Tactical Leverl.jpg to FP_Racing_Tactical_Leverl.jpg and try again.

 

Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!

8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.

Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.

Any issues with oscommerce, I am here to help you.

Posted

try to rename the image name from FP Racing Tactical Leverl.jpg to FP_Racing_Tactical_Leverl.jpg and try again.

 

Tried to change the picture name to one without spaces but the errors still show, here is the complete list.

 

Pictures and popups are working but the error shouldn't be there.

 

Error: getimagesize(/store/images/products/fp-racing-levers/FP Racing Tactical Leverl.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 78
Error: getimagesize(/store/images/products/fp-racing-levers/tacticall.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 80
Error: getimagesize(/store/images/products/fp-racing-levers/03 black red tactical Leverl.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 80
Error: getimagesize(/store/images/products/fp-racing-levers/02 FP Lever Coloursl.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 80
Error: getimagesize(/store/images/products/fp-racing-levers/tacticalm.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 114
Error: getimagesize(/store/images/products/fp-racing-levers/tacticalm.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 117
Error: getimagesize(/store/images/products/fp-racing-levers/tacticall.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 120
Error: getimagesize(/store/images/products/fp-racing-levers/03 black red tactical Leverm.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 114
Error: getimagesize(/store/images/products/fp-racing-levers/03 black red tactical Leverm.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 117
Error: getimagesize(/store/images/products/fp-racing-levers/03 black red tactical Leverl.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 120
Error: getimagesize(/store/images/products/fp-racing-levers/02 FP Lever Coloursm.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 114
Error: getimagesize(/store/images/products/fp-racing-levers/02 FP Lever Coloursm.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 117
Error: getimagesize(/store/images/products/fp-racing-levers/02 FP Lever Coloursl.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
File: includes/classes/displayimages.php
Line: 120

Posted

includes/classes/displayimages.php's call to getimagesize() expecting either a relative path or an absolute path to the file. Is /store in the filesystem root, or is it the HTML root? Your call is saying that absolute path /store is in the filesystem root, when presumably the file is actually in /home/ACCOUNT/public_html/store/images/produces/products/... or whatever. Check whether you're giving the right path for the image (need to add something before /store).

 

I agree that a filename with blanks is probably bad news. What exactly is the format... presumably the filename is given in quotes. But still, Windows-style file names is risky on any Web system.

Posted

includes/classes/displayimages.php's call to getimagesize() expecting either a relative path or an absolute path to the file. Is /store in the filesystem root, or is it the HTML root? Your call is saying that absolute path /store is in the filesystem root, when presumably the file is actually in /home/ACCOUNT/public_html/store/images/produces/products/... or whatever. Check whether you're giving the right path for the image (need to add something before /store).

 

I agree that a filename with blanks is probably bad news. What exactly is the format... presumably the filename is given in quotes. But still, Windows-style file names is risky on any Web system.

 

Here is the displayimages.php file.

 

<?php
/*
 Designed for: osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2006 Todd Holforty - [email protected]

 Released under the GNU General Public License

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/**
*** displayimages class ***
*** 
*** 
*** 
*** 
*** 
*** 
*/
 class displayimages {

   var $restrictsmimage = ADDIMAGES_RESTRICT_IMAGE_SIZE;  // true, false
   var $tablealignment = ADDIMAGES_TABLE_ALIGNMENT;   // right, center, left
   var $numberofcolumns = ADDIMAGES_NUMBER_OF_COLS;
   var $numberofrows = ADDIMAGES_NUMBER_OF_ROWS;
   var $groupwithparent = ADDIMAGES_GROUP_WITH_PARENT;  // true, false
   var $imagedefault = 'medium'; // original it's medium
   var $buildmenu = false;
   var $onpagemenu = false;
   var $linkurl = FILENAME_POPUP_ADD_IMAGE;

   var $addimages_count = 0;
   var $groupout = '';

   var $maximagewidth = 0;
   var $maximageheight = 0;


  /**
   ** constructor **/
   function displayimages ( $products_id ) {

     $this->imagedir = DIR_FS_CATALOG . DIR_WS_IMAGES;
     $product_query = tep_db_query("SELECT products_id, products_image, products_image_med, products_image_pop, products_image_description FROM " . TABLE_PRODUCTS . " WHERE products_id = '".(int)$products_id."'");
     $product = tep_db_fetch_array($product_query);
     tep_db_free_result($product_query);

     $images = array();
     $images_query = tep_db_query("select additional_images_id, images_description, thumb_images, medium_images, popup_images from " . TABLE_ADDITIONAL_IMAGES . " where products_id = '" . (int)$products_id . "'");
     while ($tmp_images = tep_db_fetch_array($images_query)) {
       $images[] = $tmp_images;
     }
     tep_db_free_result($images_query);

     // find the largest image width and height
     if (ADDIMAGES_MENU_LOCATION == 'product_info' && ENABLE_LIGHTBOX == 'true') { // doing on page rollovers and the lightbox.
       if (!empty($product['products_image_med']) || !empty($product['products_image'])) { list($this->maximagewidth, $this->maximageheight, $type) = @getimagesize($this->imagedir.(!empty($product['products_image_med'])?$product['products_image_med']:$product['products_image'])); }
       foreach ($images as $key => $image) {
         if (!empty($image['medium_images']) || !empty($image['thumb_images'])) { list($t_maximagewidth, $t_maximageheight, $type) = @getimagesize($this->imagedir.(!empty($image['medium_images'])?$image['medium_images']:$image['thumb_images'])); }
         if ($t_maximagewidth > $this->maximagewidth) { $this->maximagewidth = $t_maximagewidth; }
         if ($t_maximageheight > $this->maximageheight) { $this->maximageheight = $t_maximageheight; }
       }
     } else { // normal
       if (!empty($product['products_image_pop']) || !empty($product['products_image'])) { list($this->maximagewidth, $this->maximageheight, $type) = @getimagesize($this->imagedir.(!empty($product['products_image_pop'])?$product['products_image_pop']:$product['products_image'])); }
       foreach ($images as $key => $image) {
         if (!empty($image['popup_images']) || !empty($image['thumb_images'])) { list($t_maximagewidth, $t_maximageheight, $type) = @getimagesize($this->imagedir.(!empty($image['popup_images'])?$image['popup_images']:$image['thumb_images'])); }
         if ($t_maximagewidth > $this->maximagewidth) { $this->maximagewidth = $t_maximagewidth; }
         if ($t_maximageheight > $this->maximageheight) { $this->maximageheight = $t_maximageheight; }
       }
     }

     // determine image width to use
     $addimages_image_width = ($this->restrictsmimage=='true'?(($this->imagedefault=='medium')?DISPLAY_IMAGE_WIDTH:SMALL_IMAGE_WIDTH):'');
     $addimages_image_height = ($this->restrictsmimage=='true'?(($this->imagedefault=='medium')?DISPLAY_IMAGE_HEIGHT:SMALL_IMAGE_HEIGHT):'');

     $row = 1;
     $col = 1;

     // build composite array of products.
     $addimages_images = array();
     if (tep_not_null($product['products_image']) && $this->groupwithparent == 'true') { 
       if (tep_not_null($product['products_image_med']) && ($this->imagedefault == 'medium')) { $use_image = $product['products_image_med']; }
       elseif (tep_not_null($product['products_image']) && ($this->imagedefault == 'medium' || $this->imagedefault == 'small')) { $use_image = $product['products_image']; }
       $t_imagewidth = 0;
       $t_imageheight = 0;
       if (!empty($use_image)) { list($t_imagewidth, $t_imageheight, $type) = @getimagesize($this->imagedir.$use_image); }
       $t_medimagewidth = 0;
       $t_medimageheight = 0;
       if (!empty($product['products_image_med'])) { list($t_medimagewidth, $t_medimageheight, $type) = @getimagesize($this->imagedir.$product['products_image_med']); }
       $t_popimagewidth = 0;
       $t_popimageheight = 0;
       if (!empty($product['products_image_pop'])) { list($t_popimagewidth, $t_popimageheight, $type) = @getimagesize($this->imagedir.$product['products_image_pop']); }
       $addimages_images[] = array('id' => '', 'image' => $use_image, 'image_width' => $t_imagewidth, 'image_height' => $t_imageheight, 'medimage' => $product['products_image_med'], 'medimage_width' => $t_medimagewidth, 'medimage_height' => $t_medimageheight, 'popimage' => $product['products_image_pop'], 'popimage_width' => $t_popimagewidth, 'popimage_height' => $t_popimageheight, 'desc' => $product['products_image_description']); 
     }
     foreach ( $images as $key => $image ) {
       if (tep_not_null($image['medium_images']) && ($this->imagedefault == 'medium')) { $use_image = $image['medium_images']; }
       elseif (tep_not_null($image['thumb_images']) && ($this->imagedefault == 'medium' || $this->imagedefault == 'small')) { $use_image = $image['thumb_images']; }
       $t_imagewidth = 0;
       $t_imageheight = 0;
       if (!empty($use_image)) { list($t_imagewidth, $t_imageheight, $type) = @getimagesize($this->imagedir.$use_image); }
       $t_medimagewidth = 0;
       $t_medimageheight = 0;
       if (!empty($image['medium_images'])) { list($t_medimagewidth, $t_medimageheight, $type) = @getimagesize($this->imagedir.$image['medium_images']); }
       $t_popimagewidth = 0;
       $t_popimageheight = 0;
       if (!empty($image['popup_images'])) { list($t_popimagewidth, $t_popimageheight, $type) = @getimagesize($this->imagedir.$image['popup_images']); }
       $addimages_images[] = array('id' => $image['additional_images_id'], 'image' => $use_image, 'image_width' => $t_imagewidth, 'image_height' => $t_imageheight, 'medimage' => $image['medium_images'], 'medimage_width' => $t_medimagewidth, 'medimage_height' => $t_medimageheight, 'popimage' => $image['popup_images'], 'popimage_width' => $t_popimagewidth, 'popimage_height' => $t_popimageheight, 'desc' => $image['images_description']);
     }
     $this->addimages_count = sizeof($addimages_images);

     // start building output
     if (tep_not_null($product['products_image'])) { $this->groupout .= '<table border="0" cellspacing="0" cellpadding="4" align="'.$this->tablealignment.'" style="position: relative;">'."\n"; }

     for ( $item=0; $item<$this->addimages_count; $item++ ) {

       if ($row<($this->numberofrows+1)) {
         if ($col==1) {$this->groupout.='<tr>';}
         if (ADDIMAGES_MENU_LOCATION == 'product_info' && ENABLE_LIGHTBOX == 'true') { // doing on page rollovers and the lightbox.
           $t_menu_mouseover = (($this->buildmenu==true) ? ' onmouseover="showImage('.(!empty($addimages_images[$item]['medimage']) ? '\\\''.DIR_WS_IMAGES.$addimages_images[$item]['medimage'].'\\\', '.$addimages_images[$item]['medimage_width'].', '.$addimages_images[$item]['medimage_height'] : '\\\''.DIR_WS_IMAGES.$addimages_images[$item]['image'].'\\\', '.$addimages_images[$item]['image_width'].', '.$addimages_images[$item]['image_height']) . ', \\\''.addslashes(str_replace("'","\'",htmlspecialchars($addimages_images[$item]['desc']))).'\\\')"' : '' );
         } else { // normal
           $t_menu_mouseover = (($this->buildmenu==true) ? ' onmouseover="showImage('.(!empty($addimages_images[$item]['popimage']) ? '\\\''.DIR_WS_IMAGES.$addimages_images[$item]['popimage'].'\\\', '.$addimages_images[$item]['popimage_width'].', '.$addimages_images[$item]['popimage_height'] : '\\\''.DIR_WS_IMAGES.$addimages_images[$item]['image'].'\\\', '.$addimages_images[$item]['image_width'].', '.$addimages_images[$item]['image_height']) . ', \\\''.addslashes(str_replace("'","\'",htmlspecialchars($addimages_images[$item]['desc']))).'\\\')"' : '' );
         }

         // BOF lightbox addon
         if (ENABLE_LIGHTBOX == 'true') {
           $this->groupout .= ' 
             <td align="center" class="smallText"><script language="javascript"><!-- 
               document.write(\'<a href="images/' . $addimages_images[$item]['popimage'] . '"target="_blank" rel="lightbox[group]" title="' . addslashes(htmlspecialchars($addimages_images[$item]['desc'])) .'"' . $t_menu_mouseover . '>' . tep_image(DIR_WS_IMAGES . $addimages_images[$item]['image'], addslashes(htmlspecialchars($addimages_images[$item]['desc'])), (ADDIMAGES_RESTRICT_PARENT=='false'&&$item==0&&$this->groupwithparent=='true'?'':$addimages_image_width), (ADDIMAGES_RESTRICT_PARENT=='false'&&$item==0&&$this->groupwithparent=='true'?'':$addimages_image_height), 'hspace="5" vspace="5"') . '<br>' . (!empty($addimages_images[$item]['desc'])?addslashes($addimages_images[$item]['desc']):TEXT_CLICK_TO_ENLARGE). '</a>\');
               //--></script><noscript>
                 <a href="' . tep_href_link(DIR_WS_IMAGES . $addimages_images[$item]['popimage']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $addimages_images[$item]['image'], $addimages_images[$item]['desc'], $addimages_image_width, $addimages_image_height, 'hspace="5" vspace="5"') . '<br>' . (!empty($addimages_images[$item]['desc'])?$addimages_images[$item]['desc']:TEXT_CLICK_TO_ENLARGE) . '</a>
                 </noscript></td>'."\n";
         } else { 
         // EOF lightbox addon
           $this->groupout .= '
             <td align="center" class="smallText"><script language="javascript"><!--
               document.write(\'<a href="' . (!$this->onpagemenu ? 'javascript:popupWindow(\\\'' : '') . tep_href_link( $this->linkurl, ($item==0&&$this->groupwithparent=='true'?'pID='.$products_id:'imagesID='.$addimages_images[$item]['id'])) . (!empty($_GET['products_id']) ? '&products_id='.$_GET['products_id'] : '') . (!empty($_GET['cPath']) ? '&cPath='.$_GET['cPath'] : '') . (!$this->onpagemenu ? '\\\')' : '') . '"' . $t_menu_mouseover . '>' . tep_image(DIR_WS_IMAGES . $addimages_images[$item]['image'], addslashes($addimages_images[$item]['desc']), (ADDIMAGES_RESTRICT_PARENT=='false'&&$item==0&&$this->groupwithparent=='true'?'':$addimages_image_width), (ADDIMAGES_RESTRICT_PARENT=='false'&&$item==0&&$this->groupwithparent=='true'?'':$addimages_image_height), 'hspace="5" vspace="5"') . '<br>' . (!empty($addimages_images[$item]['desc'])?addslashes($addimages_images[$item]['desc']):TEXT_CLICK_TO_ENLARGE) . '</a>\');
               //--></script><noscript>
                 <a href="' . tep_href_link(DIR_WS_IMAGES . $addimages_images[$item]['popimage']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $addimages_images[$item]['image'], $addimages_images[$item]['desc'], $addimages_image_width, $addimages_image_height, 'hspace="5" vspace="5"') . '<br>' . (!empty($addimages_images[$item]['desc'])?$addimages_images[$item]['desc']:TEXT_CLICK_TO_ENLARGE) . '</a>
                 </noscript></td>'."\n";
         // BOF lightbox addon      
         }
         // EOF lightbox addon

         if ($col==$this->numberofcolumns) { $col=1; $row++; $this->groupout.='</tr>'."\n"; } else { $col++; }
       }

     }

     if ($col!=1 && $this->addimages_count > $this->numberofcolumns){ while (($col++)<($this->numberofcolumns+1)) { $this->groupout.='<td> </td>'."\n"; } }

     if (tep_not_null($product['products_image'])) { $this->groupout .= '</table>'."\n"; }

   }

  /**
   ** member functions
   **/
   function groupoutput () {
     return $this->groupout;
   }

   function altgroupoutput () {
     $returnvar = '
         <table width="100%" border="0" cellspacing="0" cellpadding="0">
           <tr>
             <td align="center" class="smallText">'.$this->groupout.'</td>
           </tr>
         </table>'."\n";
     return $returnvar;
   }

   function boxsize () {
     // calculate box size
     $menuimagewidth = (($this->imagedefault=='medium')?DISPLAY_IMAGE_WIDTH:SMALL_IMAGE_WIDTH);
     $menuimageheight = (($this->imagedefault=='medium')?DISPLAY_IMAGE_HEIGHT:SMALL_IMAGE_HEIGHT);
     if (empty($menuimageheight)) { $menuimageheight = $menuimagewidth; } // if width was set to zero for proper proportion display.
     if (empty($menuimagewidth)) { $menuimagewidth = $menuimageheight; } // if height was set to zero for proper proportion display.

     $real_columns = (($this->addimages_count < $this->numberofcolumns) ? $this->addimages_count : $this->numberofcolumns);
     $real_rows = ceil($this->addimages_count / $this->numberofcolumns);

     $menu_width = ($real_columns * ($menuimagewidth + 10));
     $menu_height = ($real_rows * ($menuimageheight + 10));

     return array($menu_width, $menu_height);
   }

 } // end: class displayimages {}


/**
*** displaypopupimagemenu class ***
*** 
*** 
*** 
*** 
*** 
*** 
*/
 class displaypopupimagemenu extends displayimages {

  /**
   ** constructor **/
   function displaypopupimagemenu ( $products_id ) {

     $this->imagedir = DIR_FS_CATALOG . DIR_WS_IMAGES;
     $this->restrictsmimage = ADDIMAGES_POPUP_RESTRICT_IMAGE_SIZE;
     $this->tablealignment = ADDIMAGES_POPUP_TABLE_ALIGNMENT;
     $this->numberofcolumns = ADDIMAGES_POPUP_NUMBER_OF_COLS;
     $this->numberofrows = ADDIMAGES_POPUP_NUMBER_OF_ROWS;
     $this->groupwithparent = ADDIMAGES_POPUP_GROUP_WITH_PARENT;
     $this->imagedefault = 'small';
     $this->buildmenu = true;
     $this->onpagemenu = false;
     $this->linkurl = FILENAME_POPUP_ADD_IMAGE;

     $this->displayimages ( $products_id );

   }

 } // end: class displaypopupimagemenu {}


/**
*** displayonpageimagemenu class ***
*** 
*** 
*** 
*** 
*** 
*** 
*/
 class displayonpageimagemenu extends displayimages {

  /**
   ** constructor **/
   function displayonpageimagemenu ( $products_id ) {

     $this->imagedir = DIR_FS_CATALOG . DIR_WS_IMAGES;
     $this->restrictsmimage = ADDIMAGES_POPUP_RESTRICT_IMAGE_SIZE;
     $this->tablealignment = ADDIMAGES_POPUP_TABLE_ALIGNMENT;
     $this->numberofcolumns = ADDIMAGES_POPUP_NUMBER_OF_COLS;
     $this->numberofrows = ADDIMAGES_POPUP_NUMBER_OF_ROWS;
     $this->groupwithparent = ADDIMAGES_POPUP_GROUP_WITH_PARENT;
     $this->imagedefault = 'small';
     $this->buildmenu = true;
     $this->onpagemenu = true;
     $this->linkurl = FILENAME_PRODUCT_INFO;

     $this->displayimages ( $products_id );

   }

 } // end: class displayonpageimagemenu {}




?>

Posted

A DIR_FS_CATALOG of /store/ seems odd. What does your configure.php file have for the following line:

  define('DIR_FS_CATALOG', dirname($HTTP_SERVER_VARS['SCRIPT_FILENAME']) . '/');

Is it like that, or something else? If someone hardcoded it to

  define('DIR_FS_CATALOG', '/store/');

they done wrong. That entry should have the store directory from the filesystem root, which is different that from the website root! If it needs to be hardcoded, it should be something like

  define('DIR_FS_CATALOG', '/home/ACCOUNTNAME/public_html/store/');

(depending on how your server is set up).

Posted

Yes my includes/configure.php is as below.

 

 define('DIR_FS_CATALOG', '/store/');

 

Should I put the full path and should I adjust it for every entry in the configure.php file or just this one?

Posted

I put in the full path and it now has fixed all those problems but I now have another error that showed up.

 

Error: Undefined index: QUERY_STRING
File: includes/modules/ultimate_seo_urls5/classes/Usu_Validator.php
Line: 37

Posted

Should I put the full path and should I adjust it for every entry in the configure.php file or just this one?

Anywhere you have a DIR_FS_... being defined, it must be the full filesystem path, not relative and not website. Normally, DIR_FS_CATALOG and DIR_FS_DOCUMENT_ROOT (if you hardcode either) would be the only ones you have to worry about, as all others are built off of these paths.

 

For the QUERY_STRING problem, can you show the line of code in question, and 10 or 15 lines before it?

Posted

Anywhere you have a DIR_FS_... being defined, it must be the full filesystem path, not relative and not website. Normally, DIR_FS_CATALOG and DIR_FS_DOCUMENT_ROOT (if you hardcode either) would be the only ones you have to worry about, as all others are built off of these paths.

 

For the QUERY_STRING problem, can you show the line of code in question, and 10 or 15 lines before it?

 

Ok so i've changed it in the includes/configure.php file, do I need to change it somewhere else?

Posted

Here is the full file, my hosting provider doesn't have a nice filemanager that shows the lines etc.

 

<?php
/**
*
* ULTIMATE Seo Urls 5
*
* 
* @package Ultimate Seo Urls 5
* @license http://www.opensource.org/licenses/gpl-2.0.php GNU Public License
* @link http://www.fwrmedia.co.uk
* @copyright Copyright 2008-2009 FWR Media
* @author Robert Fisher, FWR Media, http://www.fwrmedia.co.uk 
* @lastdev $Author:: Rob                                              $:  Author of last commit
* @lastmod $Date:: 2009-11-29 18:02:54 +0000 (Sun, 29 Nov 2009)       $:  Date of last commit
* @version $Rev:: 109                                                 $:  Revision of last commit
* @Id $Id:: Usu_Validator.php 109 2009-11-29 18:02:54Z Rob            $:  Full Details   
*/

 class Usu_Validator {

   private $basename;
   private $filestring;
   private $querystring;
   private $request_uri;

   public function __construct() {
     $this->disectUri();
   }

   private function disectUri() {
     // get the base filename
     $this->basename = usu5_base_filename();
     // Confirm we have an seo registered page if not return false
     if ( false === array_key_exists( $this->basename, usu::$registry->seo_pages ) ) {
       return false;
     }
     // Remove the osCsid and sanitise
     $this->sanitizeQuerystring( $_SERVER['QUERY_STRING'] );
     // Attempt to format $_SERVER['REQUEST_URI'] for Windows/IIS
     $this->iis_request_uri();
     // Remove the querystring (if there)
     if ( false !== strpos( $this->request_uri, '?' ) ) {
       $this->filestring = substr_replace( $this->request_uri, '', strpos( $this->request_uri, '?' ) );
     // Querystring should not start with & but remove anyway (if there)
     } elseif ( false !== strpos( $this->request_uri, '&' ) ) {
       $this->filestring = substr_replace( $this->request_uri, '', strpos( $this->request_uri, '&' ) );
     // Looks clean with no query string
     } else {
       $this->filestring = $this->request_uri;
     }
     // Return false if .. $this->filestring is empty .. or .. the querystring is empty and the filestring ends in .php 
     if ( ( false === tep_not_null( $this->filestring ) ) || ( ( substr( $this->filestring, -4, 4 ) == '.php' ) && ( false === tep_not_null( $this->querystring ) ) ) ) {
       return false;
     }
     // Check to see the type of URI we are dealing with
     switch ( $this->filestring ) {
       // broken osCommerce urls
       case ( substr_count ($this->filestring, '/' ) > 1 ):
         $this->filestring = str_replace( $this->basename . '/', '', $this->filestring );
         $newget = $this->extractByDirSeparator();
         $this->parsePath();
         break;
       // Non rewrite seo urls
       case ( false !== strpos( $this->filestring, '/' ) ):
         $this->filestring = str_replace( $this->basename . '/', '', $this->filestring );
         $extractqs = $this->extractByMarkers();
         $this->querystring = $extractqs . '&' . $this->querystring; 
         $this->parsePath();
         break;
       // Rewrite seo urls
       case ( false !== strpos( $this->filestring, '.html' ) ):
         $this->filestring = str_replace( '/', '', $this->filestring );
         $this->extractByMarkers(); 
         $this->parsePath();
         break;
       // Standard files
       case substr( $this->filestring, -4 ) == '.php':
         // If there is querystring but not an seo get key then don't validate
         foreach ( usu::$registry->vars['page_dependencies'][$this->basename] as $getkey => $dummy ) {
           if ( false !== strpos( $this->querystring, $getkey) ) {
             // Serve standard osC uri when the products_id has attributes
             if ( ( $getkey == 'products_id' ) && ( false !== strpos( urldecode( $this->querystring ), '}' ) ) ) {
               return false;
             }
             $this->parsePath();
             break;
           }
         }
         return false;
         break;
       default:
         break;
     }
   } // End method

   /**
   * Attempt to build $_SERVER['REQUEST_URI'] for Windows
   * This is very dirty as I have no means to test on IIS
   */
   private function iis_request_uri() {
     $rawpath = '';
     switch ( true ) {
       case array_key_exists( 'REQUEST_URI', $_SERVER ):
         $rawpath = str_replace( '\\', '/', $_SERVER['REQUEST_URI'] );
         break;
       case array_key_exists( 'HTTP_X_ORIGINAL_URL', $_SERVER ):
         $rawpath = str_replace( '\\', '/', $_SERVER['HTTP_X_ORIGINAL_URL'] );
         break;
       case array_key_exists( 'HTTP_X_REWRITE_URL', $_SERVER ):
         $rawpath = str_replace( '\\', '/', $_SERVER['HTTP_X_REWRITE_URL'] );
         break;
       case array_key_exists( 'ORIG_PATH_INFO', $_SERVER ):
         $rawpath = str_replace( '\\', '/', $_SERVER['ORIG_PATH_INFO'] );
         break;
       default:
         trigger_error( 'USU5 cannot recreate REQUEST_URI for your windows server, please inform the developer.', E_USER_WARNING );
         break;
     }
     // Remove the directory path from the URI
     if ( DIR_WS_CATALOG != '/' ) {
       $rawpath = str_replace( DIR_WS_CATALOG, '', $rawpath );
     }
     $this->request_uri = trim( $rawpath, '/' ); 
   } // end method


   /**
   * Remove the session and sanitise remaining _GET variables
   * 
   * @param string $get - the querystring
   */
   private function sanitizeQuerystring( $get ) {     
     $get_array = explode( '&', $get );
     $newqs = '';
     foreach ( $get_array as $index => $stringpair ) {
       if ( false === strpos( $stringpair, tep_session_name() ) ) {
         $pair = explode( '=', $stringpair );
         if ( count( $pair ) == 2 ) {
           $stringpair = filter_var( $pair[0], FILTER_SANITIZE_STRING ) . '=' . usu::cleanse( $pair[1] ); 
         } else {
           $stringpair = filter_var( $stringpair, FILTER_SANITIZE_STRING );
         }
         $newqs .= '&' . $stringpair;  
       }
     }
     $this->querystring = ltrim( $newqs, '&' );
   }

   /**
   * Break up an seo url into component parts
   */
   private function extractByMarkers() {
     global $HTTP_GET_VARS;
     foreach ( usu::$registry->vars['markers'] as $marker => $qskey ) {
       if ( false !== strpos( $this->filestring, $marker ) ) {
         // Found an seo marker so explode into two component parts
         $tmp = explode( $marker, $this->filestring );
         // assign the key=>value pair to _GET
         $value =  ( false !== strpos( $tmp[1], '.html' ) ) ? usu::cleanse( str_replace( '.html', '', $tmp[1] ) ) : usu::cleanse( $tmp[1] ); 
         $_GET[$qskey] = $value;
         $HTTP_GET_VARS[$qskey] = $value;

         return $qskey . '=' .  $value;
       } 
     }
     return false;
   }

   /**
   * Check that we have an seo url
   */
   private function isSeoUrl( $linkstring ) {
     $linkstring = str_replace( '.html', '', $linkstring );
     foreach ( usu::$registry->vars['markers'] as $marker => $getkey ) {
       if ( false !== strpos( $linkstring, $marker ) ) {
         // Found an seo marker so explode into two component parts
         $linkarray = explode( $marker, $linkstring );
         // we seem to have found an seo url with the right values .. last check to ensure the value is valid
         if ( ( count( $linkarray ) == 2 ) && is_numeric( str_replace( '_', '', $linkarray[1] ) ) ) {
           return true;
         }
       }
     }
     // fell through to here so is not an seo url 
     return false;
   }

   // extract _GET from the "experimental" osC search engine friendly urls
   private function extractByDirSeparator() {
   global $HTTP_GET_VARS;  
     $tmp = explode( '/', $this->filestring );
     $count = count( $tmp );
     for ( $i=0; $i<$count; $i=$i+2 ) {
       $newget[filter_var( $tmp[$i], FILTER_SANITIZE_STRING )] = usu::cleanse( $tmp[$i+1] );
       // assign cleansed key=>value pair to _GET
       $_GET[filter_var( $tmp[$i], FILTER_SANITIZE_STRING )] = usu::cleanse( $tmp[$i+1] );
       $HTTP_GET_VARS[filter_var( $tmp[$i], FILTER_SANITIZE_STRING )] = usu::cleanse( $tmp[$i+1] );
     }
     // Newly created _GET array added to the querystring and converted to _GET string
     $getstring = http_build_query( $newget ) . '&' . $this->querystring;
     $this->querystring = rtrim( $getstring, '&' );
   }

   private function parsePath() {
     // get a brand new seo url
     $newlink = tep_href_link( $this->basename,  $this->querystring );
     // new seo url excluding all before the last /
     $stripleft = ltrim( strrchr( $newlink, '/' ), '/' );
     // remove any querystring
     $compare = str_replace( strrchr( $stripleft, '?' ), '', $stripleft );
     // If we haven't returned a valid seo url then the product/category etc does not exist
     if ( false === $this->isSeoUrl( $compare ) ) {
       $this->error404();
     }
     // we have a valid seo url return but the new seo url does not match the request .. so 301 redirect                                                                        
     if ( false === ( urldecode( $this->filestring ) == $compare ) ) {
       $this->redirect( $newlink );
     }
   }

   private function redirect( $link ) {
     // header redirects can not contain & (which are written by W3C option)
     if ( false !== strpos( $link, '&' ) ) {
       $link = str_replace( '&', '&', $link );
     }
     // write/close the session before redirect
     session_write_close();
     header( "HTTP/1.0 301 Moved Permanently" );
     header( 'Location: ' . $link );
     // always exit after an "attempted" redirect to stop the script "falling through"
     exit;
   }

   // we have decided the page does not exist so we will show our custom 404 error page and header
   private function error404(){
     session_write_close();
     header( "HTTP/1.0 404 Not Found" );
     include_once usu::$usuPath . 'includes' . DIRECTORY_SEPARATOR . 'notfound_404.php';
     exit;
   } 
 }
?>

Posted

Ok so i've changed it in the includes/configure.php file, do I need to change it somewhere else?

DIR_FS_CATALOG is in includes/configure.php. DIR_FS_DOCUMENT_ROOT is in admin/includes/configure.php. They only need to be worried about if you hardcoded the path into them, instead of using the default settings. You may also have includes/local/configure.php and/or admin/includes/local/configure.php, but that's unlikely.

Posted

Here is the full file, my hosting provider doesn't have a nice filemanager that shows the lines etc.

 

36      // Remove the osCsid and sanitise
37      $this->sanitizeQuerystring( $_SERVER['QUERY_STRING'] );

Next time, just count the lines by hand, starting with the <?php at line 1, and use cut and paste to snip out just a few lines. Or, cut and paste first into a scratch file on your PC, using a good text editor (such as ViM) which can tell you what line your cursor is on. Be careful when counting by hand if your editor wraps long lines around to a new line (rather than scrolling left and right) -- you don't want to count such a line twice.

 

Anyway, are you running an old level of PHP or an old level of osC? The QUERY_STRING element is apparently not guaranteed to exist. I don't know if this is always the correct fix, but hopefully it will eliminate the error message you were getting:

       // Remove the osCsid and sanitise
       if (isset($_SERVER['QUERY_STRING']))
            $this->sanitizeQuerystring( $_SERVER['QUERY_STRING'] );
       else
            $this->sanitizeQuerystring( '' );

Apparently the author didn't anticipate $_SERVER['QUERY_STRING'] not being set in some environments, so I would classify it as a bug in the add-on. I won't swear that the data needed to set the class's internal variables isn't lurking somewhere else! Are you using osC 2.2 MS2 or older on a PHP 5 system? I would think you would be getting a whole bunch of other errors if $HTTP_SERVER_VARS, etc. ($HTTP_GET_VARS, $HTTP_POST_VARS,...) weren't defined. You can try the above fix and if it seems to work, great. If it doesn't, contact the mod's author to see how they would recommend fixing it.

Posted

Next time, just count the lines by hand, starting with the <?php at line 1, and use cut and paste to snip out just a few lines. Or, cut and paste first into a scratch file on your PC, using a good text editor (such as ViM) which can tell you what line your cursor is on. Be careful when counting by hand if your editor wraps long lines around to a new line (rather than scrolling left and right) -- you don't want to count such a line twice.

 

Anyway, are you running an old level of PHP or an old level of osC? The QUERY_STRING element is apparently not guaranteed to exist. I don't know if this is always the correct fix, but hopefully it will eliminate the error message you were getting:

       // Remove the osCsid and sanitise
       if (isset($_SERVER['QUERY_STRING']))
            $this->sanitizeQuerystring( $_SERVER['QUERY_STRING'] );
       else
            $this->sanitizeQuerystring( '' );

Apparently the author didn't anticipate $_SERVER['QUERY_STRING'] not being set in some environments, so I would classify it as a bug in the add-on. I won't swear that the data needed to set the class's internal variables isn't lurking somewhere else! Are you using osC 2.2 MS2 or older on a PHP 5 system? I would think you would be getting a whole bunch of other errors if $HTTP_SERVER_VARS, etc. ($HTTP_GET_VARS, $HTTP_POST_VARS,...) weren't defined. You can try the above fix and if it seems to work, great. If it doesn't, contact the mod's author to see how they would recommend fixing it.

 

Thanks for the info, will attempt this now and see if it fixes it. The store is based on RC2 and my host is saying I have PHP Version:

5.2.12

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...