w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Django - Difference between Database backed sessions and Cookie Based Session?
Cookie Sessions Store their data on the client/user end Work smoothly when you have a cluster of web servers Browsers typically limit cookies to a maximum size of around 4 kilobytes per domain Cookies can be set to a long lifespan, which means that data stored in a cookie can be stored for months if not years (Users can clear cookies though) Somewhat easily hacked Database Sessions Store their data server side One of your web servers handles the first request, other web servers in your cluster will not have the stored information Clients do not have access to the information you store about them and therefore better for sensitive data. Data doesn't have to travel from client to server on each request (clients just need to send an ID and the data is loaded from the local file) Can be

Categories : Django

Pass around state without cluttering code with implicits
Embed the individual players within a Players class: class Players(init: Array[String]) { players => trait Player ... val (p1, p2) = init.map(_.trim.toLowerCase match { case Array("x") => (new Player1 with Human, new Player2 with Human) ... } def nextPlayer(player: Player): Player = if (player eq p1) p2 else p1 ... }

Categories : Scala

Creating Django sessions
I ran into the same situation with my django project. I solved it by making a view that was similar too: def login_page(request): if request.user.is_authenticated(): return redirect(<insert your desired page here>) else: return render(<whatever the login page is>) This way, if the user is logged in, they will be redirected to whatever page you want them to be. EDIT: In response to the comments below, I am modifying my answer (original is still above). Here is what I have done to solve your problem. from django.contrib.auth.views import login def custom_login(request, **kwargs): """ Redirects the user to the desired page if they are authenticated """ if request.user.is_authenticated(): return redirect(<whatever pag

Categories : Django

Ignore "Unused Entity Issue: Unused Variable" in a single file
You can turn off specfic warnings in Clang using a pragma directive and the "diagnostic" keyword, like so: #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-variable" // Insert code here #pragma clang diagnostic pop No unused variable warnings will be produced for the code between the push and the pop. A second option, even more targeted, is to mark a particular variable with a GCC-style attribute, specifically, "unused". Clang honors GCC's established attributes and won't issue a warning about that one variable: __attribute__((unused)) NSString * thisStringIsJustForFun = @"It's only work if somebody makes you do it.";

Categories : Objective C

How to store an object in django sessions framework
the interpreter never reaches this part request.session['response'] = response this means that either our form isn't valid or the method of the request isn't POST try to replace if request.method == 'POST': with if request.POST: and if it doesn't work set the request.session['response'] to any other value just to make sure that the sessions framework isn't broken. You need to debug further, I'm 100% sure that this isn't a session problem.

Categories : Django

Syntax error at "def" in Django views using sessions
def CouponList(req): c = Coupon.objects.all() return render(req,'coupon_list.html',{'title':'Coupons','coupons':c}) ^ | You are missing this bracket

Categories : Python

Django User Sessions, Cookies and Timeout
You can configure the session middleware for logging out the user automatically, configure the SESSION_COOKIE_AGE, to some low value, and provide the SESSION_SAVE_EVERY_REQUEST, as True. This will automatically logout the user after certain inactivity, without any need of extending the profile. SESSION_COOKIE_AGE Default: 1209600 (2 weeks, in seconds) >> The age of session cookies, in seconds. SESSION_SAVE_EVERY_REQUEST Default: False >> Whether to save the session data on every request. If this is False (default), then the session data will only be saved if it has been modified – that is, if any of its dictionary values have been assigned or deleted. And for creating custom/extending User Profile, Django 1.5, comes with configurable User model, please check t

Categories : Python

uWSGI processes lose Django sessions
Have you checked your SESSION_ENGINE ? for example if you set it to use the django caching and set it to locmem:// you will have this kind of problems Another (possible even if hard to happen) problem (if you are in --lazy/--lazy-apps mode) could be a process with an old copy of the code, have you tried reloading the whole instance ?

Categories : Python

How to use different global variable for different browser sessions in Django website
You can get that info from: request.META['HTTP_USER_AGENT'] Some output will be for example: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.70 Safari/537.36 Maybe you can find helpful this snippet

Categories : Django

Storing sessions in database with TTL Expiry.
You can create a TTL index on a collection like db.sessions.ensureIndex( { "createdAt": 1 }, { expireAfterSeconds: 3600 } ). This will create a collection with elements TTL equal to one hour. After a hour is gone, Mongo will automatically remove stale entries. Replication is also supported! I do not know much about storing sessions in DB (I'm working with application servers that handle sessions for me) but I know that some simple frameworks (like bottle or flask for python) use this practice.

Categories : Mongodb

Fluent NHibernate sessions closes the database connection
opening and closing the connection for each use case is the recommended way in ADO.NET Using Connections High performance applications keep connections to the data source in use for a minimal amount of time, as well as take advantage of performance enhancing technology such as connection pooling. Double check that connectionpooling is enabled and supported by the ADO.Net driver you are using. If you really need to have one global connection then implement IConnectionProvider which opens a connection on first CreateConnection and hands out the created each time, however you have to make sure that no 2 databaseoperations are performed at the same time because this is not supported by the connection.

Categories : Dotnet

Slick Database Sessions, Efficiency, and Threading in Akka
Better late than never: The recommended way is using a jdbc connection pool (e.g. c3p0). You need to make sure a session is acquired and returned from and in between kept on the same thread. withSession lazily acquires a connection from the pool and returns it at the end of the scope. Quickly acquire connections when you need them and return them to the pool immediately after.

Categories : Scala

Preferred way to use sessions to avoid hitting the database in rails
I think the standard approach here would be to use a helper method on ApplicationContoller: class ApplicationController < ActionController::Base private def current_audience @current_audience ||= current_user.audience end helper_method :current_audience end This will work pretty much exactly like the current_user helper method in your controllers and views. Depending on the specifics of your application, you may want to add some more robust nil handling, but this is the basic idea.

Categories : Ruby On Rails

Prevent the same row pulled from MSSQL database across multiple sessions
When you query for the person, you could try doing something loike this instead. Select yourPerson from yourTable WITH (rowlock, xlock) WHERE yourPersonid = 1; This will give you an exclusive row lock on the person to prevent other people from using the same person concurrently.

Categories : PHP

SQL Server 2008 : how to select sum of all sessions where difference between two consecutive sessions is less than 10 minutes
Try something like this: WITH DATA AS (SELECT t1.*, CASE WHEN Isnull(Datediff(MI, t2.MESSAGETIME, t1.MESSAGETIME), 11) > 10 THEN 0 ELSE 1 END first_ident FROM TABLE1 t1 LEFT JOIN TABLE1 t2 ON t1.ID = t2.ID + 1), CTE AS (SELECT ID, MESSAGETIME, ID gid, 0 AS tot_time FROM DATA WHERE FIRST_IDENT = 0 UNION ALL SELECT t1.ID, t1.MESSAGETIME, t2.GID, t2.TOT_TIME + Datediff(MI, t2.MESSAGETIME, t1.MESSAGETIME) FROM DATA t1 INNER JOIN CTE

Categories : SQL

Django Cache + Django Database request
So my first question is I'm able to upload images which gets store on the file system,but how do I show only first 10 and then pull a refresh to fetch the next 10 and so on. Fetch first 10 with your initial logic, fetch next photos in chronological order. You must have some timestamp relating to your photo posting. Fetch images according to that. You can use Django Paginator for this. what do I cache Whatever static data you want to show to the user frequently and wont change right away. You can cache per user or for all users. According to that you choose what to cache. should I cache the first 10 photos of each user or something else Depends on you. Are those first pictures common to all the users? Then you can cache. If not and the pictures are user dependent, there is

Categories : Django

How does an iOS app keep a FBSession from expiring?
By using the FBSession with a token, that token will be extended automatically with the newest SDK: https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBSession.m#L236-L260

Categories : IOS

Why does REDIS key keep expiring?
Redis keys do not have a default expiration date. Are you sure there is nothing deleting your key? Can you check if your Redis server gets restarted? Are you using any form of persistance on the Redis data set?

Categories : Ruby On Rails

AngularJS: Expiring cookies?
You could create a cookie from standard JavaScript from within an Angular Ctrl using window.document.cookie. https://developer.mozilla.org/en-US/docs/Web/API/document.cookie Example from documentation: document.cookie = "someCookieName=true; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";

Categories : Angularjs

Self expiring object - any better alternative
Just calculate the expiry lazily: private long expiryDate; // set in constructor public boolean isExpired() { return System.currentTimeMillis() >= expiryDate; } No need to spawn a thread.

Categories : Java

Expiring a javascript variable?
Assuming the actual variable actually exists that long (the page stays open), just do what every cache does: save a timestamp and check for it. var cache = { timestamp : null, data : null }; function setData(data) { cache.data = data; cache.timestamp = new Date; } function getData(maxAge) { if (/* compare cache.timestamp to now - maxAge */) { return null; } return cache.data; }

Categories : Javascript

Cache with expiring keys
Yes, there is ActiveSupport::Cache::Store An abstract cache store class. There are multiple cache store implementations, each having its own additional features. See the classes under the ActiveSupport::Cache module, e.g. ActiveSupport::Cache::MemCacheStore. MemCacheStore is currently the most popular cache store for large production websites. Some implementations may not support all methods beyond the basic cache methods of fetch, write, read, exist?, and delete. ActiveSupport::Cache::Store can store any serializable Ruby object. http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html cache = ActiveSupport::Cache::MemoryStore.new cache.read('Chicago') # => nil cache.write('Chicago', 2707000) cache.read('Chicago') # => 2707000 Regarding

Categories : Ruby On Rails

Django - Unit Tests on localhost creating objects in main database, but not finding them in the test database later in the method
You should use LiveServerTestCase, so that django can run it's own test server and therefore use it's own test db. https://docs.djangoproject.com/en/1.4/topics/testing/#live-test-server

Categories : Python

Django keeps referring to the local database instead of the remote database
You will need to update your settings.py file to point to your new database. This is controlled by the DATABASES dictionary. Also, as an added tip, I would recommend that you update your system and use dj_database_url DATABASES = {'default': dj_database_url.config()} This will keep your database password out of version control. You then just need to create an ENV VAR named DATABASE_URL that contains the information to for your new database. See the documentation or google for more information.

Categories : Django

Private bucket and expiring URLs
Make sure you don't have a bucket policy attached to that bucket that gives everyone permissions to read your files. Also check the ACLs for each file and remove any public-read permissions. Check the S3 docs for more info: http://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingResOpsConditions.html

Categories : PHP

Session Expiring in ASP.net After refreshing any page
See this link. I think this might helps you. http://www.schnieds.com/2009/07/aspnet-session-expiration-redirect.html http://geekswithblogs.net/shahed/archive/2007/09/05/115173.aspx

Categories : C#

Google Maps Android API v2 expiring dev API key
One maps key can easily work with multiple certificates, which allows you to have one Google Maps key, and do not bother which certificate your app is currently signed with. To assign more certificates to one Google Maps key, simply put certificate hash and package name in separate line, i.e.: AA:BB:CC.......;com.webnetmobile.test XX:DD:ZZ.......;com.webnetmobile.test where AA:BB:CC... is certificate hash. One entry is for your debug certificate another for production. You can also edit current key, to add new entries, so no need to recreate (unless you sure that's mandatory)

Categories : Android

Asp.net MVC 3 session not expiring on expected time
Make sure you have disabled sliding expiration: <system.web> <sessionState mode="InProc" timeout="2" /> <authentication mode="Forms"> <forms loginUrl="/Home/Login" timeout="2" slidingExpiration="false" /> </authentication> </system.web> Now no matter whether you are sending requests to the application during the period, the forms authentication cookie won't be renewed.

Categories : Asp Net

Session expiring on Safari Mobile
I found the answer in another question, but as a reference i´ll copy it (the other question is phrased towards another problem but the solution is the same) This is for rails 3.x so the solution is to set the expire time in every request like this: class ApplicationController < ActionController::Base after_filter :short_session ... def short_session request.session_options = request.session_options.dup request.session_options[:expire_after] = 1.minute request.session_options.freeze end This is the original answer where this code was taken. How to I dynamically set the expiry time for a cookie-based session in Rails And yes this fixes the issue with webapp mode in iOS not saving the session.

Categories : Ruby On Rails

Remove cookie by expiring it not working
"You cannot directly delete a cookie on a user's computer. However, you can direct the user's browser to delete the cookie by setting the cookie's expiration date to a past date. The next time a user makes a request to a page within the domain or path that set the cookie, the browser will determine that the cookie has expired and remove it." Please read the following article for more detail. http://msdn.microsoft.com/en-us/library/ms178195(v=vs.85).aspx

Categories : Asp Net Mvc

CakePHP Expiring Headers (Plugins)
Please, check plugin assets seems all your plugin static files handled by dispatcher this is reason of wrong headers. So, try to lead official documentation and create symbolic link

Categories : PHP

Make expiring image or html
Assuming you currently have a custom post type archive template (by default, if your custom post type is named "artwork" it would be archive-artwork.php, you could create a check for the date it was published using the_date() function like so: // expiration date is a rolling date from 30 days ago $expiration_date = date('Ymd', strtotime("-30 days")); // use the_date( $format, $before, $after, $echo ) to get the current post's // date in the loop $post_date = the_date('Ymd', '', '', false); // compare the dates and output different markup or classes to your HTML if ($post_date < $expiration_date) { echo '<div class="expired-post">'; } else { echo '<div class="new-post">'; }

Categories : Wordpress

Expiring a cached item via CacheItemPolicy in .NET MemoryCache
Caching adheres to UTC time to offer uniform time calculations, so you specify a point in time at which the cached entry should expire, in UTC, and the cache will calculate the appropriate difference from now and expire it as expected. Your code will not work as expected since your absolute expiration will be after your cache item is entered once cacheExpiryInSeconds seconds pass, resulting in immediate eviction. You cannot share a CacheItemPolicy instance when AbsoluteExpiration is set in the near future, annoying I know. :)

Categories : C#

Session Variables not expiring with iOS, bootstrap and codeigniter
Apparently that's already set in the config file in codeigniter See more here: http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

Categories : PHP

$_SESSION cookies not expiring when browser is closed
As of your code, session_set_cookie_params() isn't called in any case. Therefore I propose to do this: session_set_cookie_params(0); session_start(); if (isset($_POST['username']) && isset($_POST['password'])) { ... Note, that's actually useful to call session_set_cookie_params() always for session cookies. Generate a new session-ID at each user level change To protect your applications against attackers, it is absolutely required to change the sessionID after each change of the role of a user: Anonymous user -> Logged in user Logged in user -> anonymous user Logged in user -> Administrative logged in user ... Thus, if user gets logged in or logged off, please regenerate the session ID like so: session_regenerate_id( true ); Have a look in OWASP's PHP security chea

Categories : PHP

How to keep cookies from expiring even after browser restart in CakePHP application
update session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0. See also session_get_cookie_params() and session_set_cookie_params(). I think setting your session.cookie_lifetime to such a high value will mean you will have many stale sessions on your server and this might be a issue if you have large numbers of sessions - typically sessions are stored in the system's /tmp folder. When this folder, typically on *nix machines, fills up it could cause problems on the machine - processes start locking up as they fail to create temporary files for whatever reason. (You can change the session.save_path to something other than /tmp so you don't have this issue - especially on shared hos

Categories : PHP

How do I create and save an expiring user token in node js?
First, the user token should be a Model: var mongoose = require( 'mongoose' ); var Schema = mongoose.Schema; var Token = new Schema({ token: {type: String}, createDate: {type: Date, default: Date.now} }); Token.methods.hasExpired= function(){ var now = new Date(); return (now - createDate) > 7; //token is a week old }; //don't forget to add the token as a field in your user mongoose.model( 'Token', Token); Next, in the router, inside the else clause, I would change your findOneAndUpdate to findOne, because you are not updating the whole User object, but simply a property on it. require('crypto').randomBytes(48, function(ex, buf) { var userToken = buf.toString('hex'); User.findOne({email: (req.body.email)}, function(err, usr) { if(err || !usr) {

Categories : Node Js

GAE Application needing to create Expiring Signed URL's to Google Cloud Storage
Using storage.cloud.google.com is requesting cookie based authenticated downloads. Changing: String baseURL = "https://storage.cloud.google.com/myproj/foo.txt" to String baseURL = "https://storage.googleapis.com/myproj/foo.txt" should work better. I'm not sure why you're only seeing this when using the URL created via App Engine. Maybe you're not logged in to Google when testing the App Engine application? Or running it in the local dev server? See the reference URIs section of the docs for details on possible request URIs.

Categories : Google App Engine

Django model-database changes
In order for django to detect changes, you will need to use a third party migration tool called south. Now, since you've already committed meaning you ran python manage.py syncdb, you will need to delete the table and start over. This is how you do it (after you have deleted your table): Install south using pip install south Add south to installed apps, and make sure it comes before all the other apps that you created Run this: python manage.py schemamigration --inital <your app name> Run this: python manage.py migrate <your app name> Run this: python manage.py syncdb <- last time you will need to run it :) Hope this helped.

Categories : Database

How to use Django with existing database?
If you're not using the development version, don't read the docs for that version. All they say is that - new in that version only - models created via inspectdb will by default be marked as managed = False, which means that they can't be modified. But the docs go on to describe exactly how you can modify them, simply by changing that setting. But of course, you should be using the latest stable version, 1.5, which doesn't do that anyway. You can add and edit items in models from a legacy db to your heart's content.

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.