Jump to content

[SOLVED] How To Prevent PHP Script Running From Cart Trigger


Recommended Posts

How to prevent php script running from cart trigger.

 

 

Multi-site 1.6

 

To integrate an affiliate program over multiple domains I had to include a script at the top of the index.php page that created cookies on the other store domains using an image call to each domain that triggers a script in those domains to create a cookies.

 

It all works fine until you add a product to the cart using the Modalcart3 module or try to delete a product from the cart.

 

Then a warning window opens stating:

“Impossible to add the product to the cart.

TextStatus: 'parsererror'

errorThrown: 'SyntaxError: Invalid character'

responseText:

<img src='....................................................................”

 

There is a list of images which are all the links I use to create the cookies.

 

Another issue is that when you add to the cart using the Modalcart3 module my additional script is processed which slows the cart down somewhat.

 

Is there a test (if statement) I could run that would prevent my php script being run if the trigger is related to the shopping cart and or Modalcart3?

 

So when the page loads the script runs but if the user adds to the cart or deletes from the cart the script is blocked from running which would speed the cart up, and prevent the error.

 

Thanks

Edited by IeM (see edit history)
Link to comment
Share on other sites

Ok I worked an answer.

 

When you click add to cart the link https://www.domain.com/?rand=78787832439857 is called.

 

So I wrapped the custom script link in an IF statement:

 

$pageAddress = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES);
 
if($pageAddress[1]== '?' && $pageAddress[2]== 'r' && $pageAddress[3]== 'a' && $pageAddress[6]== '='){
             // Cart link has been used so we can not create remote cookies without causing issues with the cart.
}else{
            include_once($_SERVER['DOCUMENT_ROOT'].'/..........php');
}
 
I read the string instead of using a php function such as strpos() for speed as in most cases $pageAddress[1]== '?' would return FALSE. I may change this later.
 
This works for both when the user is adding to the cart and when the user is deleting from the cart. There may be other issues not found yet.
 
Thanks
Edited by IeM (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...