Zend Sessions getting mixed up - zend-framework

I'm currently working on the login for a Zend Framework application, and I'm using a combination of Zend_Auth and Zend_Session using a database adapter (as described in the Zend Framework manuals).
I've made a resource for the session:
class DC_Resource_DbSession extends Zend_Application_Resource_ResourceAbstract{
public function init(){
}
public function setadapter($value){
$this->dbAdapter = $value;
}
public function setSession($adapter){
//put your code here
$config = array(
'name' => 'sessions',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime',
'db' => $adapter
);
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
Zend_Session::setOptions(array('name'=>'MY_SESSION_NAME'));
Zend_Session::start();
}
}
Zend Auth then uses the session to store some rudimentary authentication information.
However, when testing the login (from the same IP) if one user in our office logs in and another user goes to the site, they are logged in as the user!!! Can anyone help me figure out why they are using each other's sessions?

DOH!!!!
My humble, humiliated apologies. The id column datatype had been set to INT by our migrations guy - and obviously it needs to be VARCHAR....
smacks self in face...

Related

How to set up Omnipay with Laravel?

I am using this packet:
https://github.com/barryvdh/laravel-omnipay
In my controller I added:
$params = [
'amount' => '10',
'issuer' => 22,
'description' => 'desc',
'returnUrl' => URL::action('PurchaseController#returnApi', [43]),
];
$response = Omnipay::purchase($params)->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
return $response->getRedirectResponse();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
Here is my omnipay.php conf file:
<?php
return array(
/** The default gateway name */
'gateway' => 'PayPal_Express',
/** The default settings, applied to all gateways */
'defaults' => array(
'testMode' => true,
),
/** Gateway specific parameters */
'gateways' => array(
'PayPal_Express' => array(
'username' => '',
'landingPage' => array('billing', 'login'),
),
),
);
But get this error:
call_user_func_array() expects parameter 1 to be a valid callback,
class 'Omnipay\Common\GatewayFactory' does not have a method
'purchase'
Anyone can help me set this?
I created app on paypal and have details about it but don't know how to set it with this API...
I recommend that you switch from PayPal Express to PayPal REST. It is newer and has better documentation.
I have looked through the laravel-omnipay package and I can't see a use case for it. I would just code to the omnipay package directly.
I recommend that you create a unique transaction ID for each transaction and provide that as part of the URLs for returnUrl and cancelUrl so that you can identify which transaction you are dealing with in the return and cancel handlers.
I think that you are taking the examples in the laravel-omnipay package too literally. You don't need or want those echo statements there. You should be capturing the response from purchase() even if it is a redirectResponse and doing a getTransactionReference() check on it, because you will need that transaction reference later, e.g. for transaction lookup. You should store it in the transaction record that you created before calling purchase().
You may use
use Omnipay\Omnipay;
in your controller, change it to
use Omnipay;

creating web services for iphone and cakephp project

Is there any way to collaborate Cakephp project with Iphone. Like: retrieving json data with cakephp models as WebServices in iphone. The aim behind this question is to use the cakephp code rather then creating WebServices differently.
Your help will be appreciated, Thanks!
Cakephp is a framework that outputs json data as much as like any other php frameworks out there.
You have to write functiosn like there:
public function api_get_release_tracks($release_id = null) {
if($release_id) {
$tracks = $this->Track->find('all', array( //sql queries are better here
'fields' => array('id', 'name', 'duration', 'duration_str',
'sample_audio', 'price', 'local_price'),
'conditions' => array('release_id' => $release_id),
'order' => array('position ASC')
));
$this->set('tracks', $tracks);
$this->set('_serialize', 'tracks');
}
}
Then you can get the json output in this url:
http://localhost:8090/{api name in cofig}/{controller name}/{things after api_ in function name}/{input parameters}.json
read more in here
Also you can alter the routing to change the name
api
to anything in
Configure::write('Routing.prefixes', array('master', 'api'));
in core.php in app/config

how to use Zend_Loader_PluginLoader?

