Pages

Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Sunday, August 18, 2013

Cakephp-Refresh Auth Session information after a database change of current user

In order to update current user logged in Auth Session after a database change in his information in Users Table use the following command

$userid=$this->Auth->user('id');

$this->Session->write('Auth',$this->User->read(null,$userid));

That's it and your auth session is updated..

This is usually done once a user updates his information....

Friday, May 3, 2013

Magento-Get information of Items in Cart

Magento-Get Information of Items in Cart

$items=Mage::getSingleton('Checkout/Session')->getQuote()->getAllItems();

foreach($items as $item)
{
    echo $item->getName();
                      ->getQty();
                      ->getPrice();
                      ->getSku();
                      ->getProductid()
}


Tuesday, November 6, 2012

Session data lost in chrome and Internet Explorer

In your header file or which ever file that loads first add the following piece of code

if(session_id()=='')
session_start();

This is a very simple way to start of session.Mostly now a days frameworks have this set already in their bootstrap files but still if you are loosing session you can start off session with this.

Saturday, August 25, 2012

SESSION DATA LOST PHP IIS SERVER

Session Data loses while making an ajax call to a file on IIS server hosting PHP. A very common issue stated on the PHP session_start page as well

http://php.net/manual/en/function.session-start.php

/***** sess1.php *****/
session_start();
$_SESSION["key1"] = "testvalue";
header("Location: sess2.php");

/***** sess2.php *****/
session_start();
echo "key1 = '".$_SESSION["key1"]."'";

PROBLEM:
All session data is lost after a header redirect from the first page on which the session is initialized. The problem is, the PHPSESSID cookie is not being sent to the browser (ANY browser, IE or Mozilla) on the initial session page with the header("Location: ...") redirect. This is unrelated to client cookie settings - the set-cookie: header just isn't sent.

SOLUTION:
I was able to remedy the problem by switching to the ISAPI DLL version. This seems to be an MS/IIS bug, NOT a PHP bug - go figure. I hope this saves you some headaches especially with your user authentication scripts!!


*same case happens if we make an ajax request to a file 

I am still looking for a way to switch to ISAPI dll version though?

Best way I could get was to use cookies in such case scenario if possible.
Things work well on Apache server though but I am still looking for a solution to this....?

Sunday, July 8, 2012

Magento Session storage?Which and when to choose??

Magento stores sessions by 4 means file-storage,database, memcached and tmpfs-backed file-storage

The benefits of file-based sessions for Magento are simplicity, stability and durability. It’s simple because you don’t have to do anything to set it up. It’s stable because most modern filesystems use journaling to make sure that in the event of a system crash your session data is consistent. I also durable, because a system restart will not cause you to lose your session data.

Add below line in local.xml to start file based storage
<session_save>session_save>

Database session storage is the other storage type.With database session storage the session data is stored in the Magento MySQL database. The connection used is the same as the core connection.

One of the key benefits of using database sessions is the clustered environment support. In a filesystem based session storage scheme, if you have more than one Magento frontend node in a cluster, they will need to share session data (unless you use a loadbalancer with sticky sessions) and the database gives you that capability quite easily.

To use the database for session storage simply have this in your local.xml


<session_save>session_save>

Memcached session storage takes a bit more setup than either of the previous two options.For starters you need a Memcached server running.
Once you have it up and running, the memcached session storage offers a number of benefits. Firstly it is very cluster friendly. The session data can be shared by any number of webnodes, and to make things even better you can easily add more memcached server nodes so that even your session storage can be scaled to handle many 1000′s of concurrent sessions*. Secondly, it is (or can be) separate of the database and web node entirely, which offloads the work of storing sessions from busy nodes in a high-traffic environment.
The memcached server is not tolerant to failures, if your system crashes or dies the data in memory will be lost. Being a separate server does allow the session storage to be kept running during a web or database node restart though – something you cannot do with the tmpfs storage option below.

To use the database for Memcached storage simply have this in your local.xml
 
<session_save>session_save>
<session_save_path>session_save_path>
 
tmpfs-backed Filesystem Session storage
 
This is not really a good idea for storing sessions, it’s highly volatile and unstable two things you probably don’t want for ecommerce store sessions. It’s also not scalable either as it relies on the machine’s physical memory, and you can only stick so much of that in – you might need it for the web server too. It will also not help at all in a clustered environment as it is machine specific.
Despite all it’s limitations I really wanted to test tmpfs sessions more out of curiosity than anything, I have a hunch that it will make quite a performance boost. Let’s see how it does in the benchmark section below.
If you’re keen to try this, I’ll assume you know what you’re doing on the system side of things. Mount var (or var/sessions) as a tmpfs and set Magento to use file based session storage like in the first option above.