Hi,

Anyone,please help me ...............
my first page called index.php (which has username and password field to enter to move on to next page)

index.php code
<?php
session_start();


mysql_connect("localhost", "root", "")or die("cannot connect");
mysql_select_db("artedb")or die("cannot select DB");



if (isset($_POST) && ($_POST == "submit"))
{
if($_POST=="" && $_POST=="")
{
$msg="Please enter the User Name or Password";
}
else
{
$q=mysql_query("select * from login where username='".$_POST."' and password='".$_POST."'")or die(mysql_error());
$rowcount=mysql_num_rows($q);
if($rowcount==1)
{
$_SESSION="";
$_SESSION=$_POST;
header("Location:search.php");
}
else
{
$msg="Please enter a valid User Name or Password";
}
}
}
?>
<html>
<head>
<title>ARTE</title>
<style type="text/css">
.style1 {font-size: 18px; font-weight: bold; color:25547D; font-family:Verdana;}
.style2 {font-size: 12px; font-weight: bold; color:25547D; font-family:Verdana;}
.style3 {font-size: 11px; font-weight: bold; color:black;  font-family:Verdana;}
.style4 {font-family: Verdana;font-weight: normal;font-size: 11px;color: #404040;background-color: #fafafa;border: 1px #ffffff solid;
border-collapse: collapse;border-spacing: 0px;margin-top: 10px;
}
</style>
</head>
<body>
<table align="center" >
<tr>
<td align="center"><br /><br />
<span class="style1">    Indian Institute of Technology Madras <br /></span>
<span class="style2">    Chennai - 600 036. <br /></span>
</td>
</tr>
</table><br /><br /><br /><br /><br />
<table align="center">
<tr><td><font color="blue"><b>Login Details</b></font></td></tr>
</table>
<table align="center">
<tr><td><font color="#FF0000"><b><? echo $msg; ?></b></font></td></tr>
</table>
<form method="POST" name="newentry">
<span class="style4">
<table width="40%" border="0" cellpadding="0" cellspacing="5" align="center">


<tr>
<td width="50%" align="center"><span class="style3">User Name <font color=red>*</font></span></td>
<td><input name="uname" type="text" id="uname" value="<?= $_POST[uname] ?>"></td>
</tr><tr><td></td></tr>
<tr>
<td width="50%" align="center"><span class="style3">Password <font color=red>*</font> </span></td>
<td><input type="password" name="pass" id="pass" size=22/></td>
</tr><tr><td></td></tr>
<tr>
<td align="right">
<input type="submit" name="submit" id="submit" value="submit" />
</td>
<td><input type="reset" name="reset" id="reset" value="Reset" /></td>
</tr>
</table>
</span>
</form>
</body>
</html>

this above code is working fine.

