Hi can anyone help why URL string parameters post again and again?
HTTP://127.0.0.1/ab/1936.html?cart=yes?cart=yes
i m using this parameter to open mini cart when we added product into cart in magneto 1.9
Please help me how to protect this?
i am using this code-
<?php
if ($_GET['cart']=='yes') {
echo "<script type='text/javascript'>
jQuery('.minicart_open').show();
</script>";
}
?>
cartController.php
protected function _goBack()
{
$returnUrl = $this->getRequest()->getParam('return_url');
// print_r($returnUrl);exit;
if ($returnUrl) {
if (!$this->_isUrlInternal($returnUrl)) {
throw new Mage_Exception('External urls redirect to "' . $returnUrl . '" denied!');
}
$this->_getSession()->getMessages(true);
$this->getResponse()->setRedirect($returnUrl);
} elseif (!Mage::getStoreConfig('checkout/cart/redirect_to_cart')
&& !$this->getRequest()->getParam('in_cart')
&& $backUrl = $this->_getRefererUrl()
) {
$this->getResponse()->setRedirect($backUrl.'?cart=yes');
} else {
if (
(strtolower($this->getRequest()->getActionName()) == 'add')
&& !$this->getRequest()->getParam('in_cart')
) {
$this->_getSession()->setContinueShoppingUrl($this->_getRefererUrl());
}
$this->_redirect('checkout/cart');
}
return $this;
}
i got the answer
Just replace below line
$this->getResponse()->setRedirect($backUrl.'?cart=yes');
To
$url = $backUrl;
// Search substring
if (strpos($url, $key) == false) {
$this->getResponse()->setRedirect($backUrl.'?cart=yes');
}
else {
$this->getResponse()->setRedirect($backUrl);
}
//exit;
its working for me...Hope its helpful for you...
Related
I want to get URL before the current one in Magento and check if is shopping cart and checkout page. For example now I am in the My account page, I want to check if the visited page before My account was Shopping Cart page.
I try to add this function but is not work because my last URL is login, not
shopping cart
public function customerRegistration(Varien_Event_Observer $observer)
{
$lastUrl = Mage::getSingleton('core/session')->getLastUrl();
if(preg_match("#onestepcheckout/index#", $lastUrl)){
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('onestepcheckout/index'));
Mage::app()->getResponse()->sendResponse();
exit;
}
else{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
Mage::app()->getResponse()->sendResponse();
exit;
}
}
Update:
i find a solution, to redirect after register to checkout page if there exist a product in cart, but is a problem, after register is complete in the checkout the Billing fields is not complete and the user is not login. Anyone?
New Update:
This is what I made to redirect after login and it is work perfect, I need to do the same for Register. The problem with Register is because here the lastUrl is login. Anyone? with any idea?
public function customerLogin(Varien_Event_Observer $observer)
{
if (Mage::helper('customerredirect')->isEnabled() && !Mage::getSingleton("core/session")->getRedirectregister()){
$lasturl = Mage::getSingleton('core/session')->getLastUrl();
if (strpos(Mage::helper('core/http')->getHttpReferer(), 'checkout') === false){
if (! preg_match("#customer/account/create#", $lasturl) && Mage::helper('customerredirect')->isoptionEnabled('login_customerredirect')) {
if(Mage::getSingleton('core/session')->getIsFromCart() == 1 || Mage::getSingleton('core/session')->getIsFromCheckout() == 1){
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('onestepcheckout/index'));
Mage::app()->getResponse()->sendResponse();
exit;
}
else
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
Mage::app()->getResponse()->sendResponse();
exit;
}
}
}
}
Mage::getSingleton("core/session")->setRedirectregister(false);
Mage::getSingleton('core/session')->setIsFromCart('0');
Mage::getSingleton('core/session')->setIsFromCheckout('0');
}
Update:
A good developer told me that is a way to do this. To add an event before going to register page then add an event observer after registration is complete and then check what is necessary. But I don't know to do this, maybe someone can help me with this? Thank you
Thank you
My Original Code
public function customerLogin(Varien_Event_Observer $observer)
{
if (Mage::helper('customerredirect')->isEnabled() && !Mage::getSingleton("core/session")->getRedirectregister()){
$lasturl = Mage::getSingleton('core/session')->getLastUrl();
if (strpos(Mage::helper('core/http')->getHttpReferer(), 'checkout') === false){
if (! preg_match("#customer/account/create#", $lasturl) && Mage::helper('customerredirect')->isoptionEnabled('login_customerredirect')) {
if(Mage::getSingleton('core/session')->getIsFromCart() == 1 || Mage::getSingleton('core/session')->getIsFromCheckout() == 1){
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('onestepcheckout/index'));
Mage::app()->getResponse()->sendResponse();
exit;
}
else
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
Mage::app()->getResponse()->sendResponse();
exit;
}
}
}
}
Mage::getSingleton("core/session")->setRedirectregister(false);
Mage::getSingleton('core/session')->setIsFromCart('0');
Mage::getSingleton('core/session')->setIsFromCheckout('0');
}
/*method for SignUp Customerredirect*/
public function customerRegistration(Varien_Event_Observer $observer)
{
Mage::getSingleton("core/session")->setRedirectregister(true);
if (Mage::helper('customerredirect')->isEnabled() && Mage::helper('customerredirect')->isoptionEnabled('registration_customerredirect') ) {
$_session = $this->_getSession();
$_session->setBeforeAuthUrl(Mage::helper('customerredirect')->setRedirectOnSignup());
}
}
This is my config.xml of this extension
<events>
<customer_login>
<observers>
<customerredirect>
<class>customerredirect/observer_customer</class>
<method>customerLogin</method>
</customerredirect>
</observers>
</customer_login>
<customer_register_success>
<observers>
<customerredirect>
<class>customerredirect/observer_customer</class>
<method>customerRegistration</method>
</customerredirect>
</observers>
</customer_register_success>
</events>
So all I want now is the Register page to work like Login, In present the login redirection is perfect, but for Register always I am redirect to My Account page. Not to the checkout page.
New Option:
if (strpos(Mage::getSingleton('core/session')->getLastUrl(), 'checkout/cart') !== false) {
Mage::getSingleton('core/session')->setIsFromCart('1');
} else {
Mage::getSingleton('core/session')->setIsFromCart('0');
}
if (strpos(Mage::getSingleton('core/session')->getLastUrl(), 'onestepcheckout/index') !== false) {
Mage::getSingleton('core/session')->setIsFromCheckout('1');
} else {
Mage::getSingleton('core/session')->setIsFromCheckout('0');
}
There is an easier solution.
Create an override of:
/app/code/core/Mage/Customer/controllers/AccountController.php
Copy _loginPostRedirect() method
In the newly created file, in _loginPostRedirect method edit:
FROM:
$this->_redirectUrl($session->getBeforeAuthUrl(true));
TO:
$sUrl = $session->getBeforeAuthUrl( TRUE );
// Do url exclusions and conditional checks here
// Force user to go home on login.
$sUrl = Mage::getBaseUrl();
$this->_redirectUrl( $sUrl );
Cleaned up with your conditionals (they are a bit convoluted):
$sUrl = $session->getBeforeAuthUrl( TRUE );
if (Mage::helper('customerredirect')->isEnabled() && !Mage::getSingleton("core/session")->getRedirectregister())
{
$lasturl = Mage::getSingleton('core/session')->getLastUrl();
if (strpos(Mage::helper('core/http')->getHttpReferer(), 'checkout') === false)
{
if (! preg_match("#customer/account/create#", $lasturl) && Mage::helper('customerredirect')->isoptionEnabled('login_customerredirect'))
{
if( Mage::getSingleton('core/session')->getIsFromCart() == 1 || Mage::getSingleton('core/session')->getIsFromCheckout() == 1 )
{
$sUrl = Mage::getUrl('onestepcheckout/index');
}
else
{
$sUrl = Mage::getUrl('customer/account');
}
}
}
}
$this->_redirectUrl( $sUrl );
Edited for register:
$sUrl = $session->getBeforeAuthUrl( TRUE );
if (Mage::helper('customerredirect')->isEnabled() && !Mage::getSingleton("core/session")->getRedirectregister())
{
if (strpos(Mage::helper('core/http')->getHttpReferer(), 'checkout') === false)
{
if ( Mage::helper('customerredirect')->isoptionEnabled('login_customerredirect'))
{
$lasturl = Mage::getSingleton('core/session')->getLastUrl();
if( Mage::getSingleton('core/session')->getIsFromCart() == 1 || Mage::getSingleton('core/session')->getIsFromCheckout() == 1
|| preg_match("#customer/account/create#", $lasturl) )
{
$sUrl = Mage::getUrl('onestepcheckout/index');
}
}
}
}
I'm creating a buy-now button cs-cart add-on. I've created an add-on and I've made the add-to-cart functionality work. But cant redirect it to checkout page. I have used "fn_redirect("checkout")" function for the redirection. And used this function below this:
"fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);"
What should I do for redirection?
Edit:
My controller (buy_now.php)
if ($mode == 'add') {
if (empty($auth['user_id']) && Registry::get('settings.General.allow_anonymous_shopping') != 'allow_shopping')
{
return array(CONTROLLER_STATUS_REDIRECT, "auth.login_form?return_url=" . urlencode($_REQUEST['return_url']));
}
// Add to cart button was pressed for single product on advanced list
if (!empty($dispatch_extra)) {
if (empty($_REQUEST['product_data'][$dispatch_extra]['amount'])) {
$_REQUEST['product_data'][$dispatch_extra]['amount'] = 1;
}
foreach ($_REQUEST['product_data'] as $key => $data) {
if ($key != $dispatch_extra && $key != 'custom_files') {
unset($_REQUEST['product_data'][$key]);
}
}
}
$prev_cart_products = empty($cart['products']) ? array() : $cart['products'];
fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);
fn_save_cart_content($cart, $auth['user_id']);
$previous_state = md5(serialize($cart['products']));
$cart['change_cart_products'] = true;
fn_calculate_cart_content($cart, $auth, 'S', true, 'F', true);
if (md5(serialize($cart['products'])) != $previous_state && empty($cart['skip_notification'])) {
$product_cnt = 0;
$added_products = array();
if (!empty($added_products)) {
Registry::get('view')->assign('added_products', $added_products);
if (Registry::get('config.tweaks.disable_dhtml') && Registry::get('config.tweaks.redirect_to_cart')) {
Registry::get('view')->assign('continue_url', (!empty($_REQUEST['redirect_url']) && empty($_REQUEST['appearance']['details_page'])) ? $_REQUEST['redirect_url'] : $_SESSION['continue_url']);
}
fn_redirect(Registry::get('config.https_location') . "/checkout");
// $msg = Registry::get('view')->fetch('views/checkout/components/product_notification.tpl');
//fn_set_notification('I', __($product_cnt > 1 ? 'products_added_to_cart' : 'product_added_to_cart'), $msg, 'I');
$cart['recalculate'] = true;
} else {
fn_set_notification('N', __('notice'), __('product_in_cart'));
}
}
unset($cart['skip_notification']);
$_suffix = '.checkout';
}
`
hook template : add_to_cart.post.tpl
{$id = "buy_now_{$product.product_id}"}
<button id="opener_{$id}" name="dispatch[buy_now.add..{$product.product_id}]" class=" vs-button buynow_btn_">Buy Now</button>
I'd consider putting your fn_redirect("checkout") code into an if/else statement to see what's happening with it.
If you have this code:
fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);
Then surely you can put the redirection to the checkout page underneath it?
$redirect_url = "http://testcheckout.com?test=test"; //change this!
$errorMessage = "I should have redirected already....";
if (!empty($redirect_url)) {
//if it's not empty then it should redirect.
fn_redirect($redirect_url);
//Then put a die statement in here just to check it's not executing
//anything else and you can see if the redirect has a problem:
die(print_r($errorMessage, true ));
}
else {
//otherwise there is a problem with the supplied redirect url (empty)
die(print_r($redirect_url, true ));
}
I'd also take a look at this page which might help more:
http://forum.cs-cart.com/topic/6873-direct-buy-button/
Hope that helps!
I m facing a problem while implementing my captcha code on the wp-login.php.
I want to redirect on wp-admin page of my website when the captcha code maches. Is there a way to redirect on wp-admin page??
my code is :
function captcha_login_check($url) {
if (isset($_POST["security_check"]))
{
$code = str_decrypt($_POST["security_check"]);
if (!( $code == $_POST['security_code'] && !empty($code) ))
{
wp_clear_auth_cookie();
return $_SERVER["REQUEST_URI"];
?>
<span style="color:red">
Error, the Security Code does not match. Please Try Again.
</span>
<br>
<?php
}
else
{
$url = $_SERVER['HTTP_HOST']."/wp-admin/";
return $url;
}
}
}
Use like
else
{
$url = $_SERVER['HTTP_HOST']."/wp-admin/";
header('Location:'.$url);
}
Also You can use this
else
{
$url = $_SERVER['HTTP_HOST']."/wp-admin/";
echo ("<script>location.href='$url'</script>");
}
I'm working on a website and the index page checks if the user is logged in or not with this piece of code:
if (!$_SESSION['login'] && $_SESSION['login'] == "") {
include_once($_SERVER['DOCUMENT_ROOT'] . "/login/");
} elseif ($_SESSION['login'] == 1) {
include_once($_SERVER['DOCUMENT_ROOT'] . "/main/");
}
But I want it to look cleaner, then I started wondering if was possible to achieve something like this with a function:
checklogin($_SESSION['login']);
I don't have much experience with functions, so i'm sorry if my question looks stupid, so thanks in advance.
Try this
if(check_login()) {
echo 'You are in!';
} else {
header('Location: login.php');
exit;
}
function check_login () {
if(isset($_SESSION['login'] && $_SESSION['login'] != '') {
return true;
} else {
false;
}
}
Just use empty:
if ( empty($_SESSION['login']) ) {
include_once($_SERVER['DOCUMENT_ROOT'] . "/login/");
} else {
include_once($_SERVER['DOCUMENT_ROOT'] . "/main/");
}
Or condense it:
include_once $_SERVER['DOCUMENT_ROOT'].(empty($_SESSION['login']) ? "/login/" : "/main/");
There is what you need:
function userCheck()
{
return (isSet($_SESSION['login']) && $_SESSION['login']);
}
if(userCheck())
include_once($_SERVER['DOCUMENT_ROOT'] . "/main/");
else
include_once($_SERVER['DOCUMENT_ROOT'] . "/login/");
Disregarding the fact of whether or not your approach makes sense, I think this would do what you expect:
function checklogin($login){
if (!$login && $login == "") {
include_once($_SERVER['DOCUMENT_ROOT'] . "/path/");
}
}
// **** call to the function
checklogin($_SESSION['login']);
// ****
You can use this function:
function checklogin() {
return (isset($_SESSION['login'])) ? true : false;
}
then on pages you want to check whether the user is logged in or not, you can:
if(checklogin() === true){
//here you would put what you want to do if the user is logged in
} else {
//this would be executed if user isn't logged in
header('Location: protected.php');
exit();
//the above would redirect the user
}
I'm using PHP and JavaScript, and I got a problem when deal with the confirm() function in JavaScript.
Say I have a page add.php, firstly I receive some parameters passed from another page, and I check to see if they are valid or not. If yes, I just insert the data into db and return to another page, if they are not valid, there'll be a confirm() window popped up and let the user to choose whether to continue or not. If the user still choose to continue, I want the page to be reloaded with all the parameters sent again. But the problems is that I cannot get the parameter the second time add.php is loaded.
Previously I didn't use a window.onload function and confirm() pop up, but an < a href> link instead, everything worked fine (Please see the attached code at the end). But when I tried to use the following code, the same url stopped working
echo "<script type=\"text/javascript\">";
echo "window.onload = function() {
var v = confirm(\"$name is not alive, do you want to add it into system?\");
if (v) {
window.location.href= \"add.php?type=room&name=$name&area\"
+ \"=$area&description=$description&\"
+ \"capacity=$capacity&confirm=Y\";
} else {
window.location.href= \"admin.php?area=$area\";
}
}";
echo "</script>";
Following is the previous version, instead of using window.onload(), I used < a href="..." /> link, everything worked fine at that time. get_form_var is a function in functions.inc, which is to get the parameter using $_GET arrays.
<?php
require_once "functions.inc";
// Get non-standard form variables
$name = get_form_var('name', 'string');
$description = get_form_var('description', 'string');
$capacity = get_form_var('capacity', 'string');
$type = get_form_var('type', 'string');
$confirm = get_form_var('confirm','string');
$error = '';
// First of all check that we've got an area or room name
if (!isset($name) || ($name === ''))
{
$error = "empty_name";
$returl = "admin.php?area=$area"
. (!empty($error) ? "&error=$error" : "");
header("Location: $returl");
}
// we need to do different things depending on if its a room
// or an area
elseif ($type == "area")
{
$area = mrbsAddArea($name, $error);
$returl = "admin.php?area=$area"
. (!empty($error) ? "&error=$error" : "");
header("Location: $returl");
}
elseif ($type == "room")
{
if (isset($confirm)){
$dca_osi = getOsiVersion($name);
$room = mrbsAddRoom(
$name,
$area,
$error,
$description,
$capacity,
$dca_osi,
1
);
$returl = "admin.php?area=$area"
. (!empty($error) ? "&error=$error" : "");
header("Location:$returl");
}
else {
$dca_status= pingAddress($name);
$dca_osi = getOsiVersion($name);
if( $dca_status == 0){
$room = mrbsAddRoom(
$name,
$area,
$error,
$description,
$capacity,
$dca_osi,
0
);
$returl = "admin.php?area=$area"
. (!empty($error) ? "&error=$error" : "");
header("Location:$returl");
}
else {
print_header(
$day,
$month,
$year,
$area,
isset($room) ? $room : ""
);
echo "<div id=\"del_room_confirm\">\n";
echo "<p>\n";
echo "$name is not alive, are you sure to add it into system?";
echo "\n</p>\n";
echo "<div id=\"del_room_confirm_links\">\n";
echo "<a href=\"add.php?type=room&name"
. "=$name&area=$area&description"
. "=$description&capacity=$capacity&confirm"
. "=Y\"><span id=\"del_yes\">"
. get_vocab("YES") . "!</span></a>\n";
echo "<a href=\"admin.php?area=$area\"><span id=\"del_no\">"
. get_vocab("NO") . "!</span></a>\n";
echo "</div>\n";
echo "</div>\n";
}
}
}
function pingAddress($host)
{
$pingresult = exec("/bin/ping -c 1 $host", $outcome, $status);
if ($status==0) {
return $status;
}
else {
return 1;
}
}
function getOsiVersion($host)
{
$community = 'public';
$oid = '.1.3.6.1.4.1.1139.23.1.1.2.4';
$sysdesc = exec("snmpwalk -v 2c -c $community $host $oid");
$start = strpos($sysdesc, '"');
if ($start!==false) {
$sysdesc = substr($sysdesc, $start+1,$sysdesc.length-1);
return $sysdesc;
}
else {
return "not available";
}
}
I've solved the problem, just simply by using "&" instead of " & amp;" in the url link... it works fine now...
You try location.reload() javascript call?