开发者

disable browser back button using PHP

can any body tell "How to disable browser back button" us开发者_JAVA技巧ing PHP. I can able to disable using javascript but there is a way to disable using PHP.

I need only for dynamic pages not static pages.


There is no way to disable it via PHP - PHP is a server side language, meaning it cannot interact with anything outside it's server directly.

You could always get PHP to print some JavaScript to disabled the back button.

James


That's client related problem, so no there is no way to disable the back button using server side.

Plus I think it's a bad practice to disable it.

If you want to avoid re submission of forms when the user click the back button, your should take a look in the redirect after post pattern.


You can't disable Back button with PHP. You can disable caching using something like this:

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

This will add the appropriate headers to the HTTP request to inform the browser it should reload the page instead of fetching it through a cache.


PHP is a server sided language. Non of your php code ever is executed on your clients machine. PHP just "generates" the pag and sends the reult to the client. The only sullotion i can think of is, making your PHP code include the javascript in the page you create.


If I understand well your intention, instead of disabling the back button (not a very good idea usabilitywise anyway) you could do a checking with PHP like this (pseudocode) on the login page:

if user is logged in then
     redirect to last page
end

So, if the user clicks the back button, she will be redirected back to the page she was. This pseudocode is of course a bit oversimplistic, you should probably do some checkings, and you should probably warn the user of the redirection, but that's the idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