I would like to be sure that a $_SESSION
cannot be fooled in a login scheme involving it. I over-simplified it here to keep only the core of the question.
When using
<?php
$password = "...";
session_set_cookie_params(3600, dirname($_SERVER['SCRIPT_NAME']));
session_start();
if (isset($_POST['pass']) && $_POST['pass'] === $password) {
$_SESSION['iamlogged'] = 1;
}
if (!isset($_SESSION['iamlogged']) || !($_SESSION['iamlogged'] == 1)) {
echo '<html><body><form action="." method="post"><input type="password" name="pass" '
. 'value=""><input type="submit" value="Submit"></form></body></html>';
exit;
}
echo "You logged in in the last 30 minutes.";
// Now we can do some work
is it sure that the last line cannot be displayed for anyone not having the password? Or is there a currently known technique in PHP, to manually force this $_SESSION['iamlogged']
value?
Note: Of course, I do use password hasing+salting, etc., but I removed all of this to focus only on the $_SESSION
safetyness.
Note2: I assume register_globals
is off because PHP is newer than 5.4.
Note3: Here is a live version.