In most cases, your application can let the MapGuide Viewer manage the session state automatically. When the Viewer first loads it creates a session, and it passes the session ID every time it loads an application page.
At times, though, you may want to create the session yourself, in the custom HTML surrounding the Viewer. When you do this, then the session information is available to the surrounding pages, instead of being just available to the Viewer.
You can also create your own session when you want a custom login page or when you want to allow anonymous access without prompting for a user id and password.
For example, you may want to hide the tool bar and task frame completely, and provide all the MapGuide functions directly through the HTML in your custom page. In order to do this, your HTML must pass the session ID to any pages it loads.
To create a new session, authenticate with a user id and password, then use this to create a site connection and new session, as in the following example. Note that this example uses some files from the sample application. You will either need to copy the files to the devguide directory or run this example from the phpviewersample directory.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<?php
include 'AppConstants.php';
MgInitializeWebTier ($configFilePath);
$webLayout =
"Library://Samples/Sheboygan/Layouts/SheboyganPhp.WebLayout";
$user = 'Administrator';
$password = 'admin';
$userInfo = new MgUserInformation($user, $password);
$site = new MgSite();
$site->Open($userInfo);
$sessionId = $site->CreateSession();
?>
<html>
<head>
<title>Viewer Sample Application</title>
<meta content="text/html; charset=utf-8"
http-equiv="Content-Type">
<meta http-equiv="content-script-type"
content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
<link href="style/globalStyles.css"
rel="stylesheet" type="text/css">
</head>
<frameset rows="110,*" frameborder="NO" border="0"
framespacing="0">
<frame src="images/Title.php?AppName=HTML" name="TitleFrame"
scrolling="NO" noresize>
<frame src="images/p>
SESSION=<?= $sessionId ?>&WEBLAYOUT=<?= $webLayout ?>"
name="ViewerFrame">
</frameset>
</html>