Jump to content

Redirect cart.php to main website!!


sonuyos

Recommended Posts

hey guys,

 

I am to redirect my cart.php or make it inaccessible, so that wenever someone order it will be done thru my main website instead been able to do from cart.php

 

I have created a new plugin and my cart.php is whole jumbled up and confusining, I don't want them to see, so wenever someone comes to my site they can order from my website page wihc has cart.php?XXXX setup (normal setup) and they order it...please help!!

 

Thank you :)

Link to comment
Share on other sites

:) you mean that you don't need direct access to /cart.php (Main Cart Page), and only allow access when adding product/service

 

if so you can try this one:

create new .php file with any name in "/includes/hooks/" directory and place the following code in it

<?
function hook_noDirectAccessToCart($vars){
global $CONFIG;

   if ($vars['filename']=='cart'){
       if (count($_SESSION['cart']['domains'])=='0' && count($_SESSION['cart']['products'])=='0' && count($_GET)=='0' && count($_POST)=='0'){

           echo '<meta http-equiv="Refresh" content="0; url='.$CONFIG['SystemURL'].'">';
           exit;
       }
   }
}
add_hook("ClientAreaPage", 1, "hook_noDirectAccessToCart");
?>

 

- - - Updated - - -

 

unable to edit it:

<?php
function hook_noDirectAccessToCart($vars){
global $CONFIG;

   if ($vars['filename']=='cart'){
       if (count($_SESSION['cart']['domains'])=='0' && count($_SESSION['cart']['products'])=='0' && count($_GET)=='0' && count($_POST)=='0'){

           echo '<meta http-equiv="Refresh" content="0; url='.$CONFIG['SystemURL'].'">';
           exit;
       }
   }
}
add_hook("ClientAreaPage", 1, "hook_noDirectAccessToCart");
?>

Link to comment
Share on other sites

I don't think that hook will solve the exact issue the OP was referring to.

 

it will certainly block direct access to cart.php, but if you have "Default To Client Area" unticked, you can get around the hook by going to the homepage and clicking on the "Order New Services" button - that will take you to cart.php and the page loads, so isn't being blocked by the hook.

 

however, if you use the htaccess code in the above thread, it will block this route too - so only direct product links should work.

 

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/cart\.php$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://www.mydomain.com [R=302,L]

Link to comment
Share on other sites

i understand that the OP need to redirect access to /cart.php to /index.php while his clients able to place orders also, if this is the case i think my hook will work

my reading of the question was that the OP wanted to make it impossible to access cart.php unless you came from a product link on his web site, e.g you can't go to cart.php directly and you can't get to it by any other route... the hook takes care of the first, but not the second.

 

depending on how the OP has his site setup, the hook might be sufficient; if it isn't, then the htaccess code should cover both aspects.

 

anyway - he has two options, and without seeing the site, it's difficult to know which suits his needs... so we can let him decide! :idea:

Link to comment
Share on other sites

  • 4 years later...
On 14/04/2015 at 2:31 PM, brian! said:

I don't think that hook will solve the exact issue the OP was referring to.

it will certainly block direct access to cart.php, but if you have "Default To Client Area" unticked, you can get around the hook by going to the homepage and clicking on the "Order New Services" button - that will take you to cart.php and the page loads, so isn't being blocked by the hook.

however, if you use the htaccess code in the above thread, it will block this route too - so only direct product links should work.


RewriteEngine On
RewriteCond %{REQUEST_URI} ^/cart\.php$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://www.mydomain.com [R=302,L]
 

Hey Brian, I know this is an old topic, but it's still incredibly helpful. I noticed the redirect rule doesn't work at all and the hook has the shortcomings that you mentioned as well as not working with products in cart, i.e. "Order New Services"/"Continue Shopping" buttons with URL: /cart.php

Do you have any other ideas? Was there a change in how WHMCS handled URLs because it's very rare to see your suggestions fall short!

Link to comment
Share on other sites

10 hours ago, SteelSignature said:

Was there a change in how WHMCS handled URLs

two words - Friendly URLs 😲😲

first introduced into the client area a few years back, and recently being utilised in the admin area too - I wouldn't waste my time trying to write htaccess to work with/around it, i'd probably fall back to using a hook.

10 hours ago, SteelSignature said:

Do you have any other ideas?

to ensure anyone just going to cart.php directly (e.g the opening products page) gets redirected elsewhere, you could use the hook below (it's just a variation on a hook that i've posted previously)...

<?php

# Redirect Cart Visitors Hook for SteelSignature
# Written by brian!

function redirect_cart_vistors($vars)
{
	if ($vars['templatefile'] === 'products'){
		header("Location: clientarea.php");
		exit;
	}
}
add_hook("ClientAreaPageCart", 1, "redirect_cart_vistors");
?>
  • visitors to cart.php, or cart.php?gid=1 etc will be redirected to clientarea.php (you could change that to another page or site URL if required, e.g index.php or https://google.com etc)...
  • visitors to the domain registration / transfer / MarketConnect sales pages / viewcart and checkout should be unaffected by the hook - as will those using direct URL links to specific products.

this hook could be expanded to include other cart pages (or beyond), but whether that's necessary depends on how protective you want to be with direct access to the cart.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated