Saturday, 15 March 2014

php - Codeigniter random session logouts (Already tried override session class AND raising session_time_to_update -



php - Codeigniter random session logouts (Already tried override session class AND raising session_time_to_update -

i have tried both suggestions at: codeigniter session bugging out ajax calls

but $config['sess_time_to_update'] = php_int_max still seeing random logouts.

i took suggestions of creating class my_session

user's still reporting random logouts , logs seem indicate this.

edit: here session config:

$config['sess_cookie_name'] = 'phppos'; $config['sess_expiration'] = 86400; $config['sess_expire_on_close'] = true; $config['sess_encrypt_cookie'] = false; $config['sess_use_database'] = true; $config['sess_table_name'] = 'sessions'; $config['sess_match_ip'] = false; $config['sess_match_useragent'] = true; $config['sess_time_to_update'] = php_int_max;

i think you're suffering ajax session race condition. had same problem, , solved overriding ci session class. have article here:

http://www.hiretheworld.com/blog/tech-blog/codeigniter-session-race-conditions

the cleanest thing utilize my_session class, in libraries folder, , override methods written in link above. sorry lack of indentation, :p

class my_session extends ci_session { public function __construct() { parent::__construct(); } /********************************************************************* * overrides codeigniter session library * * handle race status during session_id updates. * - maintain old session id around in case have handle race * conditions. * - changes marked string "old_session_id_changes". * * session table changes: * alter table `sessions` add together column `old_session_id` varchar(40) default null comment 'old session id' after `user_data`, * add together index `old_session_id`(`old_session_id`); * delete `sessions`; *********************************************************************/ /** * fetch current session info if exists * * @return bool */ public function sess_read() { // fetch cookie $session = $this->ci->input->cookie($this->sess_cookie_name); // no cookie? goodbye cruel world!... if ($session === null) { log_message('debug', 'a session cookie not found.'); homecoming false; } // decrypt cookie info if ($this->sess_encrypt_cookie === true) { $session = $this->ci->encrypt->decode($session); } else { // encryption not used, need check md5 hash $hash = substr($session, strlen($session)-32); // lastly 32 chars $session = substr($session, 0, strlen($session)-32); // md5 hash match? prevent manipulation of session info in userspace if ($hash !== md5($session.$this->encryption_key)) { log_message('error', 'the session cookie info did not match expected. possible hacking attempt.'); $this->sess_destroy(); homecoming false; } } // unserialize session array $session = $this->_unserialize($session); // session info unserialized array right format? if ( ! is_array($session) or ! isset($session['session_id'], $session['ip_address'], $session['user_agent'], $session['last_activity'])) { $this->sess_destroy(); homecoming false; } // session current? if (($session['last_activity'] + $this->sess_expiration) < $this->now) { $this->sess_destroy(); homecoming false; } // ip match? if ($this->sess_match_ip === true && $session['ip_address'] !== $this->ci->input->ip_address()) { $this->sess_destroy(); homecoming false; } // user agent match? if ($this->sess_match_useragent === true && trim($session['user_agent']) !== trim(substr($this->ci->input->user_agent(), 0, 120))) { $this->sess_destroy(); homecoming false; } // there corresponding session in db? if ($this->sess_use_database === true) { /* * begin old_session_id_changes * * search both session_id , old_session_id fields * incoming session id. * * used be: * $this->ci->db->where('session_id', $session['session_id']); * * manually create or status because causes to the lowest degree * disturbance existing code. * * store session id cookie can see if * came in through old session id later. */ $this->ci->db->where( '(session_id = ' . $this->ci->db->escape($session['session_id']) . ' or old_session_id = ' . $this->ci->db->escape($session['session_id']) . ')' ); $this->cookie_session_id = $session['session_id']; /* * end old_session_id_changes */ if ($this->sess_match_ip === true) { $this->ci->db->where('ip_address', $session['ip_address']); } if ($this->sess_match_useragent === true) { $this->ci->db->where('user_agent', $session['user_agent']); } $query = $this->ci->db->limit(1)->get($this->sess_table_name); // no result? kill it! if ($query->num_rows() === 0) { $this->sess_destroy(); homecoming false; } // there custom data? if so, add together main session array $row = $query->row(); if ( ! empty($row->user_data)) { $custom_data = $this->_unserialize($row->user_data); if (is_array($custom_data)) { foreach ($custom_data $key => $val) { $session[$key] = $val; } } } /* * begin old_session_id_changes * * pull session_id database populate curent * session id because old 1 stale. * * pull old_session_id database can * compare current (cookie) session id against later. */ $session['session_id'] = $row->session_id; $session['old_session_id'] = $row->old_session_id; /* * end old_session_id_changes */ } // session valid! $this->userdata = $session; unset($session); homecoming true; } // -------------------------------------------------------------------- /** * write session info * * @return void */ public function sess_write() { // saving custom info db? if not, update cookie if ($this->sess_use_database === false) { $this->_set_cookie(); return; } // set custom userdata, session info set in sec $custom_userdata = $this->userdata; $cookie_userdata = array(); // before continuing, need determine if there custom info deal with. // let's determine removing default indexes see if there's left in array // , set session info while we're @ foreach (array('session_id','ip_address','user_agent','last_activity') $val) { unset($custom_userdata[$val]); $cookie_userdata[$val] = $this->userdata[$val]; } /* * begin old_session_id_changes * * old_session_id has own field, doesn't need go * cookie because we'll retrieve database. */ unset($custom_userdata['old_session_id']); /* * end old_session_id_changes */ // did find custom data? if not, turn empty array string // since there's no reason serialize , store empty array in db if (count($custom_userdata) === 0) { $custom_userdata = ''; } else { // serialize custom info array can store $custom_userdata = $this->_serialize($custom_userdata); } // run update query $this->ci->db->where('session_id', $this->userdata['session_id']); $this->ci->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); // write cookie. notice manually pass cookie info array // _set_cookie() function. function store $this->userdata, // in case array contains custom data, not want in cookie. $this->_set_cookie($cookie_userdata); } // -------------------------------------------------------------------- /** * update existing session * * @return void */ public function sess_update() { // update session every 5 minutes default if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now) { return; } // _set_cookie() handle if aren't using database sessions // pushing userdata cookie. $cookie_data = null; /* * begin old_session_id_changes * * don't need regenerate session if came in indexing * old_session_id), send out cookie anyway create sure * client has re-create of new cookie. * * isset check first in case we're not using database * store data. old_session_id field exists in * database. */ if ((isset($this->userdata['old_session_id'])) && ($this->cookie_session_id === $this->userdata['old_session_id'])) { // set cookie explicitly have our session info $cookie_data = array(); foreach (array('session_id','ip_address','user_agent','last_activity') $val) { $cookie_data[$val] = $this->userdata[$val]; } $this->_set_cookie($cookie_data); return; } /* * end old_session_id_changes */ // save old session id know record // update in database if need $old_sessid = $this->userdata['session_id']; $new_sessid = ''; { $new_sessid .= mt_rand(0, mt_getrandmax()); } while (strlen($new_sessid) < 32); // create session id more secure we'll combine user's ip $new_sessid .= $this->ci->input->ip_address(); // turn hash , update session info array $this->userdata['session_id'] = $new_sessid = md5(uniqid($new_sessid, true)); $this->userdata['last_activity'] = $this->now; // update session id , last_activity field in db if needed if ($this->sess_use_database === true) { // set cookie explicitly have our session info $cookie_data = array(); foreach (array('session_id','ip_address','user_agent','last_activity') $val) { $cookie_data[$val] = $this->userdata[$val]; } /* * begin old_session_id_changes * * save old session id old_session_id field * can reference later. * * rewrite cookie's session id if there 0 affected rows * because means request changed database * under current request. in case, want homecoming * value consistent previous request. reread * after update phone call here minimize timing problems. * should in transaction databases back upwards them. * * rewrite userdata future calls sess_write * output right cookie data. * * used be: * $this->ci->db->query($this->ci->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid))); */ $this->ci->db->query($this->ci->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid, 'old_session_id' => $old_sessid), array('session_id' => $old_sessid))); if ($this->ci->db->affected_rows() === 0) { $this->ci->db->where('old_session_id', $this->cookie_session_id); $query = $this->ci->db->get($this->sess_table_name); // we've lost track of session if there no results, // don't set cookie , return. if ($query->num_rows() == 0) { return; } $row = $query->row(); foreach (array('session_id','ip_address','user_agent','last_activity') $val) { $this->userdata[$val] = $row->$val; $cookie_data[$val] = $this->userdata[$val]; } // set request session id old session id // won't seek regenerate cookie 1 time again on request -- // in case sess_update ever called 1 time again (which // shouldn't be). $this->cookie_session_id = $this->userdata['old_session_id']; } /* * end old_session_id_changes */ } // write cookie $this->_set_cookie($cookie_data); } /********************************************************************* * end overrides codeigniter session library *********************************************************************/

php codeigniter session

java - Added new bean.xml and get class path resource [Spring-Mail.xml] cannot be opened because it does not exist] with root cause -



java - Added new bean.xml and get class path resource [Spring-Mail.xml] cannot be opened because it does not exist] with root cause -

i have tried follow illustration at: (http://www.mkyong.com/spring/spring-sending-e-mail-with-attachment/) add together mail service bean project, doesn't seem work. problem think can't add together new beans, 1 year ago worked on project, know might have missed?

jun 19, 2014 11:06:52 fm org.apache.catalina.core.standardwrappervalve invoke severe: servlet.service() servlet [restservices] in context path [/pyramid] threw exception [request processing failed; nested exception org.springframework.beans.factory.beandefinitionstoreexception: ioexception parsing xml document class path resource [spring-mail.xml]; nested exception java.io.filenotfoundexception: class path resource [spring-mail.xml] cannot opened because not exist] root cause java.io.filenotfoundexception: class path resource [spring-mail.xml] cannot opened because not exist @ org.springframework.core.io.classpathresource.getinputstream(classpathresource.java:172) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:329) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:303) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:180) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:216) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:187) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:251) @ org.springframework.context.support.abstractxmlapplicationcontext.loadbeandefinitions(abstractxmlapplicationcontext.java:127) @ org.springframework.context.support.abstractxmlapplicationcontext.loadbeandefinitions(abstractxmlapplicationcontext.java:93) @ org.springframework.context.support.abstractrefreshableapplicationcontext.refreshbeanfactory(abstractrefreshableapplicationcontext.java:129) @ org.springframework.context.support.abstractapplicationcontext.obtainfreshbeanfactory(abstractapplicationcontext.java:540) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:454) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:139) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:83) @ se.kth.pyramidstatus.webservices.rest.statuscontroller.loaddata(statuscontroller.java:153) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ org.springframework.web.method.support.invocablehandlermethod.invoke(invocablehandlermethod.java:215) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:132) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:104) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:749) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:689) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:83) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:938) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:870) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:961) @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:852) @ javax.servlet.http.httpservlet.service(httpservlet.java:621) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:837) @ javax.servlet.http.httpservlet.service(httpservlet.java:728) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:305) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:51) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:222) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:123) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:100) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:953) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1041) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:603) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:310) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745)

