I run into a problem using session in .php file i attached in jumi

How do i set a session in in that page? when i use :

```
//this define and require I use from reading the other papers
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );

require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');

$mainframe = JFactory::getApplication('site');
$session = &JFactory::getSession();

if(isset($_GET['id'])){ 
    var_dump($id= $_GET['id[i]']);
} else {echo "No session ";}

// code connect to db
// render out the items
//
foreach($rows as $i=>$row){ 
    $id[$i] = $row['rid'];
    $name[$i] = $row['rname'];

    $view .= '<tr>
                  <td>'.$id[$i].'</td>
                  <td><a href="http://www.thispage.php?id='.$id[$i].'">'.$name[$i].'</a></td>';
?>
}
<p><?php echo $view.'</tr></table>'; ?> </p>

```

......

It doesn't let me find the sub-page of id=1 that I clicked .
What is the better way to deal with this kind of thing?
thank you.