second page called search.php, in this page, i created a submit button called "LOGOUT". In logout only,i am facing a big problem.when by clicking "Logout button", i redirected to first page `index.php.

logout.php
<?
session_start();
session_destroy();
header ("Location: index.php");
?>

its also redirecting to that page correctly (no problem in this)

But, when i clicking "BACK or FORWARD BUTTON" on the browser (any browser), it showing all my previous used page (search.php, update.php, delete.php etc).

i dont need like this...........

how to use session_destroy() or session_unset() or how to delete the cookies .

when by clicking back or forward button in the browser ,i want to restrict from going to previous page.

regards,
santhanalakshmi.

Hi

What you need to do is set a session when the user logs in. By doing this you can test if it is still alive on other pages and if not, redirect the user to a 'please login page'.

The following will set the session when the user logs in

$q=mysql_query("select * from login where username='".$_POST['uname']."' and password='".$_POST['pass']."'")or die(mysql_error());
$rowcount=mysql_num_rows($q);
if($rowcount==1)
{
$_SESSION['uname']="";
$_SESSION['uname']=$_POST['uname'];
[B]$_SESSION['logedin'] = true;[/B]
header("Location:search.php");
}

After this you should then add:

<?php
session_start();
if (!isset ($_SESSION['logedin']) || $_SESSION['logedin'] != true) {
header('Location: http://www.google.co.uk');
}
?>

Obviously changing www.google.co.uk :)

Anyway, i hope this helps. If theres anything else just ask.

Cya soon

Thanks for ur response...........................

what do you mean 'logedin'.
$_SESSION = true;


and also where i should copy this code

<?php
session_start();
if (!isset ($_SESSION) || $_SESSION != true) {
header('Location: http://www.google.co.uk');
}
?>


did u had any idea "how to disable back button in the browser when user logout ,(it redirects to index.php page )in either php or javascript

santhanalakshmi.

Hi

<?php
session_start();
if (!isset ($_SESSION['logedin']) || $_SESSION['logedin'] != true) {
header('Location: http://www.google.co.uk');
}
?>

This should go at the top (before any html, line1) of any page you want to make sure that the user is logged in.
All its doing is asking if there is a session stored that sais the user has logged in, and if not directs them to google.co.uk (like i said, change that to whatever you want).


This is the full code you asked for.

<?php
session_start();

mysql_connect("localhost", "root", "")or die("cannot connect");
mysql_select_db("artedb")or die("cannot select DB");


if (isset($_POST['submit']) && ($_POST['submit'] == "submit"))
{
if($_POST['uname']=="" && $_POST['pass']=="")
{
$msg="Please enter the User Name or Password";
}
else
{
$q=mysql_query("select * from login where username='".$_POST['uname']."' and password='".$_POST['pass']."'")or die(mysql_error());
$rowcount=mysql_num_rows($q);
if($rowcount==1)
{
$_SESSION['uname']="";
$_SESSION['uname']=$_POST['uname'];
[B]$_SESSION['logedin'] = true;[/B]
header("Location:search.php");
} 
else
{
$msg="Please enter a valid User Name or Password";
}
}
}
?>
<html>
<head>
<title>ARTE</title>
<style type="text/css">
.style1 {font-size: 18px; font-weight: bold; color:25547D; font-family:Verdana;}
.style2 {font-size: 12px; font-weight: bold; color:25547D; font-family:Verdana;}
.style3 {font-size: 11px; font-weight: bold; color:black; font-family:Verdana;}
.style4 {font-family: Verdana;font-weight: normal;font-size: 11px;color: #404040;background-color: #fafafa;border: 1px #ffffff solid;
border-collapse: collapse;border-spacing: 0px;margin-top: 10px;
}
</style>
</head>
<body>
<table align="center" >
<tr>
<td align="center"><br /><br />
<span class="style1"> Indian Institute of Technology Madras <br /></span>
<span class="style2"> Chennai - 600 036. <br /></span>
</td>
</tr>
</table><br /><br /><br /><br /><br />
<table align="center">
<tr><td><font color="blue"><b>Login Details</b></font></td></tr>
</table>
<table align="center">
<tr><td><font color="#FF0000"><b><? echo $msg; ?></b></font></td></tr>
</table>
<form method="POST" name="newentry">
<span class="style4">
<table width="40%" border="0" cellpadding="0" cellspacing="5" align="center">

<tr>
<td width="50%" align="center"><span class="style3">User Name <font color=red>*</font></span></td>
<td><input name="uname" type="text" id="uname" value="<?= $_POST[uname] ?>"></td>
</tr><tr><td></td></tr>
<tr>
<td width="50%" align="center"><span class="style3">Password <font color=red>*</font> </span></td>
<td><input type="password" name="pass" id="pass" size=22/></td>
</tr><tr><td></td></tr>
<tr>
<td align="right">
<input type="submit" name="submit" id="submit" value="submit" />
</td>
<td><input type="reset" name="reset" id="reset" value="Reset" /></td>
</tr>
</table>
</span>
</form>
</body>
</html>

did u had any idea "how to disable back button in the browser when user logout ,(it redirects to index.php page )in either php or javascript

I dont really understand what you mean ?
If you explain more, il try and help as much as i can.

Hope this helps.
Thanks

Hi,

Anyone,please help me ...............
my first page called index.php(which has username and password field to enter to move on to next page)

index.php code

<?php
        session_start();

        mysql_connect("localhost", "root", "")or die("cannot connect"); 
    mysql_select_db("artedb")or die("cannot select DB");    


    if (isset($_POST['submit']) && ($_POST['submit'] == "submit")) 
    {
        if($_POST['uname']=="" && $_POST['pass']=="")
        {
        $msg="Please enter the User Name or Password";
            }
        else
        {
        $q=mysql_query("select * from login where username='".$_POST['uname']."' and password='".$_POST['pass']."'")or die(mysql_error());
        $rowcount=mysql_num_rows($q);
        if($rowcount==1)
        {
           $_SESSION['uname']="";
           $_SESSION['uname']=$_POST['uname'];
           header("Location:search.php");
        }       
        else
        {
            $msg="Please enter a valid User Name or Password";
        }                                       
       }
}              
?>
<html>
    <head>
    <title>ARTE</title>           
    <style type="text/css">
        .style1 {font-size: 18px; font-weight: bold; color:25547D; font-family:Verdana;}
        .style2 {font-size: 12px; font-weight: bold; color:25547D; font-family:Verdana;}
        .style3 {font-size: 11px; font-weight: bold; color:black;  font-family:Verdana;}
        .style4 {font-family: Verdana;font-weight: normal;font-size: 11px;color: #404040;background-color: #fafafa;border: 1px #ffffff solid;
                border-collapse: collapse;border-spacing: 0px;margin-top: 10px;
                }       
    </style>
        </head>
    <body>
        <table align="center" >
          <tr>
             <td align="center"><br /><br />
            <span class="style1">    Indian Institute of Technology Madras <br /></span>
            <span class="style2">    Chennai - 600 036. <br /></span>
             </td>
          </tr>
        </table><br /><br /><br /><br /><br />
        <table align="center">
            <tr><td><font color="blue"><b>Login Details</b></font></td></tr>
        </table>
        <table align="center">
            <tr><td><font color="#FF0000"><b><? echo $msg; ?></b></font></td></tr>
        </table>
    <form method="POST" name="newentry">
       <span class="style4">
        <table width="40%" border="0" cellpadding="0" cellspacing="5" align="center">   

            <tr>
            <td width="50%" align="center"><span class="style3">User Name <font color=red>*</font></span></td>
            <td><input name="uname" type="text" id="uname" value="<?= $_POST[uname] ?>"></td>           
            </tr><tr><td></td></tr>          
            <tr>
            <td width="50%" align="center"><span class="style3">Password <font color=red>*</font> </span></td>
            <td><input type="password" name="pass" id="pass" size=22/></td>
            </tr><tr><td></td></tr>
            <tr>
            <td align="right">       
                    <input type="submit" name="submit" id="submit" value="submit" />        
            </td>
            <td><input type="reset" name="reset" id="reset" value="Reset" /></td>
            </tr>
        </table> 
       </span>
    </form>
    </body>
</html>

this above code is working fine.

second page called "search.php", in this page, i created a submit button called "LOGOUT". In logout only,i am facing a big problem.when by clicking "Logout button", i redirected to first page index.php.

logout.php

<?
session_start();
session_destroy();
header ("Location: index.php");
?>

its also redirecting to that page correctly .(no problem in this)

But, when i clicking "BACK or FORWARD BUTTON" on the browser (any browser),it showing all my previous used page(search.php,update.php,delete.php etc).

i dont need like this...........

how to use session_destroy() or session_unset() or how to delete the cookies .

when by clicking back or forward button in the browser ,i want to restrict from going to previous page.

regards,
santhanalakshmi.

Hi

Use  <?php 
// set the expiration date to one hour agosetcookie("user", "", time()-3600);
?> 
to delete cookie
regards
nicky

Nicky space, by setting to see if the user is logged in and making it expire to a certain amount of time isnt a very effective way of checking if the user it logged in. It limits the time they can be logged in.

Read the comment I wrote above, sessions would be better for this example.

Regards

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.