I have done a conditional redirect with javascript (depending of referer). However now I need to detect if user got redirected and then he clicked back button and got again to the page he has been redirected from. In this case I need no to redirect him again.
I have found a solution here - but I am failed to combine php and javascript properly, so there is always an error - How do I detect if a user has got to a page using the back button?
Code:
<form name="ignore_me">
<input type="hidden" id="page_is_dirty" name="page_is_dirty" value="0" />
</form>
<script language="javascript" type="text/javascript">
var dirty_bit = document.getElementById('page_is_dirty');
if (dirty_bit.value == '1') {
document.write("<p>Do Not Redirect</p>");
}
else {
<?php if((stristr($_SERVER['HTTP_REFERER'],"thoughts") != FALSE) { ?>
<?php $setupform = '<form id="form1" method="post" action="http://yahoo.com">'; ?>
<?php $submitform = 'document.getElementById(\'form1\').submit(); </form>'; ?>
<?php echo $setupform; ?>
<?php echo $submitform; ?>
<?php } ?>
}
function mark_page_dirty() {
dirty_bit.value = '1';
}
</script>
What is wrong here?
The error is that it simply doesn't redirect - it gives a blank page with code on it:
<form name="ignore_me">
<input type="hidden" id="page_is_dirty" name="page_is_dirty" value="0" />
</form>
<script language="javascript" type="text/javascript">
var dirty_bit = document.getElementById('page_is_dirty');
if (dirty_bit.value == '1') {
document.write("<p>My First JavaScript</p>");
}
else {
<form id="form1" method="post" action="http://yahoo.com">document.getElementById('form1').submit(); </form>
}
function mark_page_dirty() {
dirty_bit.value = '1';
}