I am trying to optimize zend for performance.
I used as much cache as possible and got to the code of this page
where do i have to write it ? i tried putting it in bootstrap __initAutoload() but the profiler shows no change whatsover
$classFileIncCache = APPLICATION_PATH . '/../data/pluginLoaderCache.php';
if (file_exists($classFileIncCache)) {
include_once $classFileIncCache;
}
Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
Can someone explain how to use it pluginloader and if it has a performance increase?
here is part of my bootstrap
protected function _initSessionAfterDb()
{
//http://stackoverflow.com/questions/1100562/zend-error-via-my-ini-file
$this->bootstrap('db');
$this->bootstrap('session');
}
protected function _initSession()
{
$this->bootstrap('cache');//http://stackoverflow.com/questions/5271018/zend-how-to-enable-cachemetadata-on-session-table
//NOTE: this config is also passed to Zend_Db_Table so anything specific
//to the table can be put in the config as well
$config = array(
'name' => 'session', //table name as per Zend_Db_Table
'primary' => array(
'session_id', //the sessionID given by PHP
'save_path', //session.save_path
'name', //session name
//'cols' => array('session_id', 'save_path', 'name', 'modified', 'lifetime', 'session_data')
),
'primaryAssignment' => array(
//you must tell the save handler which columns you
//are using as the primary key. ORDER IS IMPORTANT
'sessionId', //first column of the primary key is of the sessionID
'sessionSavePath', //second column of the primary key is the save path
'sessionName', //third column of the primary key is the session name
),
'modifiedColumn' => 'modified', //time the session should expire
'dataColumn' => 'session_data', //serialized data
'lifetimeColumn' => 'lifetime', //end of life for a specific record
'user_id' => 'user_id'
);
//Tell Zend_Session to use your Save Handler
$savehandler = new Zend_Session_SaveHandler_DbTable($config);
//http://framework.zend.com/wiki/display/ZFPROP/Zend_Session_SaveHandler_DbTable
//cookie persist for 30 min
$config = Zend_Registry::get('config');
$seconds = $config->session->seconds_life;
//make the session persist for 30 min
$savehandler->setLifetime($seconds)
->setOverrideLifetime(true);
Zend_Session::setSaveHandler($savehandler);
Zend_Session::start();
}
I think you are not starting on the good foot, early optimization is the root of all evil. First I think you should investigate which part of your application is the slowest and try to fix it, xdebug should be able to help to get some performance data.
The plugin loader cache would increase the performance but not by a great deal, the framework search in the filesystem the plugins you are using. Enabling the cache would skip the searching process but I doubt it would make your application 50% faster all suddendly.
Also to answer where you should write it, like you mentioned the bootstrap is probably the best place.

Zend Framework: Need help setting up Routing

how do i set up routing as follows
these work with the standard routing
/posts => index action (listing)
/posts/view => view action (individual post)
/posts/add => add action
/posts/edit => edit action
what abt these?
/posts can by filtered based on 1 or more query strings, in any order. eg.
/posts/tagged/tag1
/posts/tagged/tag1/timeframe/1w => fyi. 1w means 1 week
/posts/timeframe/1w/tagged/tag1 => can be in any order
/posts/sortby/dtposted => more options maybe added
how can i handle these? i tried
$route = new Zend_Controller_Router_Route(
'posts/*',
array(
'controller' => 'posts',
'action' => 'index'
)
);
$router->addRoute('postsIndex', $route);
but of cos, all routes to posts/* goes to the index controller. not what i want
You dont need to use a route for those url's if your using proper naming conventions it should naturally.
class PostsController extends Zend_Controller_Action{
public function viewAction(){
}
public function editAction(){
}
public function addAction(){
}
public function indexAction(){
}
}
I suggest going back to basics and learning how controllers models and views work in the zend framework before trying to understand routing :)

Using Zend Framework Db Tables without MVC

I am trying to use the Zend Framework without using the MVC structure, specifically the Db_Table classes.
I have created a couple of classes representing my database tables, i.e.
class DBTables_Templates extends Zend_Db_Table_Abstract
{
protected $_name = "templates";
}
When I try to instantiate this class (it is included fine), I get the following error:
Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for DBTables_Templates'
Does anyone know how I create and include the database adapter for the Db_Table classes to use?
Any pointers are greatly appreciated! I am using the latest version of ZF.
You need to create a Zend_Db_Adapter, which is the class you use to connect to the database.
$db = new Zend_Db_Adapter_Pdo_Mysql(array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test'
));
Or you can use the factory() method to make instantiation more configurable:
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test'
));
See http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.connecting
Then specify this adapter object to your table class. There are at least three ways to do this:
Set an application-wide default for all tables:
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Specify the adapter to the table constructor:
$table = new MyTable( array('db'=>$db) );
Store the adapter in the registry and specify it to the table or set it as default:
Zend_Registry::set('my_db', $db);
$table = new MyTable( array('db'=>'my_db') );
// alternatively:
Zend_Db_Table_Abstract::setDefaultAdapter('my_db');
See http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.constructing