11 Replies - 2439 Views - Last Post: 19 July 2010 - 04:56 PM Rate Topic: -----

#1 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 01:05 AM

Good day!

I have a login page and when i input my username and department and i click the submit button i link to another webpage..the problem is when i clickthe back button i go back to the login page. I want that I couldnot go back to login page because i am already login..i don't know what could be the code for that..this is my code in login:

<?php  
session_start(); 
//require_once 'conn.php'; 
$host="localhost"; 
$root="root"; 
$password=""; 
$db_name="dspi"; 


mysql_connect("$host", "$root", "$password") or die("Cannot connect to server"); 
mysql_select_db("$db_name")or die("Cannot select DB");   


        $department = mysql_real_escape_string($_POST['department']);   
        $username = mysql_real_escape_string($_POST['username']); 

        $sql=mysql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mysql_error()); 
        $ct = mysql_num_rows($sql); 
     
        if($ct == 1) { 
            $row = mysql_fetch_assoc($sql);  
         
            if($row['Department']=='Accounting') { 
                header('location: accounting.php'); 
            } elseif($row['Department']=='Engineering') { 
                header('location: engineering.php'); 
            } elseif($row['Department']=='Finishing_Goods') { 
                header('location: finishing_goods.php'); 
            } elseif($row['Department']=='HRAD') { 
                header('location: HRAD.php'); 
            } elseif($row['Department']=='MIS') { 
                header('location: MIS.php'); 
            } elseif($row['Department']=='Packaging_and_Design') { 
                header('location:packaging_design.php'); 
            } elseif($row['Department']=='Production') { 
                header('location:production.php'); 
            } elseif($row['Department']=='Purchasing_Logistic') { 
                header('location:purchasing_logistic.php'); 
            } elseif($row['Department']=='QA_and_Technical') { 
                header('location:QA_technical.php'); 
            } elseif($row['Department']=='Supply_Chain') { 
                header('location:supply_chain.php'); 
            } 
            else {
				header('location:loginv01.php');
				echo"Incorrect Username or Department"; 
				
	        	}  
	}
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script TYPE="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}
//-->
</SCRIPT>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css"> 
<!--
BODY { 
background-image: url(layout_image/bgroundv03.png);
background-attachment: fixed; 
} 
#Layer1 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:1;
	left: 82px;
	top: 95px;
}
#Layer2 {
	position:absolute;
	width:229px;
	height:49px;
	z-index:1;
	left: 441px;
	top: 262px;
}
#Layer3 {
	position:absolute;
	width:186px;
	height:32px;
	z-index:2;
	left: 452px;
	top: 275px;
}
#Layer4 {
	position:absolute;
	width:82px;
	height:35px;
	z-index:3;
	left: 516px;
	top: 320px;
}
#Layer5 {
	position:absolute;
	width:60px;
	height:29px;
	z-index:4;
	left: 524px;
	top: 328px;
}
#Layer6 {
	position:absolute;
	width:130px;
	height:55px;
	z-index:5;
	left: 319px;
	top: 208px;
}
#Layer7 {
	position:absolute;
	width:230px;
	height:46px;
	z-index:6;
	left: 441px;
	top: 216px;
}
#Layer8 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:7;
	left: 45px;
	top: 100px;
}
#Layer9 {
	position:absolute;
	width:59px;
	height:28px;
	z-index:7;
	left: 70px;
	top: 96px;
}
#Layer10 {
	position:absolute;
	width:216px;
	height:30px;
	z-index:7;
	left: 453px;
	top: 228px;
}
--> 
</style>  
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <div id="Layer3">
    <select name="department" onkeypress="return submitenter(this,event)">
      <option>Choose your Department. . . . . . </option>
      <option value="Accounting" <?php if($_POST['department'] == 'Accounting') echo "selected='selected'"; ?>>Accounting</option>
      <option value="Engineering" <?php if($_POST['department'] == 'Engineering') echo "selected='selected'"; ?>>Engineering</option>
      <option value="Finishing_Goods" <?php if($_POST['department'] == 'Finishing_Goods') echo "selected='selected'"; ?>>Finishing Goods</option>
      <option value="HRAD" <?php if($_POST['department'] == 'HRAD') echo "selected='selected'"; ?>>HRAD</option>
      <option value="MIS" <?php if($_POST['department'] == 'MIS') echo "selected='selected'"; ?>>MIS</option>
      <option value="Packaging_and_Design" <?php if($_POST['department'] == 'Packaging_and_Design') echo "selected='selected'"; ?>>Packaging and Design</option>
      <option value="Production" <?php if($_POST['department'] == 'Production') echo "selected='selected'"; ?>>Production</option>
      <option value="Purchasing_Logistic" <?php if($_POST['department'] == 'Purchasing_Logistic') echo "selected='selected'"; ?>>Purchasing and Logistics</option>
      <option value="QA_and_Technical" <?php if($_POST['department'] == 'QA_and_Technical') echo "selected='selected'"; ?>>QA and Technical</option>
      <option value="Supply_Chain" <?php if($_POST['department'] == 'Supply_Chain') echo "selected='selected'"; ?>>Supply Chain</option>
    </select>
  </div>
  <div id="Layer5">
    <input type="submit" name="Submit" value="Submit"/>
  </div>
  <div id="Layer2"><img src="layout_image/subframev02.png" width="229" height="50" /></div>
  <div id="Layer4"><img src="layout_image/subframev02.png" width="80" height="46" /></div>

