0

have created a login page.. then welcome page... but user cant go directly to welcome page...if user tries to go to welcome page it is redirected to login page... but getting error....

have tried most of the answers in SOF,,, no hope

Cannot modify header information - headers already sent by

<script type="text/javascript">
function delayer(){
    window.location = "login.html"
}
</script>
<?php session_start();
$_SESSION['username']=$username;
?>
<body onLoad="setTimeout('delayer()',5000)">
<?php
include "l_db.php";
$username=$_POST['username'];
$password=$_POST['password'];
$sqal="SELECT * FROM login where username='$username' and password='$password'";
$query=mysql_query($sqal) or die(mysql_error());
$q=mysql_num_rows($query);
if($q>0)
{
echo $username;
//session_start();
//$_SESSION['username']=$username;
header('location:adminarea.php');
}
else
{
echo $password;
echo $_SESSION['username'];
echo "InValid Username or Password";
header("location:adminarea.php");
//echo "<center>    <img src=http://blog.karachicorner.com/blog-images/ajax-loading-bar/ajax-loading-bar-26.gif></center>";
}
?>

have tried most of the answers in SOF

  • There can't be any output before using `header()`. You have plenty of output before ... – Sirko Aug 03 '14 at 15:57

2 Answers2

1

You can't put echo statements before the header(...) statement.

Make sure you use header(...) before you do any echo-ing and you should be fine.

sifriday
  • 4,342
  • 1
  • 13
  • 24
0

You have already sent out

<script type="text/javascript">
function delayer(){
    window.location = "login.html"
}
</script>

and <body onLoad="setTimeout('delayer()',5000)">

before header('location:adminarea.php');, therefore it does not work. You should not send anyting out before you send headers.

Karl
  • 833
  • 6
  • 13