hi all,
i need to disable the back button if the url address is login.php. so i am having the code for restricting the back button. so if in url the address is login.php then the browser back button should not work.
here is my code for restrcting back button.

<script language="javascript" type="text/javascript"> 
function backButtonOverride()
{
  
  setTimeout("backButtonOverrideBody()", 1);

}

function backButtonOverrideBody()
{
  
  
  try {
    history.forward();
  } catch (e) {
    // OK to ignore
  }
  
  setTimeout("backButtonOverrideBody()", 0);
}</script>

Thanks in advance.

Just Copy Paste the Code in login.php
Its a dynamic page created by you script
Then use a Switch case

$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
Switch($url):{
default:
//Nothing here
break;
case 'http://domain.com/login.php':
echo '
<script language="javascript" type="text/javascript"> 
function backButtonOverride()
{
  
  setTimeout("backButtonOverrideBody()", 1);

}

function backButtonOverrideBody()
{
  
  
  try {
    history.forward();
  } catch (e) {
    // OK to ignore
  }
  
  setTimeout("backButtonOverrideBody()", 0);
}</script>';
// Put all your backslashes
break;

}

i just copy pasted the above code but even then it is going back to the page from where i logout. i am suffering alot because of this. i wil be thankful to u if it got solved.
Thanks in advance.

you could try using sessions? so there would be no need to disable the back button.
i don't really know how to disable it sorry.

in another page i tried destroying sessions. and it is working but if i logout from X page i wil cum to login page.Now if i click on browser back button i am going to the X page and if i refresh that X page again i wil cum to login page, and now even if i click on back button i cant go.
my code in X page is

<?php
session_start();  
if(!isset($_SESSION['username']))
@header("Location:http://10.70.2.142/Project/login.php");
ob_end_flush(); 
?>

so wenever i refresh the code runs and then session value is null so it will cum to login.php
so wat i need is after logout even if i click on back button it should not go back and stay in the same login page.

hmm....well, what i do is. i have a session in my login page.

say

if()
{
//check if login data is correct
$_SESSION['FLAG']=1;
header("Location:home.php");
}

then say in X.php

i'll have something like this

if($_SESSION['FLAG']!=1)
{
header("Location:login.php");
}

so the session will only turn 1 if the user has loged in.

thanks for ur response.i had done the same way but the problem is when i click on back button it should check this

if($_SESSION['FLAG']!=1)
{
header("Location:login.php");
}

so for that the X page should get refreshed. so my problem is here if i kept meta refresh for 3 sec. wen i click back button i can see the x page for 3 sec and then it gets refreshed so then it check the condition and return to login page.
i dont want to see that page for such a long time.

hmm..i haven't tried disabling the back button before.sorry.

but 3 sec is quick already xD

good luck on that quest ^^

sorry i don't have any idea when it comes to caching >.<

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.