I have a website which is hosted on AWS, I cant trust this session array $_SESSION[]
as sometime select * from table_name where id=$_SESSION[id]
doesn't work as expected. I am looking for some session management trick, is it ok If I use Database or Dyanmo DB. If there is a scalable application which has lot of user on it.what would be the prefered way for doing it?
You have 3 basic options for storing sessions in php: file based, memcached, and database backed.
If you use file based session, then you need to use sticky sessions, so subsequent requests from the same user get routed back to the same instance. This may not work if you are using autoscaling - if an instance is stopped, then that user will lose his session.
You can use memcached, where there is a single memcached instance that stores session. This is probably the easiest option. No state is saved on the instances, and you do not need to use sticky session. As long as you don't exceed the available memory for memcached, you should be OK.
The third option is to use a database backed session. This should have the same effect as using memcached sessions, but does allow more complex behavior - for instance, you can replicate your databases across datacenters and theoretically that allows you to have an application that scales across multiple regions.