Page 1 of 1
page redirecting problem
Posted: Wed Aug 19, 2009 4:19 am
by yasir_memon
this code is working properly but it is not redirecting to other page it shows the warning message
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\RMS\login.php:8) in C:\wamp\www\RMS\login.php on line 105
if i replace header with echo it give me right output so kindlt tell me now why it is not redirecting to other page
<?php
$A=$_POST["text1"];
$B=$_POST["text2"];
$conn=odbc_connect('AKTMAPP','ERP_TEST','ERP_TEST');
$sql="SELECT 1 A FROM USERS WHERE USR_NAME='$A' and PASSWORD='$B'";
$rs=odbc_exec($conn,$sql);
$count = odbc_result($rs,"A");
if($count>0)
{
header("Location:log.html");
}
else
{
echo "invalid user name or password";
}
odbc_close($conn);
?>
Re: page redirecting problem
Posted: Wed Aug 19, 2009 5:08 am
by mrvijayakumar
Dear yasir_memon,
Use
in start of the page where you are redirecting. That's all. Problem solved.
Re: page redirecting problem
Posted: Wed Aug 19, 2009 5:22 am
by yasir_memon
thanks dear i used this code but still same warning message so kindly check this waiting for your reply
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\RMS\login.php:8) in C:\wamp\www\RMS\login.php on line 106
<?php
$A=$_POST["text1"];
$B=$_POST["text2"];
$conn=odbc_connect('AKTMAPP','ERP_TEST','ERP_TEST');
$sql="SELECT 1 A FROM USERS WHERE USR_NAME='$A' and PASSWORD='$B'";
$rs=odbc_exec($conn,$sql);
$count = odbc_result($rs,"A");
//if (!$rs)
//{
//exit("Error in SQL");
//}
if($count>0)
{
//echo "gooooooooooooooood";
ob_start();
header("Location:log.html");
}
else
{
echo "invalid user name or password";
}
odbc_close($conn);
?>
Re: page redirecting problem
Posted: Wed Aug 19, 2009 5:34 am
by mrvijayakumar
Try this code,
Code: Select all
header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Location: login.php", true, 302);
Re: page redirecting problem
Posted: Wed Aug 19, 2009 5:38 am
by yasir_memon
dear now three headers and three warning messages are there kiindly check this
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\RMS\login.php:8) in C:\wamp\www\RMS\login.php on line 107
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\RMS\login.php:8) in C:\wamp\www\RMS\login.php on line 108
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\RMS\login.php:8) in C:\wamp\www\RMS\login.php on line 109
Re: page redirecting problem
Posted: Wed Aug 19, 2009 5:40 am
by jayshields
This has been discussed on this forum and many other places hundreds of times. You cannot send headers to the browser if you have already sent anything to the browser (including white space). Be extra careful when including PHP files which send headers.
Re: page redirecting problem
Posted: Wed Aug 19, 2009 5:47 am
by yasir_memon
the i am sending is total php code before this iused only html code so kindly tell me where i am sending header before if condition or any white space waiting for repli
<?php
$A=$_POST["text1"];
$B=$_POST["text2"];
$conn=odbc_connect('AKTMAPP','ERP_TEST','ERP_TEST');
$sql="SELECT 1 A FROM USERS WHERE USR_NAME='$A' and PASSWORD='$B'";
$rs=odbc_exec($conn,$sql);
$count = odbc_result($rs,"A");
if($count>0)
{
header("Location: login.php");
}
else
{
echo "invalid user name or password";
}
odbc_close($conn);
?>