Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* in site config */
- $Config['siteSalt'] = 'ksjh2k234jk45kj4uo8vxoise8';
- function hashSteamId($steamId){
- global $Config;
- return sha1($steamId . $Config['siteSalt']);
- }
- /* login.php */
- if(isset($_GET['openid_claimed_id'])){
- $steamId = SteamSignIn::validate();
- //if successful login
- if($steamId){
- $hash = hashSteamId($steamId);
- $cookieData = $steamId.'|'.$hash;
- setcookie('user', $cookieData, time()+60*60*24*365); //sets the cookie for a year
- echo 'Successfully logged in';
- exit;
- }
- echo 'Failed to validate login';
- exit;
- }
- echo '<a href="'.SteamSignIn::genUrl().'">login</a>';
- /* on each page load */
- //tries to load the logged in user. format should be 'steamId|hash'
- $userCookieData = filter_input(INPUT_COOKIE, 'user', FILTER_DEFAULT, FILTER_REQUIRE_SCALAR);
- if($userCookieData){
- //loads the steam id (all data before the "|")
- $userSteamId = strtok($userCookieData, '|');
- //loads the hash (the rest of the str in $userCookieData)
- $userSteamHash = strtok('');
- //checks the hash supplied against what it should be
- if($userSteamHash === hashSteamId($userSteamId)){
- //is valid login. do stuff
- }
- }
- /* logout.php */
- //deletes the cookie
- setcookie('userId', 0, time()-60*60*24*30);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement