The session works on the local server, but not on the web server

Are you doing this in a plugin or on a template file?

Also, you certainly want to ensure that you’re properly setting up sessions. I recommend doing so in functions.php. e.g:

add_action('init', 'track_sessions', 1);
 function track_sessions() { // if session isn't active, set it
  if(!session_id()) {
    session_start();
   }
} 

And using them as you are:

$_SESSION['my_val'] = $val;

Once done, you need to destroy the session:

add_action( 'your_action_here', 'destroy_session', 10, 5 );

 // All done. Destroy session

function destroy_session() {
   session_destroy();
}