Question

Virtuemart Categories display Products don't

Asked by: encinitasbob

I've recently installed the VirtueMart_1.1.2_eCommerce_Bundle_Joomla_1.5.8  bundle

I'm a newbie to VM so please bear with me.

Site URL - http://www.airandbeauty.co.uk/VM/index.php

The home page in both random products and latest products displays correct product URLs.
The categories iPod (VM's Samples), Air Safety (Mine) and Beauty Products (mine) will take one to a category page.
Once on a category page however the linkss for all products are incorrect replacing a segment of the code -;

CORRECT "VM/index.php?page= . . "  with a BAD "VM/php.cgi?page= . . . "

Examples would be
http://www.airandbeauty.co.uk/VM/php.cgi?page=shop.product_details&flypage=flypage.tpl&product_id=39&category_id=14&option=com_virtuemart&Itemid=64   BAD

http://www.airandbeauty.co.uk/VM/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=39&category_id=14&option=com_virtuemart&Itemid=64  GOOD

The Site Error Log shows
[Tue Mar 17 20:38:48 2009] [error] [client 99.xxx.xx.xx.x.x] script not found or unable to stat: /domains/a/i/airandbeauty.co.uk/public_html/VM/php.cgi

I don't know much code but I can fix simple problems. And I certainly don't know where to look to find what is replacing index.php with php.cgi in VirtueMart.

 I have attached a pic of the VM Site Settings

Should I reinstall the virtuemart extensions? I've been to the Virtuemart forum but haven't got an answer.  One person suggested it might be an SEO helper in Joomla, but I have  all those settings turned off right now.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-03-17 at 14:23:26ID24239562
Tags

VirtueMart / Joomla

Topics

Web-Based CMS

,

PHP Scripting Language

,

Miscellaneous Web Development

Participating Experts
1
Points
500
Comments
12

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SEO
    Hello, I'm working on a extending a shopping cart to make it more search engine friendly, please have a look at the current site and give me advice, what other steps should I take, what other features should I include? For example as it is right now titles, meta keywords, m...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: brucepietersePosted on 2009-03-18 at 04:54:12ID: 23917561

Hi,

Is it possible to test under a different flypage and see if the links still show php.cgi?...

 

by: encinitasbobPosted on 2009-03-18 at 09:34:03ID: 23920576

I've tested all 6 of the flypage settings. The links from categories continue to have php.cgi  
The recently viewed products links also have the improper  php.cgi.

 

by: brucepietersePosted on 2009-03-19 at 00:24:19ID: 23927041

Hmmm, I had a look a the forums, there's an ugly hack to get around that. Could you post administrator/components/com_virtuemart/classes/ps_session.php so I can edit it for you.

Thanks

 

by: brucepietersePosted on 2009-03-19 at 00:24:55ID: 23927043

What version of PHP are you using? Are you using SOAP as well?

 

by: encinitasbobPosted on 2009-03-19 at 08:47:23ID: 23930813

PHP Version 4.4.7
Sorry. I don't know what SOAP is.  How do I find out?

<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @version $Id: ps_session.php 1526 2008-09-15 19:21:43Z soeren_nb $
* @package VirtueMart
* @subpackage classes
* @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/


/**
 * This class handles the session initialization, restart
 * and the re-init of a session after redirection to a Shared SSL domain
 *
 */
class ps_session {

      var $component_name;
      var $_session_name = 'virtuemart';
      /**
     * Initialize the Session environment for VirtueMart
     *
     */
      function ps_session() {
            
            $this->component_name = 'option='.VM_COMPONENT_NAME;
            
            $this->initSession();
      }
      /**
     * Initiate the Session
     *
     */
      function initSession() {
            global $vmLogger, $mainframe, $mosConfig_absolute_path, $VM_LANG;
            
            // We only care for the session if it is not started!
            if( empty( $_SESSION ) || session_id() == '') {
                  
                  if(ini_get('session.session_save_handler') == 'files') {
                        // Check if the session_save_path is writable
                        $this->checkSessionSavePath();
                  }
                  session_name( $this->_session_name );
                  
                  if( @$_REQUEST['option'] == 'com_virtuemart' ) {
                        ob_start();// Fix for the issue that printed the shop contents BEFORE the page begin
                  }
                  @session_start();
                  
                  if( !empty($_SESSION) && !empty($_COOKIE[$this->_session_name])) {
                        $vmLogger->debug( 'A Session called '.$this->_session_name.' (ID: '.session_id().') was successfully started!' );
                  }
                  else {
                  }
            }
            else {
                  if( empty( $_COOKIE['virtuemart']) && !vmIsJoomla('1.5', '>=')) {
                        $_COOKIE['virtuemart'] = $this->getSessionId();                  
                        if( USE_AS_CATALOGUE == '' ) {
                              $vmLogger->debug( 'A Cookie had to be set to keep the session (there was none - does your Browser keep the Cookie?) although a Session already has been started! If you see this message on each page load, your browser doesn\'t accept Cookies from this site.' );
                        }
                  }
                  $vmLogger->debug( 'Using existing Session '.session_name().', ID: '.session_id().'.');
            }
            // Cookie Check
            // Introduced to check if the user-agent accepts cookies
            if( @$_REQUEST['option'] == 'com_virtuemart' && empty($_GET['martID'])
                  && USE_AS_CATALOGUE != '1' && VM_ENABLE_COOKIE_CHECK == '1' && !vmIsAdminMode() ) {
                  $this->doCookieCheck();
            }
      }
      /**
       * Checks if the user-agent accepts cookies
       * @since VirtueMart 1.0.7
       * @author soeren
       */
      function doCookieCheck() {
            global $mm_action_url, $VM_LANG;
            
            $doCheck = vmGet( $_REQUEST, 'vmcchk', 0 );
            $isOK = vmGet( $_SESSION, 'VMCHECK' );
            
            if( $doCheck && $isOK != 'OK' ) {
                  $GLOBALS['vmLogger']->info( $VM_LANG->_('VM_SESSION_COOKIES_NOT_ACCEPTED_TIP',false) );
            }
            elseif( empty( $isOK )) {
                  $_SESSION['VMCHECK'] = 'OK';
                  $query_string = vmGet($_SERVER,'QUERY_STRING');
                  if( !empty($query_string) && empty( $_POST )) {
                        vmRedirect( $this->url( $mm_action_url . 'index.php?' .$query_string .'&vmcchk=1', true, false ));
                  }
            }
      }
            
      /**
       * Returns the Joomla/Mambo Session ID
       * @static
       */
      function getSessionId() {
            global $mainframe;
            // Joomla >= 1.0.8
            if( is_callable( array( 'mosMainframe', 'sessionCookieName'))) {                  
                  // Session Cookie `name`
                  $sessionCookieName       = mosMainFrame::sessionCookieName();
                  // Get Session Cookie `value`
                  $sessionCookie             = vmGet( $_COOKIE, $sessionCookieName, null );
                  // Session ID / `value`
                  return mosMainFrame::sessionCookieValue( $sessionCookie );
                  
            }
            // Mambo 4.6
            elseif( is_callable( array('mosSession', 'getCurrent' ))) {
                  $session =& mosSession::getCurrent();
                  return $session->session_id;
            }
            // Mambo <= 4.5.2.3 and Joomla <= 1.0.7
            elseif( !empty( $mainframe->_session->session_id )) {
                  // Set the sessioncookie if its missing
                  // this is needed for joomla sites only
                  return $mainframe->_session->session_id;
            }
            else {
                  return session_id();
            }
      }
      /**
       * This function returns a base64_encoded string:
       * VMsessionId|JsessionID
       *
       */
      function getMartId() {
            global $vmuser, $mosConfig_secret;
            
            // Get the Joomla! / Mambo session ID
            $sessionId = ps_session::getSessionId();
            
            $userNameSeed = '';
            if( $vmuser->id ) {
                  $userNameSeed = '|'.md5( $vmuser->username . $vmuser->password . $mosConfig_secret );
                  if( is_callable(array('mosMainFrame', 'remCookieName_User'))) {
                        if( !empty( $GLOBALS['real_mosConfig_live_site'] ) && empty( $_REQUEST['real_mosConfig_live_site'])) {
                              $GLOBALS['mosConfig_live_site'] = $GLOBALS['real_mosConfig_live_site'];
                        }
                        $userNameSeed .= '|' . vmGet( $_COOKIE, mosMainFrame::remCookieName_User(), '' );
                  }
            }
            
            $martID = base64_encode( vmCreateHash($_COOKIE[$this->_session_name] . $sessionId) . $userNameSeed );
            return $martID;
      }
      /**
       * Saves the session contents to a file (so they the session can be continued later on) and does a redirect
       *
       * @param boolean $toSecure Redirect to a https or http domain?
       */
      function saveSessionAndRedirect( $toSecure = true ) {
            $martID = $this->getMartId();
                        
            $sessionFile = IMAGEPATH. md5( $martID ).'.sess';
            $session_contents = session_encode();
            
            if( file_exists( ADMINPATH.'install.copy.php')) {
                  require_once( ADMINPATH.'install.copy.php');
            }
            
            file_put_contents( $sessionFile, $session_contents );
            
            $url = $toSecure ? SECUREURL : URL;
            
            // Redirect and send the Cookie Values within the variable martID
            vmRedirect( $this->url( $url . basename($_SERVER['PHP_SELF']).'?'.vmGet($_SERVER,'QUERY_STRING')."&martID=$martID&redirected=1", true, false, true ) );
      }
      /**
       * It does what the name says. It starts a session again (with a certain ID when a $sid is given)
       *
       * @param string $sid
       */
      function restartSession( $sid = '') {
            
            // Save the session data and close the session
            session_write_close();
            
            // Prepare the new session
            if( $sid != '' ) {
                  session_id( $sid );
            }
            session_name( $this->_session_name );
            // Start the new Session.
            session_start();
            
      }
      
      function emptySession() {
            global $mainframe;
            $_SESSION = array();
            $_COOKIE[$this->_session_name] = md5( $this->getSessionId() );
      }
      /**
     * This is a solution for  the Shared SSL problem
     * We have to copy some cookies from the Main Mambo site domain into
     * the shared SSL domain (only when necessary!)
       *
       * The function is called on each page load.
       */
      function prepare_SSL_Session() {
            global $mainframe, $my, $database, $mosConfig_secret, $page, $VM_MODULES_FORCE_HTTPS;
            if( vmIsAdminMode() && vmIsJoomla('1.0')) {
                  return;
            }
            $ssl_redirect = vmGet( $_GET, "ssl_redirect", 0 );
            $redirected = vmGet( $_GET, "redirected", 0 );
            $martID = vmGet( $_GET, 'martID', '' );
            $ssl_domain = "";
            
            if (!empty( $VM_MODULES_FORCE_HTTPS )) {
                  $pagearr = explode( '.', $page );
                  $module = $pagearr[0];
                  // When NOT in https mode, but the called page is part of a shop module that is
                  // forced to use https, we prepare the redirection to https here
                  if( array_search( $module, $VM_MODULES_FORCE_HTTPS ) !== false
                        && !vmIsHttpsMode()
                        && $this->check_Shared_SSL( $ssl_domain )
                        ) {
                              
                        $ssl_redirect = 1;
                  }
            }
            // Generally redirect to HTTP (from HTTPS) when it is not necessary? (speed up the pageload)
            if( VM_GENERALLY_PREVENT_HTTPS == '1'
                  && vmIsHttpsMode() && $redirected != 1
                  && $ssl_redirect == 0 && !vmIsAdminMode()
                  && URL != SECUREURL
                  && @$_REQUEST['option']=='com_virtuemart') {
                        
                  $pagearr = explode( '.', $page );
                  $module = $pagearr[0];
                  
                  // When it is not necessary to stay in https mode, we leave it here
                  if( array_search( $module, $VM_MODULES_FORCE_HTTPS ) === false ) {
                        if( $this->check_Shared_SSL($ssl_domain)) {
                              $this->saveSessionAndRedirect( false );
                        }
                        $query_string = vmGet($_SERVER,'QUERY_STRING');
                        if( !empty($query_string) && empty( $_POST )) {
                              vmRedirect( $this->url( URL.basename( $_SERVER['PHP_SELF']).'?'.vmGet($_SERVER,'QUERY_STRING').'&redirected=1', true, false, true ));
                        }
                  }
            }
            
            /**
        * This is the first part of the Function:
        * We check if the function must be called at all
        * Usually this is only called once: Before we go to the checkout.
        * The variable ssl_redirect=1 is appended to the URL, just for this function knows
        * is must be active! This has nothing to do with SSL / Shared SSL or whatever
        */
            if( $ssl_redirect == 1 ) {
                  
                  $_SERVER['QUERY_STRING'] = str_replace('&ssl_redirect=1', '', vmGet($_SERVER, 'QUERY_STRING' ) );
                  // check_Shared_SSL compares the normal http domain name
                  // and the https Domain Name. If both do not match, we move on
                  // else we leave this function.
                  if( $this->check_Shared_SSL( $ssl_domain ) && !vmIsHttpsMode() && $redirected == 0) {
                        
                        $this->saveSessionAndRedirect( true );
                  }
                  // do nothing but redirect
                  elseif( !vmIsHttpsMode() && $redirected == 0 ) {
                        vmRedirect( $this->url(SECUREURL . basename($_SERVER['PHP_SELF'])."?".vmGet($_SERVER,'QUERY_STRING').'&redirected=1', true, false, true ) );
                  }
            }
            /**
        * This is part two of the function
        * If the redirect (see 4/5 lines above) was successful
        * and the Store uses Shared SSL, we have the variable martID
        * So let's copy the Session contents ton the new domain and start the session again
        * othwerwise: do nothing.
        */
            if( !empty( $martID ) ) {
                  
                  if( $this->check_Shared_SSL( $ssl_domain ) ) {
      
                        // We now need to copy the Session Data to the SSL Domain
                        if( $martID ) {                              
                              
                              require_once( ADMINPATH.'install.copy.php');
                              
                              $sessionFile = IMAGEPATH. md5( $martID ).'.sess';
                              
                              // Read the contents of the session file
                              $session_data = file_get_contents( $sessionFile );
                              
                              // Delete it for security and disk space reasons
                              unlink( $sessionFile );
                              
                              // Read the session data into $_SESSION
                              // From now on, we can use all the data in $_SESSION
                              session_decode( $session_data );
                              
                              $check = base64_decode( $martID );
                              $checkValArr = explode( "|", $check );
                              
                              if( defined('_JEXEC') ) {
                                    //TODO
                              }
                              elseif( class_exists('mambocore')) {
                                    //TODO
                              }
                              elseif( $GLOBALS['_VERSION']->RELEASE == '1.0' && (int)$GLOBALS['_VERSION']->DEV_LEVEL >= 13) {
                                    if( !empty( $GLOBALS['real_mosConfig_live_site'] ) && empty( $_REQUEST['real_mosConfig_live_site'])) {
                                          $GLOBALS['mosConfig_live_site'] = $GLOBALS['real_mosConfig_live_site'];
                                    }
                                    if( !empty( $checkValArr[2] )) {
                                          // Joomla! >= 1.0.13 can be cheated to log in a user who has previsously logged in and checked the "Remember me" box
                                          setcookie( mosmainframe::remCookieName_User(), $checkValArr[2], false, '/' );
                                          // there's no need to call "$mainframe->login"
                                    }
                              } else {
                                    // Check if the user was logged in in the http domain
                                    // and is not yet logged in at the Shared SSL domain
                                    if( isset( $checkValArr[1] ) && !$my->id ) {
                                          // user should expect to be logged in,
                                          // we can use the values from $_SESSION['auth'] now
                                          $username = $database->getEscaped( trim( $_SESSION['auth']['user_name'] ) );
                                          if( !empty( $username )) {
                                                $database->setQuery('SELECT username, password FROM `#__users` WHERE `username` = \''.$username.'\';');
                                                $database->loadObject( $user );
                                                if( is_object( $user )) {
                                                      // a last security check using the transmitted md5 hash and the rebuilt hash
                                                      $check = md5( $user->username . $user->password . $mosConfig_secret );
                                                      if( $check === $checkValArr[1] ) {
                                                            // Log the user in with his username
                                                            $mainframe->login( $user->username, $user->password );
                                                      }
                                                }
                                                
                                          }
                                    }
                              }
                                                      
                              
                              session_write_close();
                              
                              // Prevent the martID from being displayed in the URL
                              if( !empty( $_GET['martID'] )) {
                                    $query_string = substr_replace( vmGet($_SERVER,'QUERY_STRING'), '', strpos( vmGet($_SERVER,'QUERY_STRING'), '&martID'));
                                    $url = vmIsHttpsMode() ? SECUREURL : URL;
                                    vmRedirect( $this->url( $url . "index.php?$query_string&cartReset=N&redirected=1", true, false, true) );
                              }
      
                        }
      
                  }
            }
      }
      /**
       * This function compares the store URL with the SECUREURL
       * and returns the result
       *
       * @param string $ssl_domain The SSL domain (empty string to be filled here)
       * @return boolean True when we have to do a SSL redirect (for Shared SSL)
       */
      function check_Shared_SSL( &$ssl_domain ) {
            
            if( URL == SECUREURL ) {
                  $ssl_domain = str_replace("http://", "", URL );
                  $ssl_redirect = false;
                  return $ssl_redirect;
            }
            
            // Extract the Domain Names without the Protocol
            $domain = str_replace("http://", "", URL );
            $ssl_domain = str_replace("https://", "", SECUREURL );
            // If SSL and normal Domain do not match,
            // we assume that you use Shared SSL

            if( $ssl_domain != $domain ) {
                  $ssl_redirect = true;
            }
            else {
                  $ssl_redirect = false;
            }

            return $ssl_redirect;
      }
      /**
       * Correct the session save path if necessary
       * or generate an error if the save path can't be corrected
       *
       * @return mixed
       */
      function checkSessionSavePath() {
            global $mosConfig_absolute_path, $VM_LANG, $vmLogger;
            
            if( !@is_writable( session_save_path()) ) {
                  // If the session save path is not writable this can have different
                  // reasons. One reason is that the open_basedir directive is set, but
                  // doesn't include the session_save_path
                  $open_basedir = @ini_get('open_basedir'); // Get the list of allowed directories
                  if( !empty($open_basedir)) {
                        switch( substr( strtoupper( PHP_OS ), 0, 3 ) ) {
                              case "WIN":
                                    $basedirs = explode(';', $open_basedir );
                                    break;
                              case "MAC": // fallthrough
                              case "DAR": // Does PHP_OS return 'Macintosh' or 'Darwin' ?
                              default: // change nothing
                                    $basedirs = explode(':', $open_basedir );
                                    break;
                              break;
                        }
                        $session_save_path_is_allowed_directory = false;
                        foreach ( $basedirs as $basedir ) {
                              $basedir_strlen = strlen( $basedir );
                              // If the session save path is a subdirectory of a directory allowed by open_basedir
                              // we need to do further investigation
                              if( strtolower( substr( session_save_path(), 0, $basedir_strlen )) == $basedir ) {
                                    $session_save_path_is_allowed_directory = true;
                              }
                        }
                        if( !$session_save_path_is_allowed_directory) {
                              // PHP Sessions can be stored in a session save path which is not
                              // allowed through open_basedir!
                              return true;
                        }
                  }
                  $try_these_paths = array( 'Cache Path' => $mosConfig_absolute_path. '/cache',
                                                            'Media Directory' => $mosConfig_absolute_path.'/media',
                                                            'Shop Image Directory' => IMAGEPATH );
                  foreach( $try_these_paths as $name => $session_save_path ) {
                        if( @is_writable( $session_save_path )) {
                              $vmLogger->debug( sprintf( $VM_LANG->_('VM_SESSION_SAVEPATH_UNWRITABLE_TMPFIX',false), session_save_path(), $name));
                              session_save_path( $session_save_path );
                              break;
                        }
                  }
            }
            // If the path is STILL not writable, generate an error
            if( !@is_writable( session_save_path()) ) {
                  $vmLogger->err( $VM_LANG->_('VM_SESSION_SAVEPATH_UNWRITABLE',false) );
            }
      }
      /**
     * Gets the Itemid for the com_virtuemart Component
     * and stores it in a global Variable
     *
     * @return int Itemid
     */
      function getShopItemid() {

            if( empty( $_REQUEST['shopItemid'] )) {
                  $db = new ps_DB;
                  $db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
                  if( $db->next_record() ) {
                        $_REQUEST['shopItemid'] = $db->f("id");
                  }
                  else {
                        if( !empty( $_REQUEST['Itemid'] )) {
                              $_REQUEST['shopItemid'] = intval( $_REQUEST['Itemid'] );
                        }
                        else {
                              $_REQUEST['shopItemid'] = 1;
                        }
                  }
            }

            return intval($_REQUEST['shopItemid']);

      }
      
      /**
       * Prints a reformatted URL
       *
       * @param string $text
       */
      function purl($text, $createAbsoluteURI=false, $encodeAmpersands=true, $ignoreSEF=false) {            
            echo $this->url( $text, $createAbsoluteURI, $encodeAmpersands, $ignoreSEF );            
      }
      
      /**
       * This reformats an URL, appends "option=com_virtuemart" and "Itemid=XX"
       * where XX is the Id of an entry in the table mos_menu with "link: option=com_virtuemart"
       * It also calls sefRelToAbs to apply SEF formatting
       *
       * @param string $text THE URL
       * @param boolean False: Create a URI like /joomla/index.php?....; True: Create a URI like http://www.domain.com/index.php?....
       * @return string The reformatted URL
       */
      function url($text, $createAbsoluteURI=false, $encodeAmpersands=true, $ignoreSEF=false ) {
            global $mm_action_url, $page, $mainframe;
            
            if( !defined( '_VM_IS_BACKEND' )) {
                  $Itemid = "&Itemid=".$this->getShopItemid();
            }
            else {
                  $Itemid = '';
            }

            switch ($text) {
                  case SECUREURL:
                        $text =  SECUREURL.basename( $_SERVER['SCRIPT_NAME'] )."?".$this->component_name.$Itemid;
                        break;
                  case URL:
                        $text =  URL.basename( $_SERVER['SCRIPT_NAME'] )."?".$this->component_name.$Itemid;
                        break;
                        
                  default:
                        $limiter = strpos($text, '?');
                        if( !stristr( $text, $_SERVER['SCRIPT_NAME']) && $limiter === false ) {
                              $text = '?'.$text;
                        }
                        $appendix = "";
                        // now append "&option=com_virtuemart&Itemid=XX"
                        if (!strstr($text, "option=")) {
                              $appendix .= "&" . $this->component_name;
                        }
                        $appendix .= $Itemid;
                        
                        $script = basename( substr( $text, 0, $limiter ));
                        if( $script == '' ) {
                              $script = basename( $_SERVER['SCRIPT_NAME'] );
                        }
                        
                        if (!defined( '_VM_IS_BACKEND' )) {
                              if( $script == 'index3.php') {
                                    $script = 'index2.php'; // index3.php is not available in the frontend!
                              }
      
                              $appendix = $script.substr($text, $limiter, strlen($text)).$appendix;
                        
                              if( class_exists('JRoute') && !$ignoreSEF && $mainframe->getCfg('sef') ) {
                                    $appendix = JRoute::_( str_replace( $script.'&', $script.'?', $appendix ) );
                                    
                              }
                              else if( function_exists('sefRelToAbs') && !$ignoreSEF && !defined( '_JLEGACY' ) ) {
                                    $appendix = sefRelToAbs( str_replace( $script.'&', $script.'?', $appendix ) );
                              }
                              if( $createAbsoluteURI && substr($appendix,0,4)!='http'  && ($ignoreSEF || !$mainframe->getCfg('sef')) ) {
                                    $appendix = URL . $appendix;
                              }
                              
                              
                        }
                        elseif( $_SERVER['SERVER_PORT'] == 443 ) {
                              //$script = strstr($_SERVER['PHP_SELF'], 'index2.php') ? 'index2.php' : 'index3.php';
                              
                              $appendix = SECUREURL."administrator/$script".substr($text, $limiter, strlen($text)-1).$appendix;
                        }
                        else {
                              //$script = strstr($_SERVER['PHP_SELF'], 'index2.php') ? 'index2.php' : 'index3.php';
                              $appendix = URL."administrator/$script".substr($text, $limiter, strlen($text)-1).$appendix;
                        }
                        if( vmIsAdminMode() && strstr($text, 'func') !== false ) {
                              $appendix .= '&vmtoken='.vmSpoofValue($this->getSessionId());
                        }
                        if ( stristr($text, SECUREURL)) {
                              $appendix = str_replace(URL, SECUREURL, $appendix);
                        }
                        elseif( stristr($text, URL) && $createAbsoluteURI ) {
                              $appendix = str_replace(SECUREURL, URL, $appendix);
                        }
      
                        $text = $appendix;
      
                        break;
            }
            if( $encodeAmpersands ) {
              $text = vmAmpReplace( $text );
          }  else {
            $text = str_replace( '&amp;', '&', $text );
          }
            return $text;
      }

      /**
       * Formerly printed the session id into a hidden field
       * @deprecated
       * @return boolean
       */
      function hidden_session() {
            return true;
      }

      function initRecentProducts() {
            global $recentproducts, $sess;
            // Register the recentproducts
            if (empty($_SESSION['recent'])) {
                  $recentproducts = array();
                  $recentproducts['idx'] = 0;
                  $_SESSION['recent'] = $recentproducts;
                  return $recentproducts;
            }
            
            return $_SESSION['recent'];
      }

} // end of class session
?>

 

by: encinitasbobPosted on 2009-03-19 at 08:49:28ID: 23930838

classes/ps_session.php attached

<?php 
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @version $Id: ps_session.php 1526 2008-09-15 19:21:43Z soeren_nb $
* @package VirtueMart
* @subpackage classes
* @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/
 
 
/**
 * This class handles the session initialization, restart
 * and the re-init of a session after redirection to a Shared SSL domain
 *
 */
class ps_session {
 
	var $component_name;
	var $_session_name = 'virtuemart';
	/**
     * Initialize the Session environment for VirtueMart
     *
     */
	function ps_session() {
		
		$this->component_name = 'option='.VM_COMPONENT_NAME;
		
		$this->initSession();
	}
	/**
     * Initiate the Session
     *
     */
	function initSession() {
		global $vmLogger, $mainframe, $mosConfig_absolute_path, $VM_LANG;
		
		// We only care for the session if it is not started!
		if( empty( $_SESSION ) || session_id() == '') {
			
			if(ini_get('session.session_save_handler') == 'files') {
				// Check if the session_save_path is writable
				$this->checkSessionSavePath();
			}
			session_name( $this->_session_name );
			
			if( @$_REQUEST['option'] == 'com_virtuemart' ) {
				ob_start();// Fix for the issue that printed the shop contents BEFORE the page begin
			}
			@session_start();
			
			if( !empty($_SESSION) && !empty($_COOKIE[$this->_session_name])) {
				$vmLogger->debug( 'A Session called '.$this->_session_name.' (ID: '.session_id().') was successfully started!' );
			}
			else {
			}
		}
		else {
			if( empty( $_COOKIE['virtuemart']) && !vmIsJoomla('1.5', '>=')) {
				$_COOKIE['virtuemart'] = $this->getSessionId();			
				if( USE_AS_CATALOGUE == '' ) {
					$vmLogger->debug( 'A Cookie had to be set to keep the session (there was none - does your Browser keep the Cookie?) although a Session already has been started! If you see this message on each page load, your browser doesn\'t accept Cookies from this site.' );
				}
			}
			$vmLogger->debug( 'Using existing Session '.session_name().', ID: '.session_id().'.');
		}
		// Cookie Check
		// Introduced to check if the user-agent accepts cookies
		if( @$_REQUEST['option'] == 'com_virtuemart' && empty($_GET['martID']) 
			&& USE_AS_CATALOGUE != '1' && VM_ENABLE_COOKIE_CHECK == '1' && !vmIsAdminMode() ) {
			$this->doCookieCheck();
		}
	}
	/**
	 * Checks if the user-agent accepts cookies
	 * @since VirtueMart 1.0.7
	 * @author soeren
	 */
	function doCookieCheck() {
		global $mm_action_url, $VM_LANG;
		
		$doCheck = vmGet( $_REQUEST, 'vmcchk', 0 );
		$isOK = vmGet( $_SESSION, 'VMCHECK' );
		
		if( $doCheck && $isOK != 'OK' ) {
			$GLOBALS['vmLogger']->info( $VM_LANG->_('VM_SESSION_COOKIES_NOT_ACCEPTED_TIP',false) );
		}
		elseif( empty( $isOK )) {
			$_SESSION['VMCHECK'] = 'OK';
			$query_string = vmGet($_SERVER,'QUERY_STRING');
			if( !empty($query_string) && empty( $_POST )) {
				vmRedirect( $this->url( $mm_action_url . 'index.php?' .$query_string .'&vmcchk=1', true, false ));
			}
		}
	}
		
	/**
	 * Returns the Joomla/Mambo Session ID
	 * @static 
	 */
	function getSessionId() {
		global $mainframe;
		// Joomla >= 1.0.8
		if( is_callable( array( 'mosMainframe', 'sessionCookieName'))) {			
			// Session Cookie `name`
			$sessionCookieName 	= mosMainFrame::sessionCookieName();
			// Get Session Cookie `value`
			$sessionCookie 		= vmGet( $_COOKIE, $sessionCookieName, null );
			// Session ID / `value`
			return mosMainFrame::sessionCookieValue( $sessionCookie );
			
		}
		// Mambo 4.6
		elseif( is_callable( array('mosSession', 'getCurrent' ))) {
			$session =& mosSession::getCurrent();
			return $session->session_id;
		}
		// Mambo <= 4.5.2.3 and Joomla <= 1.0.7
		elseif( !empty( $mainframe->_session->session_id )) {
			// Set the sessioncookie if its missing
			// this is needed for joomla sites only
			return $mainframe->_session->session_id;
		}
		else {
			return session_id();
		}
	}
	/**
	 * This function returns a base64_encoded string:
	 * VMsessionId|JsessionID
	 *
	 */
	function getMartId() {
		global $vmuser, $mosConfig_secret;
		
		// Get the Joomla! / Mambo session ID
		$sessionId = ps_session::getSessionId();
		
		$userNameSeed = '';
		if( $vmuser->id ) {
			$userNameSeed = '|'.md5( $vmuser->username . $vmuser->password . $mosConfig_secret );
			if( is_callable(array('mosMainFrame', 'remCookieName_User'))) {
				if( !empty( $GLOBALS['real_mosConfig_live_site'] ) && empty( $_REQUEST['real_mosConfig_live_site'])) {
					$GLOBALS['mosConfig_live_site'] = $GLOBALS['real_mosConfig_live_site'];
				}
				$userNameSeed .= '|' . vmGet( $_COOKIE, mosMainFrame::remCookieName_User(), '' );
			}
		}
		
		$martID = base64_encode( vmCreateHash($_COOKIE[$this->_session_name] . $sessionId) . $userNameSeed );
		return $martID;
	}
	/**
	 * Saves the session contents to a file (so they the session can be continued later on) and does a redirect
	 *
	 * @param boolean $toSecure Redirect to a https or http domain?
	 */
	function saveSessionAndRedirect( $toSecure = true ) {
		$martID = $this->getMartId();
				
		$sessionFile = IMAGEPATH. md5( $martID ).'.sess';
		$session_contents = session_encode();
		
		if( file_exists( ADMINPATH.'install.copy.php')) {
			require_once( ADMINPATH.'install.copy.php');
		}
		
		file_put_contents( $sessionFile, $session_contents );
		
		$url = $toSecure ? SECUREURL : URL;
		
		// Redirect and send the Cookie Values within the variable martID
		vmRedirect( $this->url( $url . basename($_SERVER['PHP_SELF']).'?'.vmGet($_SERVER,'QUERY_STRING')."&martID=$martID&redirected=1", true, false, true ) );
	}
	/**
	 * It does what the name says. It starts a session again (with a certain ID when a $sid is given)
	 *
	 * @param string $sid
	 */
	function restartSession( $sid = '') {
		
		// Save the session data and close the session
		session_write_close();
		
		// Prepare the new session
		if( $sid != '' ) {
			session_id( $sid );
		}
		session_name( $this->_session_name );
		// Start the new Session.
		session_start();
		
	}
	
	function emptySession() {
		global $mainframe;
		$_SESSION = array();
		$_COOKIE[$this->_session_name] = md5( $this->getSessionId() );
	}
	/**
     * This is a solution for  the Shared SSL problem
     * We have to copy some cookies from the Main Mambo site domain into
     * the shared SSL domain (only when necessary!)
	 *
	 * The function is called on each page load.
	 */
	function prepare_SSL_Session() {
		global $mainframe, $my, $database, $mosConfig_secret, $page, $VM_MODULES_FORCE_HTTPS;
		if( vmIsAdminMode() && vmIsJoomla('1.0')) {
			return;
		}
		$ssl_redirect = vmGet( $_GET, "ssl_redirect", 0 );
		$redirected = vmGet( $_GET, "redirected", 0 );
		$martID = vmGet( $_GET, 'martID', '' );
		$ssl_domain = "";
		
		if (!empty( $VM_MODULES_FORCE_HTTPS )) {
			$pagearr = explode( '.', $page );
			$module = $pagearr[0];
			// When NOT in https mode, but the called page is part of a shop module that is
			// forced to use https, we prepare the redirection to https here
			if( array_search( $module, $VM_MODULES_FORCE_HTTPS ) !== false 
				&& !vmIsHttpsMode()
				&& $this->check_Shared_SSL( $ssl_domain ) 
				) {
					
				$ssl_redirect = 1;
			}
		}
		// Generally redirect to HTTP (from HTTPS) when it is not necessary? (speed up the pageload)
		if( VM_GENERALLY_PREVENT_HTTPS == '1' 
			&& vmIsHttpsMode() && $redirected != 1
			&& $ssl_redirect == 0 && !vmIsAdminMode()
			&& URL != SECUREURL
			&& @$_REQUEST['option']=='com_virtuemart') {
				
			$pagearr = explode( '.', $page );
			$module = $pagearr[0];
			
			// When it is not necessary to stay in https mode, we leave it here
			if( array_search( $module, $VM_MODULES_FORCE_HTTPS ) === false ) {
				if( $this->check_Shared_SSL($ssl_domain)) {
					$this->saveSessionAndRedirect( false );
				}
				$query_string = vmGet($_SERVER,'QUERY_STRING');
				if( !empty($query_string) && empty( $_POST )) {
					vmRedirect( $this->url( URL.basename( $_SERVER['PHP_SELF']).'?'.vmGet($_SERVER,'QUERY_STRING').'&redirected=1', true, false, true ));
				}
			}
		}
		
		/**
        * This is the first part of the Function:
        * We check if the function must be called at all
        * Usually this is only called once: Before we go to the checkout.
        * The variable ssl_redirect=1 is appended to the URL, just for this function knows
        * is must be active! This has nothing to do with SSL / Shared SSL or whatever
        */
		if( $ssl_redirect == 1 ) {
			
			$_SERVER['QUERY_STRING'] = str_replace('&ssl_redirect=1', '', vmGet($_SERVER, 'QUERY_STRING' ) );
			// check_Shared_SSL compares the normal http domain name
			// and the https Domain Name. If both do not match, we move on
			// else we leave this function.
			if( $this->check_Shared_SSL( $ssl_domain ) && !vmIsHttpsMode() && $redirected == 0) {
				
				$this->saveSessionAndRedirect( true );
			}
			// do nothing but redirect
			elseif( !vmIsHttpsMode() && $redirected == 0 ) {
				vmRedirect( $this->url(SECUREURL . basename($_SERVER['PHP_SELF'])."?".vmGet($_SERVER,'QUERY_STRING').'&redirected=1', true, false, true ) );
			}
		}
		/**
        * This is part two of the function
        * If the redirect (see 4/5 lines above) was successful
        * and the Store uses Shared SSL, we have the variable martID
        * So let's copy the Session contents ton the new domain and start the session again
        * othwerwise: do nothing.
        */
		if( !empty( $martID ) ) {
			
			if( $this->check_Shared_SSL( $ssl_domain ) ) {
	
				// We now need to copy the Session Data to the SSL Domain
				if( $martID ) {					
					
					require_once( ADMINPATH.'install.copy.php');
					
					$sessionFile = IMAGEPATH. md5( $martID ).'.sess';
					
					// Read the contents of the session file
					$session_data = file_get_contents( $sessionFile );
					
					// Delete it for security and disk space reasons
					unlink( $sessionFile );
					
					// Read the session data into $_SESSION
					// From now on, we can use all the data in $_SESSION
					session_decode( $session_data );
					
					$check = base64_decode( $martID );
					$checkValArr = explode( "|", $check );
					
					if( defined('_JEXEC') ) {
						//TODO
					}
					elseif( class_exists('mambocore')) {
						//TODO
					}
					elseif( $GLOBALS['_VERSION']->RELEASE == '1.0' && (int)$GLOBALS['_VERSION']->DEV_LEVEL >= 13) {
						if( !empty( $GLOBALS['real_mosConfig_live_site'] ) && empty( $_REQUEST['real_mosConfig_live_site'])) {
							$GLOBALS['mosConfig_live_site'] = $GLOBALS['real_mosConfig_live_site'];
						}
						if( !empty( $checkValArr[2] )) {
							// Joomla! >= 1.0.13 can be cheated to log in a user who has previsously logged in and checked the "Remember me" box
							setcookie( mosmainframe::remCookieName_User(), $checkValArr[2], false, '/' );
							// there's no need to call "$mainframe->login"
						}
					} else {
						// Check if the user was logged in in the http domain
						// and is not yet logged in at the Shared SSL domain
						if( isset( $checkValArr[1] ) && !$my->id ) {
							// user should expect to be logged in,
							// we can use the values from $_SESSION['auth'] now
							$username = $database->getEscaped( trim( $_SESSION['auth']['user_name'] ) );
							if( !empty( $username )) {
								$database->setQuery('SELECT username, password FROM `#__users` WHERE `username` = \''.$username.'\';');
								$database->loadObject( $user );
								if( is_object( $user )) {
									// a last security check using the transmitted md5 hash and the rebuilt hash
									$check = md5( $user->username . $user->password . $mosConfig_secret );
									if( $check === $checkValArr[1] ) {
										// Log the user in with his username
										$mainframe->login( $user->username, $user->password );
									}
								}
								
							}
						}
					}
									
					
					session_write_close();
					
					// Prevent the martID from being displayed in the URL
					if( !empty( $_GET['martID'] )) {
						$query_string = substr_replace( vmGet($_SERVER,'QUERY_STRING'), '', strpos( vmGet($_SERVER,'QUERY_STRING'), '&martID'));
						$url = vmIsHttpsMode() ? SECUREURL : URL;
						vmRedirect( $this->url( $url . "index.php?$query_string&cartReset=N&redirected=1", true, false, true) );
					}
	
				}
	
			}
		}
	}
	/**
	 * This function compares the store URL with the SECUREURL
	 * and returns the result
	 *
	 * @param string $ssl_domain The SSL domain (empty string to be filled here)
	 * @return boolean True when we have to do a SSL redirect (for Shared SSL)
	 */
	function check_Shared_SSL( &$ssl_domain ) {
		
		if( URL == SECUREURL ) {
			$ssl_domain = str_replace("http://", "", URL );
			$ssl_redirect = false;
			return $ssl_redirect;
		}
		
		// Extract the Domain Names without the Protocol
		$domain = str_replace("http://", "", URL );
		$ssl_domain = str_replace("https://", "", SECUREURL );
		// If SSL and normal Domain do not match,
		// we assume that you use Shared SSL
 
		if( $ssl_domain != $domain ) {
			$ssl_redirect = true;
		}
		else {
			$ssl_redirect = false;
		}
 
		return $ssl_redirect;
	}
	/**
	 * Correct the session save path if necessary
	 * or generate an error if the save path can't be corrected
	 *
	 * @return mixed
	 */
	function checkSessionSavePath() {
		global $mosConfig_absolute_path, $VM_LANG, $vmLogger;
		
		if( !@is_writable( session_save_path()) ) {
			// If the session save path is not writable this can have different
			// reasons. One reason is that the open_basedir directive is set, but
			// doesn't include the session_save_path
			$open_basedir = @ini_get('open_basedir'); // Get the list of allowed directories
			if( !empty($open_basedir)) {
				switch( substr( strtoupper( PHP_OS ), 0, 3 ) ) {
					case "WIN":
						$basedirs = explode(';', $open_basedir );
						break;
					case "MAC": // fallthrough
					case "DAR": // Does PHP_OS return 'Macintosh' or 'Darwin' ?
					default: // change nothing
						$basedirs = explode(':', $open_basedir );
						break;
					break;
				}
				$session_save_path_is_allowed_directory = false;
				foreach ( $basedirs as $basedir ) {
					$basedir_strlen = strlen( $basedir );
					// If the session save path is a subdirectory of a directory allowed by open_basedir
					// we need to do further investigation
					if( strtolower( substr( session_save_path(), 0, $basedir_strlen )) == $basedir ) {
						$session_save_path_is_allowed_directory = true;
					}
				}
				if( !$session_save_path_is_allowed_directory) {
					// PHP Sessions can be stored in a session save path which is not
					// allowed through open_basedir!
					return true;
				}
			}
			$try_these_paths = array( 'Cache Path' => $mosConfig_absolute_path. '/cache',
										'Media Directory' => $mosConfig_absolute_path.'/media',
										'Shop Image Directory' => IMAGEPATH );
			foreach( $try_these_paths as $name => $session_save_path ) {
				if( @is_writable( $session_save_path )) {
					$vmLogger->debug( sprintf( $VM_LANG->_('VM_SESSION_SAVEPATH_UNWRITABLE_TMPFIX',false), session_save_path(), $name));
					session_save_path( $session_save_path );
					break;
				}
			}
		}
		// If the path is STILL not writable, generate an error
		if( !@is_writable( session_save_path()) ) {
			$vmLogger->err( $VM_LANG->_('VM_SESSION_SAVEPATH_UNWRITABLE',false) );
		}
	}
	/**
     * Gets the Itemid for the com_virtuemart Component
     * and stores it in a global Variable
     *
     * @return int Itemid
     */
	function getShopItemid() {
 
		if( empty( $_REQUEST['shopItemid'] )) {
			$db = new ps_DB;
			$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
			if( $db->next_record() ) {
				$_REQUEST['shopItemid'] = $db->f("id");
			}
			else {
				if( !empty( $_REQUEST['Itemid'] )) {
					$_REQUEST['shopItemid'] = intval( $_REQUEST['Itemid'] );
				}
				else {
					$_REQUEST['shopItemid'] = 1;
				}
			}
		}
 
		return intval($_REQUEST['shopItemid']);
 
	}
	
	/**
	 * Prints a reformatted URL
	 *
	 * @param string $text
	 */
	function purl($text, $createAbsoluteURI=false, $encodeAmpersands=true, $ignoreSEF=false) {		
		echo $this->url( $text, $createAbsoluteURI, $encodeAmpersands, $ignoreSEF );		
	}
	
	/**
	 * This reformats an URL, appends "option=com_virtuemart" and "Itemid=XX"
	 * where XX is the Id of an entry in the table mos_menu with "link: option=com_virtuemart"
	 * It also calls sefRelToAbs to apply SEF formatting
	 * 
	 * @param string $text THE URL
	 * @param boolean False: Create a URI like /joomla/index.php?....; True: Create a URI like http://www.domain.com/index.php?....
	 * @return string The reformatted URL
	 */
	function url($text, $createAbsoluteURI=false, $encodeAmpersands=true, $ignoreSEF=false ) {
		global $mm_action_url, $page, $mainframe;
		
		if( !defined( '_VM_IS_BACKEND' )) {
			$Itemid = "&Itemid=".$this->getShopItemid();
		}
		else {
			$Itemid = '';
		}
 
		switch ($text) {
			case SECUREURL:
				$text =  SECUREURL.basename( $_SERVER['SCRIPT_NAME'] )."?".$this->component_name.$Itemid;
				break;
			case URL:
				$text =  URL.basename( $_SERVER['SCRIPT_NAME'] )."?".$this->component_name.$Itemid;
				break;
				
			default:
				$limiter = strpos($text, '?');
				if( !stristr( $text, $_SERVER['SCRIPT_NAME']) && $limiter === false ) {
					$text = '?'.$text;
				}
				$appendix = "";
				// now append "&option=com_virtuemart&Itemid=XX"
				if (!strstr($text, "option=")) {
					$appendix .= "&" . $this->component_name;
				}
				$appendix .= $Itemid;
				
				$script = basename( substr( $text, 0, $limiter ));
				if( $script == '' ) {
					$script = basename( $_SERVER['SCRIPT_NAME'] );
				}
				
				if (!defined( '_VM_IS_BACKEND' )) {
					if( $script == 'index3.php') {
						$script = 'index2.php'; // index3.php is not available in the frontend!
					}
	
					$appendix = $script.substr($text, $limiter, strlen($text)).$appendix;
				
					if( class_exists('JRoute') && !$ignoreSEF && $mainframe->getCfg('sef') ) {
						$appendix = JRoute::_( str_replace( $script.'&', $script.'?', $appendix ) );
						
					} 
					else if( function_exists('sefRelToAbs') && !$ignoreSEF && !defined( '_JLEGACY' ) ) {
						$appendix = sefRelToAbs( str_replace( $script.'&', $script.'?', $appendix ) );
					}
					if( $createAbsoluteURI && substr($appendix,0,4)!='http'  && ($ignoreSEF || !$mainframe->getCfg('sef')) ) {
						$appendix = URL . $appendix;
					}
					
					
				}
				elseif( $_SERVER['SERVER_PORT'] == 443 ) {
					//$script = strstr($_SERVER['PHP_SELF'], 'index2.php') ? 'index2.php' : 'index3.php';
					
					$appendix = SECUREURL."administrator/$script".substr($text, $limiter, strlen($text)-1).$appendix;
				}
				else {
					//$script = strstr($_SERVER['PHP_SELF'], 'index2.php') ? 'index2.php' : 'index3.php';
					$appendix = URL."administrator/$script".substr($text, $limiter, strlen($text)-1).$appendix;
				}
				if( vmIsAdminMode() && strstr($text, 'func') !== false ) {
					$appendix .= '&vmtoken='.vmSpoofValue($this->getSessionId());
				}
				if ( stristr($text, SECUREURL)) {
					$appendix = str_replace(URL, SECUREURL, $appendix);
				}
				elseif( stristr($text, URL) && $createAbsoluteURI ) {
					$appendix = str_replace(SECUREURL, URL, $appendix);
				}
	
				$text = $appendix;
	
				break;
		}
		if( $encodeAmpersands ) {
	        $text = vmAmpReplace( $text );
	    }  else {
		$text = str_replace( '&amp;', '&', $text );
	    }
		return $text;
	}
 
	/**
	 * Formerly printed the session id into a hidden field
	 * @deprecated 
	 * @return boolean
	 */
	function hidden_session() {
		return true;
	}
 
	function initRecentProducts() {
		global $recentproducts, $sess;
		// Register the recentproducts
		if (empty($_SESSION['recent'])) {
			$recentproducts = array();
			$recentproducts['idx'] = 0;
			$_SESSION['recent'] = $recentproducts;
			return $recentproducts;
		}
		
		return $_SESSION['recent'];
	}
 
} // end of class session
?>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:

Select allOpen in new window

 

by: brucepietersePosted on 2009-03-19 at 09:53:36ID: 23931593

Ok, please back up the original ps_session.php(.bak) and replace the contents of the file with:

<?php 
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @version $Id: ps_session.php 1526 2008-09-15 19:21:43Z soeren_nb $
* @package VirtueMart
* @subpackage classes
* @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/
 
 
/**
 * This class handles the session initialization, restart
 * and the re-init of a session after redirection to a Shared SSL domain
 *
 */
class ps_session {
 
	var $component_name;
	var $_session_name = 'virtuemart';
	/**
     * Initialize the Session environment for VirtueMart
     *
     */
	function ps_session() {
		
		$this->component_name = 'option='.VM_COMPONENT_NAME;
		
		$this->initSession();
	}
	/**
     * Initiate the Session
     *
     */
	function initSession() {
		global $vmLogger, $mainframe, $mosConfig_absolute_path, $VM_LANG;
		
		// We only care for the session if it is not started!
		if( empty( $_SESSION ) || session_id() == '') {
			
			if(ini_get('session.session_save_handler') == 'files') {
				// Check if the session_save_path is writable
				$this->checkSessionSavePath();
			}
			session_name( $this->_session_name );
			
			if( @$_REQUEST['option'] == 'com_virtuemart' ) {
				ob_start();// Fix for the issue that printed the shop contents BEFORE the page begin
			}
			@session_start();
			
			if( !empty($_SESSION) && !empty($_COOKIE[$this->_session_name])) {
				$vmLogger->debug( 'A Session called '.$this->_session_name.' (ID: '.session_id().') was successfully started!' );
			}
			else {
			}
		}
		else {
			if( empty( $_COOKIE['virtuemart']) && !vmIsJoomla('1.5', '>=')) {
				$_COOKIE['virtuemart'] = $this->getSessionId();			
				if( USE_AS_CATALOGUE == '' ) {
					$vmLogger->debug( 'A Cookie had to be set to keep the session (there was none - does your Browser keep the Cookie?) although a Session already has been started! If you see this message on each page load, your browser doesn\'t accept Cookies from this site.' );
				}
			}
			$vmLogger->debug( 'Using existing Session '.session_name().', ID: '.session_id().'.');
		}
		// Cookie Check
		// Introduced to check if the user-agent accepts cookies
		if( @$_REQUEST['option'] == 'com_virtuemart' && empty($_GET['martID']) 
			&& USE_AS_CATALOGUE != '1' && VM_ENABLE_COOKIE_CHECK == '1' && !vmIsAdminMode() ) {
			$this->doCookieCheck();
		}
	}
	/**
	 * Checks if the user-agent accepts cookies
	 * @since VirtueMart 1.0.7
	 * @author soeren
	 */
	function doCookieCheck() {
		global $mm_action_url, $VM_LANG;
		
		$doCheck = vmGet( $_REQUEST, 'vmcchk', 0 );
		$isOK = vmGet( $_SESSION, 'VMCHECK' );
		
		if( $doCheck && $isOK != 'OK' ) {
			$GLOBALS['vmLogger']->info( $VM_LANG->_('VM_SESSION_COOKIES_NOT_ACCEPTED_TIP',false) );
		}
		elseif( empty( $isOK )) {
			$_SESSION['VMCHECK'] = 'OK';
			$query_string = vmGet($_SERVER,'QUERY_STRING');
			if( !empty($query_string) && empty( $_POST )) {
				vmRedirect( $this->url( $mm_action_url . 'index.php?' .$query_string .'&vmcchk=1', true, false ));
			}
		}
	}
		
	/**
	 * Returns the Joomla/Mambo Session ID
	 * @static 
	 */
	function getSessionId() {
		global $mainframe;
		// Joomla >= 1.0.8
		if( is_callable( array( 'mosMainframe', 'sessionCookieName'))) {			
			// Session Cookie `name`
			$sessionCookieName 	= mosMainFrame::sessionCookieName();
			// Get Session Cookie `value`
			$sessionCookie 		= vmGet( $_COOKIE, $sessionCookieName, null );
			// Session ID / `value`
			return mosMainFrame::sessionCookieValue( $sessionCookie );
			
		}
		// Mambo 4.6
		elseif( is_callable( array('mosSession', 'getCurrent' ))) {
			$session =& mosSession::getCurrent();
			return $session->session_id;
		}
		// Mambo <= 4.5.2.3 and Joomla <= 1.0.7
		elseif( !empty( $mainframe->_session->session_id )) {
			// Set the sessioncookie if its missing
			// this is needed for joomla sites only
			return $mainframe->_session->session_id;
		}
		else {
			return session_id();
		}
	}
	/**
	 * This function returns a base64_encoded string:
	 * VMsessionId|JsessionID
	 *
	 */
	function getMartId() {
		global $vmuser, $mosConfig_secret;
		
		// Get the Joomla! / Mambo session ID
		$sessionId = ps_session::getSessionId();
		
		$userNameSeed = '';
		if( $vmuser->id ) {
			$userNameSeed = '|'.md5( $vmuser->username . $vmuser->password . $mosConfig_secret );
			if( is_callable(array('mosMainFrame', 'remCookieName_User'))) {
				if( !empty( $GLOBALS['real_mosConfig_live_site'] ) && empty( $_REQUEST['real_mosConfig_live_site'])) {
					$GLOBALS['mosConfig_live_site'] = $GLOBALS['real_mosConfig_live_site'];
				}
				$userNameSeed .= '|' . vmGet( $_COOKIE, mosMainFrame::remCookieName_User(), '' );
			}
		}
		
		$martID = base64_encode( vmCreateHash($_COOKIE[$this->_session_name] . $sessionId) . $userNameSeed );
		return $martID;
	}
	/**
	 * Saves the session contents to a file (so they the session can be continued later on) and does a redirect
	 *
	 * @param boolean $toSecure Redirect to a https or http domain?
	 */
	function saveSessionAndRedirect( $toSecure = true ) {
		$martID = $this->getMartId();
				
		$sessionFile = IMAGEPATH. md5( $martID ).'.sess';
		$session_contents = session_encode();
		
		if( file_exists( ADMINPATH.'install.copy.php')) {
			require_once( ADMINPATH.'install.copy.php');
		}
		
		file_put_contents( $sessionFile, $session_contents );
		
		$url = $toSecure ? SECUREURL : URL;
		
		// Redirect and send the Cookie Values within the variable martID
		vmRedirect( $this->url( $url . basename($_SERVER['PHP_SELF']).'?'.vmGet($_SERVER,'QUERY_STRING')."&martID=$martID&redirected=1", true, false, true ) );
	}
	/**
	 * It does what the name says. It starts a session again (with a certain ID when a $sid is given)
	 *
	 * @param string $sid
	 */
	function restartSession( $sid = '') {
		
		// Save the session data and close the session
		session_write_close();
		
		// Prepare the new session
		if( $sid != '' ) {
			session_id( $sid );
		}
		session_name( $this->_session_name );
		// Start the new Session.
		session_start();
		
	}
	
	function emptySession() {
		global $mainframe;
		$_SESSION = array();
		$_COOKIE[$this->_session_name] = md5( $this->getSessionId() );
	}
	/**
     * This is a solution for  the Shared SSL problem
     * We have to copy some cookies from the Main Mambo site domain into
     * the shared SSL domain (only when necessary!)
	 *
	 * The function is called on each page load.
	 */
	function prepare_SSL_Session() {
		global $mainframe, $my, $database, $mosConfig_secret, $page, $VM_MODULES_FORCE_HTTPS;
		if( vmIsAdminMode() && vmIsJoomla('1.0')) {
			return;
		}
		$ssl_redirect = vmGet( $_GET, "ssl_redirect", 0 );
		$redirected = vmGet( $_GET, "redirected", 0 );
		$martID = vmGet( $_GET, 'martID', '' );
		$ssl_domain = "";
		
		if (!empty( $VM_MODULES_FORCE_HTTPS )) {
			$pagearr = explode( '.', $page );
			$module = $pagearr[0];
			// When NOT in https mode, but the called page is part of a shop module that is
			// forced to use https, we prepare the redirection to https here
			if( array_search( $module, $VM_MODULES_FORCE_HTTPS ) !== false 
				&& !vmIsHttpsMode()
				&& $this->check_Shared_SSL( $ssl_domain ) 
				) {
					
				$ssl_redirect = 1;
			}
		}
		// Generally redirect to HTTP (from HTTPS) when it is not necessary? (speed up the pageload)
		if( VM_GENERALLY_PREVENT_HTTPS == '1' 
			&& vmIsHttpsMode() && $redirected != 1
			&& $ssl_redirect == 0 && !vmIsAdminMode()
			&& URL != SECUREURL
			&& @$_REQUEST['option']=='com_virtuemart') {
				
			$pagearr = explode( '.', $page );
			$module = $pagearr[0];
			
			// When it is not necessary to stay in https mode, we leave it here
			if( array_search( $module, $VM_MODULES_FORCE_HTTPS ) === false ) {
				if( $this->check_Shared_SSL($ssl_domain)) {
					$this->saveSessionAndRedirect( false );
				}
				$query_string = vmGet($_SERVER,'QUERY_STRING');
				if( !empty($query_string) && empty( $_POST )) {
					vmRedirect( $this->url( URL.basename( $_SERVER['PHP_SELF']).'?'.vmGet($_SERVER,'QUERY_STRING').'&redirected=1', true, false, true ));
				}
			}
		}
		
		/**
        * This is the first part of the Function:
        * We check if the function must be called at all
        * Usually this is only called once: Before we go to the checkout.
        * The variable ssl_redirect=1 is appended to the URL, just for this function knows
        * is must be active! This has nothing to do with SSL / Shared SSL or whatever
        */
		if( $ssl_redirect == 1 ) {
			
			$_SERVER['QUERY_STRING'] = str_replace('&ssl_redirect=1', '', vmGet($_SERVER, 'QUERY_STRING' ) );
			// check_Shared_SSL compares the normal http domain name
			// and the https Domain Name. If both do not match, we move on
			// else we leave this function.
			if( $this->check_Shared_SSL( $ssl_domain ) && !vmIsHttpsMode() && $redirected == 0) {
				
				$this->saveSessionAndRedirect( true );
			}
			// do nothing but redirect
			elseif( !vmIsHttpsMode() && $redirected == 0 ) {
				vmRedirect( $this->url(SECUREURL . basename($_SERVER['PHP_SELF'])."?".vmGet($_SERVER,'QUERY_STRING').'&redirected=1', true, false, true ) );
			}
		}
		/**
        * This is part two of the function
        * If the redirect (see 4/5 lines above) was successful
        * and the Store uses Shared SSL, we have the variable martID
        * So let's copy the Session contents ton the new domain and start the session again
        * othwerwise: do nothing.
        */
		if( !empty( $martID ) ) {
			
			if( $this->check_Shared_SSL( $ssl_domain ) ) {
	
				// We now need to copy the Session Data to the SSL Domain
				if( $martID ) {					
					
					require_once( ADMINPATH.'install.copy.php');
					
					$sessionFile = IMAGEPATH. md5( $martID ).'.sess';
					
					// Read the contents of the session file
					$session_data = file_get_contents( $sessionFile );
					
					// Delete it for security and disk space reasons
					unlink( $sessionFile );
					
					// Read the session data into $_SESSION
					// From now on, we can use all the data in $_SESSION
					session_decode( $session_data );
					
					$check = base64_decode( $martID );
					$checkValArr = explode( "|", $check );
					
					if( defined('_JEXEC') ) {
						//TODO
					}
					elseif( class_exists('mambocore')) {
						//TODO
					}
					elseif( $GLOBALS['_VERSION']->RELEASE == '1.0' && (int)$GLOBALS['_VERSION']->DEV_LEVEL >= 13) {
						if( !empty( $GLOBALS['real_mosConfig_live_site'] ) && empty( $_REQUEST['real_mosConfig_live_site'])) {
							$GLOBALS['mosConfig_live_site'] = $GLOBALS['real_mosConfig_live_site'];
						}
						if( !empty( $checkValArr[2] )) {
							// Joomla! >= 1.0.13 can be cheated to log in a user who has previsously logged in and checked the "Remember me" box
							setcookie( mosmainframe::remCookieName_User(), $checkValArr[2], false, '/' );
							// there's no need to call "$mainframe->login"
						}
					} else {
						// Check if the user was logged in in the http domain
						// and is not yet logged in at the Shared SSL domain
						if( isset( $checkValArr[1] ) && !$my->id ) {
							// user should expect to be logged in,
							// we can use the values from $_SESSION['auth'] now
							$username = $database->getEscaped( trim( $_SESSION['auth']['user_name'] ) );
							if( !empty( $username )) {
								$database->setQuery('SELECT username, password FROM `#__users` WHERE `username` = \''.$username.'\';');
								$database->loadObject( $user );
								if( is_object( $user )) {
									// a last security check using the transmitted md5 hash and the rebuilt hash
									$check = md5( $user->username . $user->password . $mosConfig_secret );
									if( $check === $checkValArr[1] ) {
										// Log the user in with his username
										$mainframe->login( $user->username, $user->password );
									}
								}
								
							}
						}
					}
									
					
					session_write_close();
					
					// Prevent the martID from being displayed in the URL
					if( !empty( $_GET['martID'] )) {
						$query_string = substr_replace( vmGet($_SERVER,'QUERY_STRING'), '', strpos( vmGet($_SERVER,'QUERY_STRING'), '&martID'));
						$url = vmIsHttpsMode() ? SECUREURL : URL;
						vmRedirect( $this->url( $url . "index.php?$query_string&cartReset=N&redirected=1", true, false, true) );
					}
	
				}
	
			}
		}
	}
	/**
	 * This function compares the store URL with the SECUREURL
	 * and returns the result
	 *
	 * @param string $ssl_domain The SSL domain (empty string to be filled here)
	 * @return boolean True when we have to do a SSL redirect (for Shared SSL)
	 */
	function check_Shared_SSL( &$ssl_domain ) {
		
		if( URL == SECUREURL ) {
			$ssl_domain = str_replace("http://", "", URL );
			$ssl_redirect = false;
			return $ssl_redirect;
		}
		
		// Extract the Domain Names without the Protocol
		$domain = str_replace("http://", "", URL );
		$ssl_domain = str_replace("https://", "", SECUREURL );
		// If SSL and normal Domain do not match,
		// we assume that you use Shared SSL
 
		if( $ssl_domain != $domain ) {
			$ssl_redirect = true;
		}
		else {
			$ssl_redirect = false;
		}
 
		return $ssl_redirect;
	}
	/**
	 * Correct the session save path if necessary
	 * or generate an error if the save path can't be corrected
	 *
	 * @return mixed
	 */
	function checkSessionSavePath() {
		global $mosConfig_absolute_path, $VM_LANG, $vmLogger;
		
		if( !@is_writable( session_save_path()) ) {
			// If the session save path is not writable this can have different
			// reasons. One reason is that the open_basedir directive is set, but
			// doesn't include the session_save_path
			$open_basedir = @ini_get('open_basedir'); // Get the list of allowed directories
			if( !empty($open_basedir)) {
				switch( substr( strtoupper( PHP_OS ), 0, 3 ) ) {
					case "WIN":
						$basedirs = explode(';', $open_basedir );
						break;
					case "MAC": // fallthrough
					case "DAR": // Does PHP_OS return 'Macintosh' or 'Darwin' ?
					default: // change nothing
						$basedirs = explode(':', $open_basedir );
						break;
					break;
				}
				$session_save_path_is_allowed_directory = false;
				foreach ( $basedirs as $basedir ) {
					$basedir_strlen = strlen( $basedir );
					// If the session save path is a subdirectory of a directory allowed by open_basedir
					// we need to do further investigation
					if( strtolower( substr( session_save_path(), 0, $basedir_strlen )) == $basedir ) {
						$session_save_path_is_allowed_directory = true;
					}
				}
				if( !$session_save_path_is_allowed_directory) {
					// PHP Sessions can be stored in a session save path which is not
					// allowed through open_basedir!
					return true;
				}
			}
			$try_these_paths = array( 'Cache Path' => $mosConfig_absolute_path. '/cache',
										'Media Directory' => $mosConfig_absolute_path.'/media',
										'Shop Image Directory' => IMAGEPATH );
			foreach( $try_these_paths as $name => $session_save_path ) {
				if( @is_writable( $session_save_path )) {
					$vmLogger->debug( sprintf( $VM_LANG->_('VM_SESSION_SAVEPATH_UNWRITABLE_TMPFIX',false), session_save_path(), $name));
					session_save_path( $session_save_path );
					break;
				}
			}
		}
		// If the path is STILL not writable, generate an error
		if( !@is_writable( session_save_path()) ) {
			$vmLogger->err( $VM_LANG->_('VM_SESSION_SAVEPATH_UNWRITABLE',false) );
		}
	}
	/**
     * Gets the Itemid for the com_virtuemart Component
     * and stores it in a global Variable
     *
     * @return int Itemid
     */
	function getShopItemid() {
 
		if( empty( $_REQUEST['shopItemid'] )) {
			$db = new ps_DB;
			$db->query( "SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND published=1");
			if( $db->next_record() ) {
				$_REQUEST['shopItemid'] = $db->f("id");
			}
			else {
				if( !empty( $_REQUEST['Itemid'] )) {
					$_REQUEST['shopItemid'] = intval( $_REQUEST['Itemid'] );
				}
				else {
					$_REQUEST['shopItemid'] = 1;
				}
			}
		}
 
		return intval($_REQUEST['shopItemid']);
 
	}
	
	/**
	 * Prints a reformatted URL
	 *
	 * @param string $text
	 */
	function purl($text, $createAbsoluteURI=false, $encodeAmpersands=true, $ignoreSEF=false) {		
		echo $this->url( $text, $createAbsoluteURI, $encodeAmpersands, $ignoreSEF );		
	}
	
	/**
	 * This reformats an URL, appends "option=com_virtuemart" and "Itemid=XX"
	 * where XX is the Id of an entry in the table mos_menu with "link: option=com_virtuemart"
	 * It also calls sefRelToAbs to apply SEF formatting
	 * 
	 * @param string $text THE URL
	 * @param boolean False: Create a URI like /joomla/index.php?....; True: Create a URI like http://www.domain.com/index.php?....
	 * @return string The reformatted URL
	 */
	function url($text, $createAbsoluteURI=false, $encodeAmpersands=true, $ignoreSEF=false ) {
		global $mm_action_url, $page, $mainframe;
		
		if( !defined( '_VM_IS_BACKEND' )) {
			$Itemid = "&Itemid=".$this->getShopItemid();
		}
		else {
			$Itemid = '';
		}
 
		switch ($text) {
			case SECUREURL:
				$text =  SECUREURL."index.php?".$this->component_name.$Itemid;
				break;
			case URL:
				$text =  URL."index.php?".$this->component_name.$Itemid;
				break;
				
			default:
				$limiter = strpos($text, '?');
				if( !stristr( $text, $_SERVER['SCRIPT_NAME']) && $limiter === false ) {
					$text = '?'.$text;
				}
				$appendix = "";
				// now append "&option=com_virtuemart&Itemid=XX"
				if (!strstr($text, "option=")) {
					$appendix .= "&" . $this->component_name;
				}
				$appendix .= $Itemid;
				
				$script = basename( substr( $text, 0, $limiter ));
				if( $script == '' ) {
					$script = "index.php";
				}
				
				if (!defined( '_VM_IS_BACKEND' )) {
					if( $script == 'index3.php') {
						$script = 'index2.php'; // index3.php is not available in the frontend!
					}
	
					$appendix = $script.substr($text, $limiter, strlen($text)).$appendix;
				
					if( class_exists('JRoute') && !$ignoreSEF && $mainframe->getCfg('sef') ) {
						$appendix = JRoute::_( str_replace( $script.'&', $script.'?', $appendix ) );
						
					} 
					else if( function_exists('sefRelToAbs') && !$ignoreSEF && !defined( '_JLEGACY' ) ) {
						$appendix = sefRelToAbs( str_replace( $script.'&', $script.'?', $appendix ) );
					}
					if( $createAbsoluteURI && substr($appendix,0,4)!='http'  && ($ignoreSEF || !$mainframe->getCfg('sef')) ) {
						$appendix = URL . $appendix;
					}
					
					
				}
				elseif( $_SERVER['SERVER_PORT'] == 443 ) {
					//$script = strstr($_SERVER['PHP_SELF'], 'index2.php') ? 'index2.php' : 'index3.php';
					
					$appendix = SECUREURL."administrator/$script".substr($text, $limiter, strlen($text)-1).$appendix;
				}
				else {
					//$script = strstr($_SERVER['PHP_SELF'], 'index2.php') ? 'index2.php' : 'index3.php';
					$appendix = URL."administrator/$script".substr($text, $limiter, strlen($text)-1).$appendix;
				}
				if( vmIsAdminMode() && strstr($text, 'func') !== false ) {
					$appendix .= '&vmtoken='.vmSpoofValue($this->getSessionId());
				}
				if ( stristr($text, SECUREURL)) {
					$appendix = str_replace(URL, SECUREURL, $appendix);
				}
				elseif( stristr($text, URL) && $createAbsoluteURI ) {
					$appendix = str_replace(SECUREURL, URL, $appendix);
				}
	
				$text = $appendix;
	
				break;
		}
		if( $encodeAmpersands ) {
	        $text = vmAmpReplace( $text );
	    }  else {
		$text = str_replace( '&amp;', '&', $text );
	    }
		return $text;
	}
 
	/**
	 * Formerly printed the session id into a hidden field
	 * @deprecated 
	 * @return boolean
	 */
	function hidden_session() {
		return true;
	}
 
	function initRecentProducts() {
		global $recentproducts, $sess;
		// Register the recentproducts
		if (empty($_SESSION['recent'])) {
			$recentproducts = array();
			$recentproducts['idx'] = 0;
			$_SESSION['recent'] = $recentproducts;
			return $recentproducts;
		}
		
		return $_SESSION['recent'];
	}
 
} // end of class session
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:

Select allOpen in new window

 

by: encinitasbobPosted on 2009-03-19 at 11:17:20ID: 23932434

Sorry Bruce:

No effect that I can see.  At present the same results

 

by: encinitasbobPosted on 2009-03-19 at 12:59:01ID: 23933456

Is it possible you posted the original script and not your hack?

 

by: brucepietersePosted on 2009-03-20 at 04:35:35ID: 23938370

Nope it's the changed one. Line changes on 511, 514 and 531. Hmm, have you tried upgrading your modules to the latest versions?

 

by: encinitasbobPosted on 2009-03-20 at 11:09:12ID: 23942103

Your hack does work. Sorry about my confusion.

 

by: encinitasbobPosted on 2009-03-20 at 11:11:44ID: 31559305

Thank you. This solves the immediate problem. Hope it doesn't cause unforssen difficulties.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...