thanks in forehand

edit 1, bean.xml:

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean id="mailsender" class="org.springframework.mail.javamail.javamailsenderimpl"> <property name="host" value="smtp.gmail.com" /> <property name="port" value="587" /> <property name="username" value="username" /> <property name="password" value="password" /> <property name="javamailproperties"> <props> <prop key="mail.smtp.auth">true</prop> <prop key="mail.smtp.starttls.enable">true</prop> </props> </property> </bean> <bean id="mailmail" class="com.mkyong.common.mailmail"> <property name="mailsender" ref="mailsender" /> <property name="simplemailmessage" ref="customemailmessage" /> </bean> <bean id="customemailmessage" class="org.springframework.mail.simplemailmessage"> <property name="from" value="from@no-spam.com" /> <property name="to" value="to@no-spam.com" /> <property name="subject" value="testing subject" /> <property name="text"> <value> <![cdata[ dear %s, mail service content : %s ]]> </value> </property> </bean> </beans>

edit 2, code of execution:

applicationcontext context = new classpathxmlapplicationcontext("spring-mail.xml"); mailmail mm = (mailmail) context.getbean("mailmail"); mm.sendmail("yong mook kim", "this text content");

add xml file path sub directory of resources :

applicationcontext context = new classpathxmlapplicationcontext("/mailsend/spring-mail.xml"); //here mailsend dir name have taken mailmail mm = (mailmail) context.getbean("mailmail"); mm.sendmail("yong mook kim", "this text content");

