1

I am new to PHP
i am making a simple login functionality for user with php & mysql

Here i want to make a simple thing where when a user after "loggingin" if presses back button he shouldn't get the login page back on screen.
I have tried using JS history.forward but its little wierd...

It shows glimps of login page for a second and takes back user to same page from where he presses back button...

How to make a facebook like functionality where login page never appears after loging in even on pressing back button..

Please HELP...:)

<?php

include_once 'conn.php';
if (isset($_SESSION['username'])) {
    header('location:home.php');
}

if (isset($_REQUEST['btnsignin'])) {
    if ($_REQUEST['txtemail'] <> "" && $_REQUEST['txtpass'] <> "") {
        $email = $_REQUEST['txtemail'];
        $pass = $_REQUEST['txtpass'];
        $q = mysql_query("SELECT * FROM register WHERE emailid = '" . $email . "' && password = '" . $pass . "'");
        while ($row = mysql_fetch_assoc($q)) {
            $_SESSION['username'] = $email;
            $_SESSION['userid'] = $row['uid'];
            header('location:home.php');
        }
    }
}
?>
Tzar
  • 1,761
  • 2
  • 14
  • 21
AmIt PagarIa
  • 35
  • 1
  • 11

3 Answers3

1

You always want to add exit; after the header() function to prevent the code block below from execution.

sunshinejr
  • 4,834
  • 2
  • 22
  • 32
  • You definitely should use exit();. Otherwise the script execution is not terminated. exit(header("Location: http:// example . com")); or header("Location: http:// example . com"); exit(); See: http://stackoverflow.com/a/3553710/3437255 – Danny Mar 21 '14 at 11:47
0

try to use 'AND' in place of '&&' in your sql query.

Himanshu
  • 4,327
  • 16
  • 31
  • 39
0

you have to start session in php before set it. you can session start with.

 include_once 'conn.php';
 session_start();  //add this line in your code.
   if (isset($_SESSION['username']))
    {
   header('location:home.php');
    }
Maulik Kanani
  • 642
  • 6
  • 22
  • if you neww in php than you can also follow my blog. "http://study-php-example.blogspot.in/" if you like than give me rate on stack overflow. – Maulik Kanani Mar 21 '14 at 15:26