Unless this is included in a larger script you need to call session_start() before you try to access session variables. Also before any output is sent to the browser:
<?php
session_start(); //Starts the previously initialized session, or creates a new one.
$username = $_SESSION['user'];
$userid = $_SESSION['id'] ;
And then you should also be checking to verify that the session variables you want are initialized before trying to use them.
<?php
session_start(); //Starts the previously initialized session, or creates a new one.
if( isset($_SESSION['user']) ) {
$username = $_SESSION['user'];
}
if( isset($_SESSION['id']) ) {
$userid = $_SESSION['id'] ;
}