ignore back button or refresh button on the browser

Hi,

I have

index.php, a.php, b.php, c.php, d.php, e.php

I am in d.php now. if i click back button or refresh button on browser, it has to go back to a.php
And also, if I click back button or refresh buttonon browser, it has to go back to a.php.

How can i do that??

bbvicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

justinsaneCommented:
The "and also" part to your question and the first part to your question are the same thing. Did you mean to add somethings else there?

Also, do you only need to get back to a.php when coming (back or reload) from d.php or from all of them?
0
bbvicAuthor Commented:
from all of them..
0
WilliamFrantzCommented:
'index.php, a.php, b.php, c.php, d.php, e.php'

So the first time you display a page, you want it to display normally, but the second time you display a page, you want it redirected to a.php.

If someone requests b.php, they see b.php, but if they reload the page, they see a.php.

If someone requests b.php, they see b.php, if they click on a link to c.php, they see c.php, if they then click 'back', they see a.php (not b.php).

Effectively, a visitor can only see b.php once.  As soon as they leave the page they can't get back to it; ever.  If they reload the page, they are sent someplace else.

First of all, there is no solution that you can implement that can't be foiled by malicious users.  Ultimately, you will need some way to identify returning users and users can always spoof their identification.

Some browsers will allow you to tamper with the history by using Javascript.  You may be able to embed some Javascript to take care of the user trying to go 'back'.

Another approach might be to use $_SERVER['HTTP_REFERER'].  However, it can be spoofed and I don't know what browsers do with the referer header when you reload a page.

What ever you do, you probably want to make sure that none of your pages are cached by doing the following:

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

You could then set a cookie on the visitors machine after they visit each page (other than a.php):

if (isset($_COOKIE['beenHere']))
{
    require('a.php');
    exit;
}
/* set the cookie for 30 days (60s*60m*24h*30d) */
setcookie('beenHere', 'true', time()+60*60*24*30);

Alternately, you could structure it more like this:

if (!isset($_COOKIE['beenToB'] && isset($_REQUEST['B'])
{
    setcookie('beenToB', 'true', time()+60*60*24*30);
    require('b.php');
    exit;
}

Then use links like:
http://server.com/a.php?B

Instead of:
http://server.com/b.php

You chould use IP addresses and some kind of time-out instead of cookies.  The time-out would be necessary to account for DHCP.  Note, this technique wouldn't be as fool-proof but it would be harder for malicious users to spoof.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WilliamFrantzCommented:
The best solution will probably be to always send users to a.php every time and then 'require' the other pages as needed.  This gives you the most control and the only URL that ever gets stored in their history is a.php.  The user doesn't ever need to see the direct URL to the other pages (b.php, c.php, etc.).
0
blue_hunterTechnical ConsultantCommented:
try to work out with the code below


<script language="javascript">
function onUnloadJS(){
document.location.href="a.php";
return true;
}
</script>

<body onunload="onUnloadJS()">
</body>


cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.