automatic redirecting to base_url in codeigniter - codeigniter

I have not used redirect but even my page getting redirect automatically to home page. controller page:
//print_r($data);
$orderid = $this->Order_model->insert_order_detail();
if($orderid){
if ($cart = $this->cart->contents()){
foreach ($cart as $item):
$order_detail = array(
'order_id' => $orderid,
'product_id' => $item['id'],
'order_qty' => $item['qty']
);
$order_data = $this->Order_model->insert_order_data($order_detail);
endforeach;
}
}
$enscryptorder = $this->encryption->encrypt($orderid);
redirect('billing/payment_mode');
//-------herer page is redirecting to base not to billing controller

You can try this for your redirect code
redirect(base_url().'billing/payment_mode');
Did you also manage your routes in your config?

You can try this, add a URL helper in your autoload config. After that it may be work for you.
Thanks

Related

How to retain Magento customer session throughout all pages?

I am creating customer login using custom php code. I am using API calls for creating the frontend, so I need to maintain the logged in session values throughtout all the pages once the customer has logged in.
Code in a.php
require_once "../magento/app/Mage.php";
Mage::app('default');
umask(0);
Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
$session->start();
if (!empty($email) && !empty($password )) {
try {
$a = $session->login($email, $password );
$session->setCustomerAsLoggedIn( $session->getCustomer() );
if ($session->getCustomer()->getIsJustConfirmed()) {
$this->_welcomeCustomer($session->getCustomer(), true);
}
}
}
I am able to log in using this code but I need to maintain this logged in session throughout all the pages.
I tried to get the logged in user information from other page. But I can't.
Code in b.php
require_once "../magento/app/Mage.php";
umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton('customer/session');
$session->start();
var_dump(Mage::getSingleton('customer/session')->isLoggedIn());
if($session->isLoggedIn()) {
echo 'User logged In';
} else {
echo 'User not logged In';
}
After calling the page a.php and when I call b.php in the same browser, I need the customer information of the user logged in using a.php? Is that possible? Can anyone help me in this?
Try this one
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customerData = Mage::getSingleton('customer/session')->getCustomer();
echo $customerData->getId();
}
<?php
require_once "../magento/app/Mage.php";
Mage::app('default');
umask(0);
Mage::getSingleton('core/session', array('name' => 'frontend'));
var_dump(Mage::getSingleton('customer/session')->isLoggedIn());
// print true
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customerData = Mage::getSingleton('customer/session')->getCustomer();
echo $customerData->getId();
// return customer's id
}

integrating my own joomla login to main site

I am trying to make my own login form to extend more field information. I try to build it separate from my my site, so I save it to testlogin.php in base Joomla main site directory. Here is my script:
<?php
define('_JEXEC', 1 );
define ('JPATH_BASE', dirname(_FILE_));
define('DS',DIRECTORY_SEPARATOR);
require_once(JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once(JPATH_BASE.DS.'includes'.DS.'framework.php');
require_once(JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'factory.php');
$mainframe =& JFactory::getApplication('site');
$mainframe ->initialise();
$credentials=Array('username' => 'dadanuser', 'password' => 'dadan');
$options=Array('remember' => true);
$mainframe->login($credentials, $options);
//echo $result;
$user =& JFactory::getUser();
echo $user->username;
$session =& JFactory::getSession();
$myUser = $session->set( 'myUser', $user );
?>
I run it directly and I get login with username: dadanuser, but when I open Joomla main site I still not login yet, maybe I have to set session in right way?
anyone can help ?
Why reinvent the wheel? If you are in 2.5 or 3 you can just use a profile plugin to add the extra fields. If you are in 1.5 you can use the earlier version of that which was distributed as an extension.
http://joomlacode.org/gf/project/usermeta

Magento external Script and Session

I want to add an external script which gets a sku via GET check the ID and then redirect to the cart if available otherwise it sets en error and also redirecting to the cart.
The script is called from a product page:
http://myhost/scripts/addto.php?sku=12345
Here is the colmplete code
<?php
include_once '../../../../../app/Mage.php';
Mage::app();
$session = Mage::getSingleton('core/session', array('name' => 'frontend'));
$sku = $_GET['sku'];
if (!isset($_GET['qty'])) { $qty = '1'; } else { $qty = $_GET['qty']; }
$id = Mage::getModel('catalog/product')->getIdBySku($sku);
if ($id == '') {
$id = $sku;
Mage::getSingleton('checkout/session')->addError("Product not found!");
}
Works fine, but after logout and relogin the error message is missing. I found out that's because of a cookie which is set. After deleting that cookie the error message is working again after relogin.
What does not work?
You logout and login and then the script stop working? So the session is not found? The product ist not found? The product is not loaded? The user is not forwarded? :-)
Sure it does not. The Message is a Notice. If it is shown once, it is deleted.
What behaviour do you want?
use Mage::getSingleton('core/session')->addError("Product not found!");, maybe checkout/session is user specific...
cheers

