This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
example.php
56 lines (37 loc) · 1.5 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
Example usage of SteamAuth
Uses: handlers, login, SteamID, POST Logout
*/
include("SteamAuth/SteamAuth.class.php");
$auth = new SteamAuth();
// You can use this to do other checks on the person, such as making an account in a database
$auth->SetOnLoginCallback(function($steamid){
return true; // returning true will log them in, false will stop the login (you should put an error message in that case)
});
// This handler is for when a login fails Ex: canceled, auth failed, exploit attempt, etc
$auth->SetOnLoginFailedCallback(function(){
return true;
});
// You can use this to do other checks on the person, such as making an modifying a database
$auth->SetOnLogoutCallback(function($steamid){
return true;
});
// Always call Init() on pages you want to check a login from. Call this AFTER you set handlers!
$auth->Init();
// Where we handle the POST logout from the form below
if(isset($_POST['logout'])){
$auth->Logout(); // The logout function also refreshes the page
}
//Check if user is logged in
if($auth->IsUserLoggedIn()){
// Display your content here~
// Display SteamID
echo "Your SteamID is " . $auth->SteamID . "<br/>";
// We use POST to logout so people can't embed images to the logout function and annoy people.
echo "<form method=\"POST\"><input type=\"submit\" name=\"logout\" value=\"Logout\" /></form>";
}else{
// Display login button
echo "<a href=\"" . $auth->GetLoginURL() . "\"><img src=\"assets/sits_large_noborder.png\" alt=\"Sign in through Steam\" /></a>";
}
?>