Visa källkod
Nedanstående filer finns i denna katalog. Klicka på en fil för att visa dess innehåll.
- .buildpath
- .project
- CCard.php
- CCardHand.php
- CDeck.php
- argyle.jpg
- card.php
- common.php
- deck.php
- grunge.jpg
- hand.php
- index.php
- sessDest.php
- sessions.php
- sessions_mroos.php
- source.php
- template.php
- tiles.jpg
Stäng "sessions.php"
<?php
// ===============================================================
// Contents: Kortgrejer.
// Author: Staffan Lindsgård
// ===============================================================
$pagetitle = "Kortelikort!";
$customhead = '';
$html = '';
require_once "common.php";
echo $page_top;
// ===============================================================
// Inkluderar externa PHP-filer.
require_once "CCardHand.php";
require_once('CDeck.php');
// ===============================================================
// Startar sessionen.
session_start();
// ===============================================================
// Inställningar för felsökning.
error_reporting(-1);
$debug = false;
$debug = (empty($_POST['debug']) ? $debug : $_POST['debug']);
$debug = ($debug=="true" ? true : false);
$debug_out = "<h2 class='debug'>Debug</h2>\n";
// ===============================================================
// Inkommande variabler.
$sesact = (empty($_GET['sesact']) ? FALSE : $_GET['sesact']);
$debug_out = "<h3 class='debug'>Inkommande variabler</h3>\n";
$debug_out = "<p><strong>\$sesact:</strong> {$sesact}</p>\n";
// ===============================================================
// Sessionsinfo.
switch($sesact) {
case 'init': { // Destroy and then initiate the session
require('sessDest.php');
//
// Initiating a session and storing an object in the session variable
//
// http://php.net/manual/en/function.session-start.php
// http://php.net/manual/en/function.session-regenerate-id.php
//
session_start(); // Must call again if we destroyed just destroyed
// the session.
session_regenerate_id(); // To avoid problems
$_SESSION['hand'] = new CCardHand();
$_SESSION['deck'] = new CDeck();
$_SESSION['rounds'] = 0;
// $_SESSION['deck']->Shuffle();
$debug .= 'Session destroyed and created.';
$debug .= 'Current session id is: ' . session_id() . '<br />';
}
break;
case 'destroy': { // Only destroy the session
require('sessDest.php');
$debug .= 'Session destroyed.';
$debug .= 'Current session id is: ' . session_id() . '<br />';
}
break;
default:
break;
}// -------------------------------------------------------------------------------------------
//
// Using the session variable
//
// http://php.net/manual/en/function.isset.php
//
if(isset($_SESSION['deck'])) {
$card = $_SESSION['deck']->DealFromTop();
// Only if there is more cards to retrieve
if($card) {
$card->FlipCard();
$_SESSION['hand']->AddCard($card);
$_SESSION['rounds'] += 1;
} else {
$html .= "<h1><em>The deck is empty.</em></h1>";
}
$html .= "<h1>Leker med sessioner</h1>";
$html .= $_SESSION['hand']->GetHandAsCSS();
$html .= <<<EOD
<p>
Antalet rundor äro {$_SESSION['rounds']}.
<a href='sessions.php'>Ny runda</a>
</p>
EOD;
}
$html .= <<<EOD
<p>
<a href='sessions.php?sesact=init'>Initiera ny session (och förstör den befintliga)</a><br/>
<a href='sessions.php?sesact=destroy'>Förstör sessionen</a>
</p>
EOD;
//$html .= $_SESSION['hand']->GetHandAsCSS();
?>
<h1>Då skall vi se på den lilla handen...</h1>
<p>Jaha, där ser man...</p>
<?php echo $html; ?>
<?php echo $debug_out; ?>
<?php
echo $page_bottom;
?>