Can't use session variable in routes.php file in codeigniter?

I am use following code to retrieve the session variable in routes.php
if($this->db_session->userdata('request_url')!="")
{
$route['user/(:any)'] = "search_user_name/redirect_url/".$_SESSION['request_url'];
$this->db_session->unset_userdata('request_url');
}
else {
$route['user/(:any)'] = "search_user_name/index/$1";
}
the session variable would be set into template/header.php
$this->db_session->set_userdata('request_url', $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
You can not use db_session in routes.php because routes.php is parsed before db_session is loaded.
Maybe you should create a base controller and redirect from the constructor of the base controller.
Correct me if iam wrong.
You can use hooks.
Codeigniter user guide hooks
You can use database in routes and put your routes url in database.
Here is an example:
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$table2 = $db->dbprefix.'lang';
$query2 = $db->get( $table2 );
$result2 = $query2->result();
foreach( $result2 as $row )
{
$fields = $db->list_fields($table2);
$findme = 'code';
foreach($fields as $field):
$pos = strpos($field, $findme);
if($pos !== false and $row->$field != ''):
$route[''.$row->$field.''] = 'main/setlang/$1';
endif;
endforeach;
}

Checking for Magento login on external page

I'm hitting a wall here while trying to access items from Magento on an external page (same server, same domain, etc, etc). I want to see if the user is logged into Magento before showing them certain parts on the site.
Keep in mind that this code exists outside of Magento.
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
if (empty($session))
{
$session = Mage::getSingleton("customer/session");
}
if($session->isLoggedIn())
echo "hi";
$cart = Mage::helper('checkout/cart')->getCart()->getItemsCount();
echo $cart;
$cart returns 0, where I definitely have products in my cart. isLoggedIn() also returns false. What am I doing wrong here? Is there an option in Magento that I need to turn on or off to be able to access this information outside of Magento?
Using the code above, I created a php file in the Magento folder. From there, added the number of items in the cart and whether you were logged in or not to an array and encoded it as json. I used some jquery on my external page to grab the file and pull the data I needed.
Not quite the ideal situation, but it works for now.
Are you including Mage.php (which defines getSingleton)?
require_once ($_SERVER['DOCUMENT_ROOT'] . '/app/Mage.php');
What does $session have in it after the getSingleton() call?
print_r ($session);
EDIT: I tried this on my end and was not able to get accurate isLoggedIn() or getItemsCount() data. When I dumped out $session its showing all the fields as 'protected.'
I'm not interested in requiring the user to log in...I merely want to access data from the already logged in session.
Anyone else have any thoughts on this? All the examples out there seem to be pre 1.4.x.
require_once "app/Mage.php";
umask(0);
Mage::app();
// require_once $_SERVER['DOCUMENT_ROOT'] . "/mage1/app/Mage.php";
// Customer Information
$firstname = "krishana";
$lastname = "singh";
$email = "krish.bhati#gmail.com";
$password = "myverysecretpassword";
// Website and Store details
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId;
$customer->setStore($store);
$mageRunCode = isset ( $_SERVER ['MAGE_RUN_CODE'] ) ? $_SERVER ['MAGE_RUN_CODE'] : '';
$mageRunType = isset ( $_SERVER ['MAGE_RUN_TYPE'] ) ? $_SERVER ['MAGE_RUN_TYPE'] : 'store';
$app = Mage::app ( $mageRunCode, $mageRunType );
Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton('customer/session');
$session->start();
$customer->loadByEmail($email);
$customer_id= $customer->getId();
if($customer_id){
Mage_Core_Model_Session_Abstract_Varien::start();
$session->login($email, $password);
$session->setCustomerAsLoggedIn($session->getCustomer());
echo $session->isLoggedIn() ? $session->getCustomer()->getName().' is online!' : 'not logged in';
}

Resources