<div id="Layer6"><img src="layout_image/userv01.png" width="131" height="62" /></div>
<div id="Layer7"><img src="layout_image/subframev02.png" width="229" height="50" /></div>
<div id="Layer10">
  <input name="username" type="text" size="30" />
</div>
</form>
</body>
</html>



This post has been edited by Rhoda Rose: 19 July 2010 - 01:07 AM


Is This A Good Question/Topic? 0
  • +

Replies To: disable the back button so that it would not go back to the login page

#2 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 01:08 AM

Good day!

I have a login page and when i input my username and department and i click the submit button i link to another webpage..the problem is when i clickthe back button i go back to the login page. I want that I couldnot go back to login page because i am already login..i don't know what could be the code for that..this is my code in login:

<?php  
session_start(); 
//require_once 'conn.php'; 
$host="localhost"; 
$root="root"; 
$password=""; 
$db_name="dspi"; 


mysql_connect("$host", "$root", "$password") or die("Cannot connect to server"); 
mysql_select_db("$db_name")or die("Cannot select DB");   


        $department = mysql_real_escape_string($_POST['department']);   
        $username = mysql_real_escape_string($_POST['username']); 

        $sql=mysql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mysql_error()); 
        $ct = mysql_num_rows($sql); 
     
        if($ct == 1) { 
            $row = mysql_fetch_assoc($sql);  
         
            if($row['Department']=='Accounting') { 
                header('location: accounting.php'); 
            } elseif($row['Department']=='Engineering') { 
                header('location: engineering.php'); 
            } elseif($row['Department']=='Finishing_Goods') { 
                header('location: finishing_goods.php'); 
            } elseif($row['Department']=='HRAD') { 
                header('location: HRAD.php'); 
            } elseif($row['Department']=='MIS') { 
                header('location: MIS.php'); 
            } elseif($row['Department']=='Packaging_and_Design') { 
                header('location:packaging_design.php'); 
            } elseif($row['Department']=='Production') { 
                header('location:production.php'); 
            } elseif($row['Department']=='Purchasing_Logistic') { 
                header('location:purchasing_logistic.php'); 
            } elseif($row['Department']=='QA_and_Technical') { 
                header('location:QA_technical.php'); 
            } elseif($row['Department']=='Supply_Chain') { 
                header('location:supply_chain.php'); 
            } 
            else {
				header('location:loginv01.php');
				echo"Incorrect Username or Department"; 
				
	        	}  
	}
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script TYPE="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}
//-->
</SCRIPT>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css"> 
<!--
BODY { 
background-image: url(layout_image/bgroundv03.png);
background-attachment: fixed; 
} 
#Layer1 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:1;
	left: 82px;
	top: 95px;
}
#Layer2 {
	position:absolute;
	width:229px;
	height:49px;
	z-index:1;
	left: 441px;
	top: 262px;
}
#Layer3 {
	position:absolute;
	width:186px;
	height:32px;
	z-index:2;
	left: 452px;
	top: 275px;
}
#Layer4 {
	position:absolute;
	width:82px;
	height:35px;
	z-index:3;
	left: 516px;
	top: 320px;
}
#Layer5 {
	position:absolute;
	width:60px;
	height:29px;
	z-index:4;
	left: 524px;
	top: 328px;
}
#Layer6 {
	position:absolute;
	width:130px;
	height:55px;
	z-index:5;
	left: 319px;
	top: 208px;
}
#Layer7 {
	position:absolute;
	width:230px;
	height:46px;
	z-index:6;
	left: 441px;
	top: 216px;
}
#Layer8 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:7;
	left: 45px;
	top: 100px;
}
#Layer9 {
	position:absolute;
	width:59px;
	height:28px;
	z-index:7;
	left: 70px;
	top: 96px;
}
#Layer10 {
	position:absolute;
	width:216px;
	height:30px;
	z-index:7;
	left: 453px;
	top: 228px;
}
--> 
</style>  
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <div id="Layer3">
    <select name="department" onkeypress="return submitenter(this,event)">
      <option>Choose your Department. . . . . . </option>
      <option value="Accounting" <?php if($_POST['department'] == 'Accounting') echo "selected='selected'"; ?>>Accounting</option>
      <option value="Engineering" <?php if($_POST['department'] == 'Engineering') echo "selected='selected'"; ?>>Engineering</option>
      <option value="Finishing_Goods" <?php if($_POST['department'] == 'Finishing_Goods') echo "selected='selected'"; ?>>Finishing Goods</option>
      <option value="HRAD" <?php if($_POST['department'] == 'HRAD') echo "selected='selected'"; ?>>HRAD</option>
      <option value="MIS" <?php if($_POST['department'] == 'MIS') echo "selected='selected'"; ?>>MIS</option>
      <option value="Packaging_and_Design" <?php if($_POST['department'] == 'Packaging_and_Design') echo "selected='selected'"; ?>>Packaging and Design</option>
      <option value="Production" <?php if($_POST['department'] == 'Production') echo "selected='selected'"; ?>>Production</option>
      <option value="Purchasing_Logistic" <?php if($_POST['department'] == 'Purchasing_Logistic') echo "selected='selected'"; ?>>Purchasing and Logistics</option>
      <option value="QA_and_Technical" <?php if($_POST['department'] == 'QA_and_Technical') echo "selected='selected'"; ?>>QA and Technical</option>
      <option value="Supply_Chain" <?php if($_POST['department'] == 'Supply_Chain') echo "selected='selected'"; ?>>Supply Chain</option>
    </select>
  </div>
  <div id="Layer5">
    <input type="submit" name="Submit" value="Submit"/>
  </div>
  <div id="Layer2"><img src="layout_image/subframev02.png" width="229" height="50" /></div>
  <div id="Layer4"><img src="layout_image/subframev02.png" width="80" height="46" /></div>

