Hi everyone,
I'm using Zend but this should be basic PHP.
I have a user that logs in or signs up on a page. When he or she is signed in, he or she is taken to the last page he or she was on. However, when that person clicks the back button, they are right back at the login/sign up screen.
What type of code do I need to use to refresh the page when the back button is pressed so they do not see that sign up page?
Thanks!
Back Button Refresh
Moderator: General Moderators
Re: Back Button Refresh
Well i have an idea that should fix it:
When the user logs in, set a session variable eg: $_SESSION['logged_in'] = true. Then, at the top of the login page, add this:
Be sure to put that code before any HTML output.
When the user logs in, set a session variable eg: $_SESSION['logged_in'] = true. Then, at the top of the login page, add this:
Code: Select all
<?php
if($_SESSION['logged_in'] == true)
{
header('Location: http://www.example.com'); // instead of example.com, add your last visited page code or mainpage location
}
?>
Re: Back Button Refresh
That's a cool solution and I'll try it out...I've actually already tried several session methods (mainly through Zend) that just do not run when pressing the back button because they are all just referring to cache memory from the browser. Cross your fingers!
Re: Back Button Refresh
Code: Select all
<script type="text/javascript">
// onbeforeunload prevents page caching in IE and Firefox:
window.onbeforeunload = function () {
}
// onunload prevents page caching in Safari:
window.onunload = function () {
}
</script>
Re: Back Button Refresh
Reviresco,
I'm kind of <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> that such a perfect workable solution like yours is not easy to find on the internet (actually it was my fault for being close minded to PHP rather than JS). Thank you so much, it's literally plug and play and works!
Mince,
Thanks again for trying to help! It was a great solution but didn't work with the browser.
I'm kind of <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> that such a perfect workable solution like yours is not easy to find on the internet (actually it was my fault for being close minded to PHP rather than JS). Thank you so much, it's literally plug and play and works!
Mince,
Thanks again for trying to help! It was a great solution but didn't work with the browser.
-
kalpesh.mahida
- Forum Commoner
- Posts: 36
- Joined: Wed Oct 06, 2010 7:09 am
Re: Back Button Refresh
Jaceinla,
I think you were right when user click back button the browser refers to cache output of page.
Client browser can be forced to disable caching using php header() function as bellow.
Hope this will help you,
Kalpesh Mahida
I think you were right when user click back button the browser refers to cache output of page.
Client browser can be forced to disable caching using php header() function as bellow.
Code: Select all
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
Kalpesh Mahida