SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    starnge require() problem

    I am moving an osCommerce shop to one of my servers from another one. Both use PHP 4.x.

    On the checkout page there is the following code:

    Code:
    require (DIR_WS_CLASSES . 'payment.php');
    This is bringing up the error:

    Warning: main(1) [function.main]: failed to open stream: No such file or directory in xxx/xxx/httpdocs/shop/checkout_confirmation.php on line 48

    Fatal error: main() [function.require]: Failed opening required '1' (include_path='.:/usr/lib/php') in xxx/xxx/httpdocs/shop/checkout_confirmation.php on line 48
    I've trid putting the path in an if statement with file_exists() and this comes back true, but the require won't work.

    The other puzzle is the 1 in main(1) and Failed opening required '1'

    does anyone have any ideas?

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like TRUE is passed as a parameter to the require() function. Show some code, specifically line 48 from checkout_confirmation.php.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    line 48 is the require() line

  4. #4
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote some more code around line 48.

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post more codes around the error. Try echoing DIR_WS_CLASSES too..
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    immediately before this is:

    Code:
    require('includes/application_top.php');
    
    // if the customer is not logged on, redirect them to the login page
      if (!tep_session_is_registered('customer_id')) {
        $navigation->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_PAYMENT));
        tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
      }
    
    // if there is nothing in the customers basket, redirect them to the shopping basket page
      if ($basket->count_contents() < 1) {
        tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
      }
    
    // avoid hack attempts during the checkout procedure by checking the internal basketID
      if (isset($basket->basketID) && tep_session_is_registered('basketID')) {
        if ($basket->basketID != $basketID) {
          tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
        }
      }
    
    // if no shipping method has been selected, redirect the customer to the shipping method selection page
      if (!tep_session_is_registered('shipping')) {
        tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
      }
    
      if (!tep_session_is_registered('payment')) tep_session_register('payment');
      if (isset($HTTP_POST_VARS['payment'])) $payment = $HTTP_POST_VARS['payment'];
    
      if (!tep_session_is_registered('comments')) tep_session_register('comments');
      if (tep_not_null($HTTP_POST_VARS['comments'])) {
        $comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
      }
    Don't think there is anything there to cause this though

  7. #7
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please post code around line 48, including the line. Not code before or after. Also if you use php tags rather than code, it'll be much easier to read.

    Thanks.

  8. #8
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // load the selected payment module

      
    require (DIR_WS_CLASSES 'payment.php') or die();
      if (
    $credit_covers$payment=''//ICW added for CREDIT CLASS
      
    $payment_modules = new payment($payment); 
    line 48 being require(...

  9. #9
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This isn't going to work:

    PHP Code:
    require (DIR_WS_CLASSES 'payment.php') or die(); 
    because require is not a regular function. It is a special language construct and brackets are optional and not obeyed in terms of delimiting call parameter (everything until semicolon is treated as parameter), thus you're passing boolean value evaluated from the expression:

    PHP Code:
    (DIR_WS_CLASSES 'payment.php') or die() 
    which evaluates to TRUE (because the string is not empty) and that's what is passed to require as parameter (1), hence the error saying it cannot find file "1".

    Anyway, the solution:

    PHP Code:
    require (DIR_WS_CLASSES 'payment.php'); 
    You don't need "or die" there because if require fails then a fatal error will be thrown anyway.

  10. #10
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK thats great, thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •