sonuyos Posted April 14, 2015 Share Posted April 14, 2015 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 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted April 14, 2015 Share Posted April 14, 2015 so do you need to redirect all access from /cart.php to /index.php?? 0 Quote Link to comment Share on other sites More sharing options...
sonuyos Posted April 14, 2015 Author Share Posted April 14, 2015 so do you need to redirect all access from /cart.php to /index.php?? Yes, but not the order one.../cart.php?XXX 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 14, 2015 Share Posted April 14, 2015 try the code from the thread below, but change the final URL to your own... http://forum.whmcs.com/showthread.php?83095-Removing-Cart-php&p=353654#post353654 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted April 14, 2015 Share Posted April 14, 2015 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"); ?> 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 14, 2015 Share Posted April 14, 2015 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] 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted April 14, 2015 Share Posted April 14, 2015 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 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 14, 2015 Share Posted April 14, 2015 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! 0 Quote Link to comment Share on other sites More sharing options...
SteelSignature Posted December 3, 2019 Share Posted December 3, 2019 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! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 3, 2019 Share Posted December 3, 2019 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. 1 Quote Link to comment Share on other sites More sharing options...
Bhondawe30 Posted December 5, 2019 Share Posted December 5, 2019 Thanks for sharing the code, It will be helpful for me. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.