<div id="Layer6"><img src="layout_image/userv01.png" width="131" height="62" /></div>
<div id="Layer7"><img src="layout_image/subframev02.png" width="229" height="50" /></div>
<div id="Layer10">
  <input name="username" type="text" size="30" />
</div>
</form>
</body>
</html>



Was This Post Helpful? 0
  • +
  • -

#3 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 01:10 AM

Disabling the back button is impossible with PHP, possible with Javascript but it can be easily gotten around (disabling Javascript entirely comes to mind), and highly discouraged as you can very easily trap your users on a page.

I'd suggest finding an alternative or simply going on without it.

One such alternative would be to have your login form check for a valid session, I guess, and use header() to relocate them to the page they should be on instead, though.
Was This Post Helpful? 2
  • +
  • -

#4 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 01:29 AM

is it possible in php that once she already login she could not login again when she click the back button and she go back to login page?
Was This Post Helpful? 0
  • +
  • -

#5 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 01:48 AM

Yeah. I just told you how to do it, but I'm not going to write it for you.
Was This Post Helpful? 2
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3530
  • View blog
  • Posts: 10,179
  • Joined: 08-June 10

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 02:11 AM

you can "work around" that by using a session. if a user comes to your site, check whether he has an already running session (or his login credentials saved in a cookie), so you can omit the login page.

btw. some users (esp. the more savvy ones) get annoyed, if you disable browser controls (to put it in my words, I donít like pages, that limit me in using my browser)
Was This Post Helpful? 1
  • +
  • -

#7 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 02:39 AM

ok... i try to learn about session()
Was This Post Helpful? 0
  • +
  • -

#8 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 03:22 AM

i already hace a seesion() on the top of my code
Was This Post Helpful? 0
  • +
  • -

#9 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 03:24 AM

I didn't say anything about session_start(). Please read what I said again.
Was This Post Helpful? 1
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 04:57 AM

Merged duplicate topics. Do NOT create duplicate topics.
Was This Post Helpful? 1
  • +
  • -

#11 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 05:10 AM

To help you understand.. here is what Valek is referring to from his first post...

Quote

have your login form check for a valid session, I guess, and use header() to relocate them to the page they should be on instead


Then a simple Google Search...
Was This Post Helpful? 0
  • +
  • -

#12 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: disable the back button so that it would not go back to the login page

Posted 19 July 2010 - 04:56 PM

i try that when i already login and i am in a department page, and i click the back button i back on the login page and i try to login again, sad to say i login again eventhough i login already
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1