If you do not want $name to print if the session isn't started, one method is this:
On a previous page, start a session using session_start(), then set a session variable. You can define a variable then register it:
page1.php
<?
session_start();
$myVariable = "some value";
session_register('myVariable');
rest of code here...
?>
page2.php
<?
session_start()
if(session_is_registered('myVariable')){
echo 'My name: '.$name;
}
else{
do something else...
}
?>
This way, if the page is accessed directly, if the session variable hasn't been registered from a previous page, do something else... will execute, otherwise the echo statement will.
Hope this helps.