java xml spring maven

mysql - Optimise Quesry containing Joins and Sub Queries -



mysql - Optimise Quesry containing Joins and Sub Queries -

i've inherited application client , have been working on next query takes 187 seconds , searches 304m table rows in order send 444 result rows.

am right want rid of sub selects , replace them joins? can't find way correctly. help optimising query hugely appreciated. thanks...

select business.name, business.primary_city, count(click.id) clicks, count(distinct email_leads.parent_message_id) tot_email_leads, count(bc.business_id) county_no, count(br.business_id) region_no, count(reveals.id) reveals_no businesses business left bring together business_clickthroughs click on ( business.id = click.business_id , (click.created between '2014-04-01 00:00:00' , '2014-04-30 23:59:59')) left bring together users u on business.id = u.business_id left bring together messages email_leads on (u.id = email_leads.from_to , (email_leads.parent_message_id null or email_leads.parent_message_id = email_leads.id ) , (email_leads.created between '2014-04-01 00:00:00' , '2014-04-30 23:59:59')) left bring together business_counties bc on business.id = bc.business_id left bring together businesses_business_types bt on business.id = bt.business_id left bring together business_reveals reveals on (reveals.business_id = business.id , (reveals.created between '2014-04-01 00:00:00' , '2014-04-30 23:59:59')) left bring together business_regions br on business.id = br.business_id 1=1 grouping business.id;

