Forum

Thread tagged as: Question, Problem

Problem with file path

This may just be me as I have always had a block when it comes to file paths, but on my local server (i.e. where I am building a site) I am calling a cart functions script, which I have put into the Paypal Shop directory, from a jQuery Ajax call and all works fine. However I have uploaded the files to my client area [directory / sub-domain] on my live site and no matter what variation I try I cannot get the file path to work (varying errors depending on what I try).

The Ajax call is made from

/shop/category-name/product-name on my local machine

The jQuery file (that has the Ajax call) is located in

/assets/js/shop.jquery.min.js

The shopping cart functions are in

/perch/addons/apps/perch_shop_paypal/cart.functions.php

And in my jQuery file I am trying to access using

/perch/addons/apps/perch_shop_paypal/cart.functions.php

As I say this works fine on my localhost but not on my remote server and I don't know why or if it is just to do with being on a sub-domain. Can anyone help?

Emma Davis

Emma Davis 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

What errors are you getting?

With /perch/addons/apps/perch_shop_paypal/cart.functions.php I get

https://www.client.my-site.co.uk/perch/?r=%2Fmanage%2Faddons%2Fapps%2Fperch_shop_paypal%2Fcart.functions.php 403 (Forbidden)

Which I find a bit odd in itself that it is replacing the forward slashes.

I have tried other variations of the path but will stick with this one for the moment.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

403 (Forbidden).

Looks like a server configuration issue so you should take that up with your host.

OK, but can you confirm this is the correct path structure you would use in this situation please?

Sorry to come back to you about this but I am now pulling my hair out. My hosting company says it isn't the server (though I am never quite sure I believe them) and that it is to do with my .htaccess file and I just can't see a problem with it and I still have no idea what would cause the html entity replacement in the url (I have never seen it before).

Is anyone able to cast an eye of my .htaccess file and let me know if they can see any issues that might be causing this problem please (dog-agility-equipment is the name I have given my shop directory)?

Options +FollowSymlinks
RewriteEngine On

# show file names without .php extension
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ $1.php [L,QSA]

RewriteRule ^dog-agility-equipment/([a-zA-Z0-9-/]+)$ /dog-agility-equipment/category.php?cat=$1 [L]
RewriteRule ^agility-equipment/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)$ /dog-agility-equipment/product.php?s=$2 [L]
RewriteRule ^agility-equipment/([a-zA-Z0-9-/]+)$ /dog-agility-equipment/product.php?s=$1 [L]

ErrorDocument 404 /not-found.php

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"

ExpiresByType text/css "access 1 minute"
ExpiresByType text/html "access 1 minute"
ExpiresByType application/pdf "access 1 minute"
ExpiresByType text/x-javascript "access 1 minute"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 minute"
</IfModule>


## COMPRESS FILES TO REDUCE PAGE-LOAD SPEED ##
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# ##############################################################################
# # INTERNET EXPLORER                                                          #
# ##############################################################################

# ------------------------------------------------------------------------------
# | Better website experience                                                  |
# ------------------------------------------------------------------------------

# Force Internet Explorer to render pages in the highest available
# mode in the various cases when it may not.
# https://hsivonen.fi/doctype/#ie8

<FilesMatch "\.(htm|html|php)$">
    <IfModule mod_headers.c>
        BrowserMatch MSIE ie
        Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
    </IfModule>
</FilesMatch>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Your script is being redirected to the Perch login page - hence the 403 status and the encoded querystring.

I can think of two possible reasons:

  1. The URL you're requesting is part of the Perch control panel and your JavaScript request isn't authenticated

  2. You're requesting the correct URL, but a bad rewrite rule is redirecting it to part of the Perch control panel.

Did you rename the perch folder to manage or is that a typo? Could that be the cause?

Yes I thought that odd as well and forgot to mention it as it only happens when I call the script directly from the form (i.e. I have commented out the jQuery / Ajax call so that I can test more easily) and just thought it was something to do with whatever the issue is in the first instance.

When you say the url I am requesting is part of the control panel, can you explain a bit more please - do you mean because the file I am trying to access is within the Perch folder?

I would say the 2nd is the issue but I can't see anything wrong with my rewrite rules which is why I am completely baffled (I also don't understand why it works perfectly fine on localhost and the issue has only arisen since I have uploaded to a remote server).

