visitors of form.php submit a form with a foo
value that should be a
or b
.
form is processed on redirect.php, which should send them right away (PHP header refresh) to a destination according to their foo
value, while displaying a "redirectig you, please wait" message.
I've had a visitor complaining that he was seeing the message but redirection never occured, so I've patched up the following javascript in order to handle such an event, giving the user an option to manually get to the destination, if he wasn't redirected for over 3 seconds.
Are there any vulnerabilities to the method that I'm planning to use? is it a good way to handle this? (also, do you see anything wrong in general with the whole code?)
I would rather use something server-side to display such a message (as I don't want a user who is not being delayed, to be able to view the source and see the destination, which is otherwise only sent in the header), but as far as I understand it is impossible.
<?php
$url = "could-not-get-a-foo-parameter-at-all-error-monitoring-page.html";
if(isset($_POST['foo'])){
switch ($_POST['foo']) {
case "a":
$url = "http://www.aaa.com/";
break;
case "b":
$url = "http://www.bbb.com/";
break;
default:
$url = "foo-parameter-exists-but-is-wrong-error-monitoring-page.html";
break;
}
}
header( "refresh:0;url=$url" );
?>
<!doctype html>
<html>
<head>
<style>
.message {
color:blue;
}
.red {
color:red;
}
</style>
</head>
<body>
<div class="message">Redirecting, Please hold on...</div>
<div id="targetElement" class="red"></div>
<script id="blockOfStuff" language="text">
<a href="<?php echo $url ?>">Click here to be manually redirected</a>
</script>
<script>
var myVar=setTimeout(function(){myTimer()},3000);
function myTimer() {
var div = document.createElement('div');
div.setAttribute('class', 'someClass');
div.innerHTML = document.getElementById('blockOfStuff').innerHTML;
document.getElementById('targetElement').appendChild(div);
}
</script>