judging query writing, subselects right way go. don't show actual original query, speculation.

your query joining info along separate dimensions -- users, messages, counties, "reveals" (whatever is). joins result in cartesian product of these dimensions each business, farther magnifying info , slowing query down.

and, if larger tables have 300+ 1000000 rows, 300 seconds summarize all info in 8 or tables doesn't seem unreasonable. query doesn't have where conditions filtering data. joins left joins, reducing filtering.

if performance issue, inquire another question. include actual query, explain plan query, , layouts of tables (particularly index structures).

mysql sql join subquery

web services - Soap UI to Exchange -



web services - Soap UI to Exchange -

i trying connect soap ui our exchange server maintain getting error in soap ui of

error loading [https://<<our exchange server>>/ews/services.wsdl]: org.apache.xmlbeans.xmlexception: org.apache.xmlbeans.xmlexception: error: unexpected element: string

i using our endpoint have been reading , not wsdl url.

https://<<our exchange server>>/ems/exchange.asmx

anyone know might going on here?

not sure if typo in code or comment, ewsurl should https://mail.contoso.com/ews/exchange.asmx, not /ems/.

web-services soap wsdl exchange-server ews

Matlab Time-varying covariance matrix loop -



Matlab Time-varying covariance matrix loop -

i have portfolio assets , calculate variance of portfolio. calculated weights of assets , covariance matrix. both time-varying. variance need formula below:

wt'*sigma_1*wt = variance portfolio

in matlab used next code calculate weight of each asset:

for t=1:n at_1(:,t) = inv(sigma_1(:,:,t))*fit_1'; wt_1(t,1) = at_1(1,t)/sum(at_1(:,t)); wt_1(t,2) = at_1(2,t)/sum(at_1(:,t)); wt_1(t,3) = at_1(3,t)/sum(at_1(:,t)); wt_1(t,4) = at_1(4,t)/sum(at_1(:,t)); wt_1(t,5) = at_1(5,t)/sum(at_1(:,t)); wt_1(t,6) = at_1(6,t)/sum(at_1(:,t)); wt_1(t,7) = at_1(7,t)/sum(at_1(:,t)); wt_1(t,8) = at_1(8,t)/sum(at_1(:,t)); wt_1(t,9) = at_1(9,t)/sum(at_1(:,t)); wt_1(t,10) = at_1(10,t)/sum(at_1(:,t)); end

where sigma_1 covariance matrix. need loop calculate time-varying variance of portfolio. have 10 time-varying weights, , time-varying covariance sigma_1.i stuck writing loop that. can help me this?

have tried this?

t=1:n at_1(:,t) = inv(sigma_1(:,:,t))*fit_1'; k=1:10 wt_1(t,k) = at_1(k,t)/sum(at_1(:,t)); end end

matlab matrix conditional covariance

java - Graph Node doesnt loop through all neighbouring nodes? -



java - Graph Node doesnt loop through all neighbouring nodes? -

im having troubles graph assignment, i've run issue cant seem find.

system.out.println(plattegrond.getgraph().neighbours("een").tostring()); system.out.println(plattegrond.isroute("een", "drie", new hashset<string>()));

these lines of code print

[twee, drie, vier] false

so seems, "een" has "twee", "drie", , "vier" neighbours. isroute method returns false. method shown below.

public boolean isroute(string nodea, string nodeb, set<string> visited) { visited.add(nodea); if(nodea.equals(nodeb)) { homecoming true; } for(string neighbour : graph.neighbours(nodea)) { if(!visited.contains(neighbour)) { homecoming isroute(neighbour, nodeb, visited); } } homecoming false; }

i've traced steps debugger, , in enhanced loop, "drie" not come neighbour. "twee" , "four" will. same problem happens if seek find path "zes". when inquire "twee" neighbours are,

[een, vier, zes]

the isroute method 1 time again homecoming false when inquire find route "zes". 1 time again "zes" not come in loop neighbour. however, when inquire find route either "twee" or "four" homecoming true.

im lost on one.

there problem there... in have if statement return.. first neighbour twee , not in list visit twee , never go next iteration because of homecoming statement.

try using boolean variable , doing this:

boolean b = false; for(string neighbour : graph.neighbours(nodea)) { if(!visited.contains(neighbour)) { // statement can never alter b false 1 time becomes true // , create sure homecoming after checking whole set of neighbours b = b || isroute(neighbour, nodeb, visited); } } homecoming b;

this might not exact right solution @ to the lowest degree know problem... returning after first item , not iterating on neighbours.

java recursion graph

python - Django template tags forloop -



python - Django template tags forloop -

i have created template tag , trying loop through results template tag don't results

tags.py

from django import template loadprograms import dbcontext register = template.library() @register.simple_tag def get_category(): x = dbcontext.dbcontext() results = x.executequery("select name categories") categories = [each[0] each in results] homecoming categories

template code

{% load category_tags %} {% get_category %} {% each in get_category %} {{ each }} {% endfor %}

the {% get_category %} prints categories without issues loop stmt loop through results not work

what problem?

to create alter in tag, you'll have set variable in context, if objective have list of categories available in templates, have passed in view - need write template context processor, allow views have variable in context.

a template context processor method adds request context, returning dictionary. think of view function, returns context.

from .models import categories def cat_names(request): homecoming {'category_names': category.objects.values_list('name', flat=true)}

to activate context processor, have few things:

add above code file called template_processors.py in same place models.py , views.py.

in settings.py, add together fully-qualified name of method template_context_processors setting, making sure don't override defaults. easily, import default settings first, add together it:

from django.conf.default_settings import template_context_processors tcp template_context_processors = tcp + ('yourapp.template_processors.cat_names',)

use render shortcut, create sure context correctly passed.

in views, can this:

from django.shortcuts import render def home(request): homecoming render(request, 'home.html')

in home.html, can do:

{% name in category_names %} {{ name }} {% endfor %}

python django