I have renamed the Perch folder to manage (just so it makes more sense to the client). Would this cause the problem as I thought I could rename the folder?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It doesn't make a difference, only that you said your paths were all /perch.

But this really doesn't make sense:

https://www.client.my-site.co.uk/perch/?r=%2Fmanage%2Faddons%2Fapps%2Fperch_shop_paypal%2Fcart.functions.php

I'm trying to figure out how you'd access a page under /manage and then get redirected to log in at /perch. Have you updated your config.php file to reflect the renaming?

Sorry, I changed to perch in my first post to have it make more sense (i.e. so you would know the paths) I should have just used what I use and explained that I had renamed the directory.

So actually what I get is

https://www.client.my-site.co.uk/manage/?r=%2Fmanage%2Faddons%2Fapps%2Fperch_shop_paypal%2Fcart.functions.php
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does cart.functions.php do? Does it attempt to include any parts of Perch?

cart.functions.php does all the 'stuff' for adding to, editing and deleting from the shopping cart using both sessions and also adding and updating cookie data both on the users machine and within the database. I have created a couple of classes and used other scripts for the Paypal shop as an example to create the script.

This is what I have at the top of the script (the rest is just properties and methods for the cart):

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
# include the API
include('../../../core/inc/api.php');

$API  = new PerchAPI(1.0, 'perch_shop_paypal');
$Lang = $API->get('Lang');

# include your class files
include('PerchShop_Cache.class.php');
include('PerchShop_Carts.class.php');
include('PerchShop_Cart.class.php');

I also have some additions to the main runtime file which checks if a cookie has been stored on the users computer each time they visit the site, which is:

if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }

    include(dirname(__FILE__).'/core/runtime/runtime.php');

    // Check if a shopping cart cookie exists on the visitor's computer and if so, re-create the cart session with stored data
    if (!isset($_SESSION['cart']) && !isset($_SESSION['cookie_checked'])) {

        if(isset($_COOKIE['longfield_cart_cookie'])){

            $API  = new PerchAPI(1.0, 'perch_shop_paypal');
            $Lang = $API->get('Lang');

            # include your class files
            include(dirname(__FILE__).'/addons/apps/perch_shop_paypal/PerchShop_Carts.class.php');
            include(dirname(__FILE__).'/addons/apps/perch_shop_paypal/PerchShop_Cart.class.php');

            $Carts = new PerchShop_Carts($API);

            $cart_data = $Carts->find_by_cookie($_COOKIE['longfield_cart_cookie']);

            if (!empty($cart_data)) {

                $details = $cart_data->to_array();
                $cart_session = unserialize($details['cartData']);

                $_SESSION['cart']['cart_items_qty'] = $cart_session['cart_items_qty'];
                $_SESSION['cart']['cart_subtotal'] = $cart_session['cart_subtotal'];
                $_SESSION['cart']['cart_delivery'] = $cart_session['cart_delivery'];
                $_SESSION['cart']['cart_total'] = $cart_session['cart_total'];

                foreach ($cart_session['items'] as $item) {

                    $_SESSION['cart']['items'][] = $item;

                }

            }

        }

        $_SESSION['cookie_checked'] = 1;

    }

Not sure if any of this has a bearing on the problems I am having on the remote server - and still confused as to why it works fine on localhost??

Anyone?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure how to help, as so much of this is your code rather than mine.

Starting with basics, can you see the HTTP request going to the correct URL? If you GET that URL yourself in a browser or with cURL, what happens?

Well that is really strange. The HTTP request is going to the correct URL, however the status code says 302 Moved Temporarily (I have tried a couple of locations for the file and both state the same).

Then it appears that the url is changed to

/manage?r=%2Fmanage%2Faddons%2Fapps%2Fperch_shop_paypal%2Fcart.functions.php

Which then returns a 403 Forbidden.

If I try to go directly to the URL I get exactly the same header / response.

Unfortunately I don't know how to GET the URL with cURL. Any pointers?

OK, I have now done some more debugging and found that it is my call to

include('../../../core/inc/api.php');

Which is causing the issue. As I have copied the includes directly from the requirements for add-on apps and this file is within the Paypal app folder, why would this be causing an issue?

Finally have this sorted. I have changed the include files to match that of the Paypal IPN callback and all is now working as it should.

Took a long time to get there but thank you Drew for your help as it made me think of other things and ways of debugging the problem which has led to resolving it :)