It is not all about Java or PHP. HTTP is a stateless protocol.
To make it stateful, the developer (programmer) has to make sure that all relevant information is stored and make sure that all relevant information is read back in when the script is called upon.
Most of the servers provide session management for stat management.
As to why stateless - stateful session add significant memory and performance overhead see:
models-with-persistent-state-between-http-requests