0

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.

4
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by charvie
0

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;

}

Edited by jhbalaji: n/a

0

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.

0

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.

0

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.

0

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.

Edited by charvie: n/a

0

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.

Edited by niths: n/a

0

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 >.<

Edited by charvie: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.