~ubuntu-branches/ubuntu/utopic/lasso/utopic-proposed

« back to all changes in this revision

Viewing changes to php/examples/sample-sp/logout.php

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2004-09-13 09:26:34 UTC
  • Revision ID: james.westby@ubuntu.com-20040913092634-01vdfl8j9cp94exa
Tags: upstream-0.4.1
ImportĀ upstreamĀ versionĀ 0.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*  
 
3
 * Service Provider Example -- Logout
 
4
 *
 
5
 * Copyright (C) 2004 Entr'ouvert
 
6
 * http://lasso.entrouvert.org
 
7
 * 
 
8
 * Authors: Christophe Nowicki <cnowicki@easter-eggs.com>
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 * 
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 * 
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 */
 
24
 
 
25
  $config = unserialize(file_get_contents('config.inc'));
 
26
 
 
27
 require_once 'DB.php';
 
28
 
 
29
  if (!empty($_GET['SID'])) 
 
30
        session_start($_GET['SID']);
 
31
  else
 
32
        session_start();
 
33
 
 
34
  if (!isset($_SESSION["nameidentifier"])) {
 
35
        print "User is not logged in";
 
36
        exit(0);
 
37
        }
 
38
 
 
39
  lasso_init();
 
40
  
 
41
  $db = &DB::connect($config['dsn']);
 
42
 
 
43
  if (DB::isError($db)) 
 
44
        die($db->getMessage());
 
45
 
 
46
  $server_dump = file_get_contents($config['server_dump_filename']);
 
47
  
 
48
  $server = LassoServer::newfromdump($server_dump);
 
49
  
 
50
  $logout = new LassoLogout($server, lassoProviderTypeSp);
 
51
  
 
52
  $query = "SELECT identity_dump FROM users WHERE user_id='";
 
53
  $query .= $_SESSION['user_id']."'";
 
54
 
 
55
  $res =& $db->query($query);
 
56
  
 
57
  if (DB::isError($res)) 
 
58
        print $res->getMessage(). "\n";
 
59
 
 
60
  $row = $res->fetchRow();
 
61
  
 
62
  $logout->setIdentityFromDump($row[0]);
 
63
  $logout->setSessionFromDump($_SESSION['session_dump']);
 
64
 
 
65
  $logout->initRequest();
 
66
  $logout->buildRequestMsg();
 
67
 
 
68
  $url = parse_url($logout->msgUrl);
 
69
 
 
70
  $soap = sprintf(
 
71
        "POST %s HTTP/1.1\r\nHost: %s:%d\r\nContent-Length: %d\r\nContent-Type: text/xml\r\n\r\n%s\r\n",
 
72
  $url['path'], $url['host'], $url['port'], 
 
73
  strlen($logout->msgBody), $logout->msgBody);
 
74
 
 
75
  # PHP 4.3.0 with OpenSSL support required
 
76
  $fp = fsockopen("ssl://" . $url['host'], $url['port'], $errno, $errstr, 30) or die($errstr ($errno));
 
77
 
 
78
  fwrite($fp, $soap);
 
79
  $ret = fgets($fp);
 
80
 
 
81
  if (!preg_match("/^HTTP\/1\\.. 200/i", $ret)) {
 
82
        die("User is already logged out");
 
83
  }
 
84
 
 
85
  while (!feof($fp)) {
 
86
        $reponse .= @fread($fp, 8192);
 
87
  }
 
88
 
 
89
  fclose($fp);
 
90
 
 
91
  # Destroy The PHP Session
 
92
  $_SESSION = array();
 
93
 
 
94
  session_destroy();
 
95
  
 
96
  $db->disconnect();
 
97
  lasso_shutdown();
 
98
 
 
99
  $url = "index.php";
 
100
  
 
101
  header("Request-URI: $url");
 
102
  header("Content-Location: $url");
 
103
  header("Location: $url");
 
104
?>