function LoginButton() { if (isset($_POST['logout'])) { unset($_POST); session_destroy(); return 'Logged out.'; } if (!isset($_SESSION['sid']) && isset($_SERVER['REQUEST_METHOD'])) { try { // Change 'localhost' to your domain name. $openid = new LightOpenID('http://endgame.tf'); //$openid = new LightOpenID('http://76.164.223.234'); //elseif ( is_v4() ) $openid = new LightOpenID( 'http://65.111.166.150' ); if (!$openid->mode) { if (isset($_GET['login'])) { $openid->identity = 'http://steamcommunity.com/openid'; header('Location: ' . $openid->authUrl()); } return '<form action="?login" method="post"><input class="steamlogin" type="image" src="img/sits.gif" alt="Login With Steam"></form>'; } elseif ($openid->mode == 'cancel') { return 'User has canceled authentication!'; } else { if ($openid->validate()) { $id = $openid->identity; // identity is something like: http://steamcommunity.com/openid/id/76561197994761333 // we only care about the unique account ID at the end of the URL. $ptn = "/^http:\\/\\/steamcommunity\\.com\\/openid\\/id\\/(7[0-9]{15,25}+)\$/"; preg_match($ptn, $id, $matches); if (strlen($matches[1]) < 16) { return 'Invalid steamid.'; } //echo "User is logged in (steamID: $matches[1])\n"; //session_start(); database_login((int) $matches[1]); $_SESSION['sid'] = (int) $matches[1]; //This is where the user's steamID is set, IMPORTANT. if (isset($_SESSION['sid']) && is_numeric($_SESSION['sid']) == TRUE && !isset($_SESSION['currentUserName'])) { $playerURL = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . AKey() . "&steamids=" . $_SESSION['sid'] . "&format=json"; $playerData = json_decode(get_data($playerURL), true); $_SESSION['currentUserName'] = $playerData['response']['players'][0]['personaname']; //addUser( $_SESSION['sid'] ); header("Location: " . "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); } } else { return 'User is not logged in.'; } } } catch (ErrorException $e) { return $e->getMessage(); } } else { return '<form action="' . $_SERVER['PHP_SELF'] . '" method="post"><INPUT TYPE = "Submit" Name = "logout" VALUE = "Log out"></form>'; } }
$errors[] = 'The username field must not be empty.'; } //if password is not set if (!isset($_POST['user_pass'])) { $errors[] = 'The password field must not be empty.'; } //if there are errors of some description if (!empty($errors)) { echo 'Uh-oh.. a couple of fields are not filled in correctly..'; echo '<ul>'; foreach ($errors as $key => $value) { echo '<li>' . $value . '</li>'; } echo '</ul>'; } else { $result = database_login($_POST['user_name'], $_POST['user_pass']); //if there was an sql error if ($result == database_SQL_ERROR) { echo 'Something went wrong while signing in. Please try again later.'; } else { if ($result == database_CREDENTIAL_ERROR) { echo 'You have supplied a wrong user/password combination. Please try again.'; } else { $_SESSION["signed_in"] = true; echo 'Welcome, ' . $_SESSION['user_name'] . '. <a href="index.php">Proceed to the forum overview</a>.'; } } } } } ?>