Created
April 1, 2019 22:35
-
-
Save SamJUK/c220e3742487567c6262238edf85695e to your computer and use it in GitHub Desktop.
Modify another php session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
var_dump(session_id()); | |
echo '<br>'; | |
echo '<pre>'; | |
print_r($_SESSION); | |
echo '</pre>'; | |
?> | |
<hr> | |
<a href="login.php"><button>Login</button></a> | |
<a href="logout.php"><button>Logout</button></a> | |
<a onclick="logout_user();"><button>Logout User</button></a> | |
<a href="reset.php"><button>Reset</button></a> | |
<script> | |
function logout_user() { | |
window.location.href = "logout.php?target="+prompt('User Session Id'); | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
$_SESSION['logged_in'] = '1'; | |
header('Location: index.php'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (empty($_GET['target'])) { | |
session_start(); | |
unset($_SESSION['logged_in']); | |
} else { | |
// Save our id so we can revert to it later | |
session_start(); | |
$old_id = session_id(); | |
session_write_close(); | |
// Modify targets session | |
session_id($_GET['target']); | |
session_start(); | |
unset($_SESSION['logged_in']); | |
session_write_close(); | |
// Reset session id to ours | |
session_id($old_id); | |
session_start(); | |
} | |
header('Location: index.php'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
session_regenerate_id(); | |
header('Location: index.php'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment