page redirecting problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

page redirecting problem

Post 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);
?>
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

Re: page redirecting problem

Post by mrvijayakumar »

Dear yasir_memon,
Use

Code: Select all

ob_start();
in start of the page where you are redirecting. That's all. Problem solved.
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: page redirecting problem

Post 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);

?>
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

Re: page redirecting problem

Post 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);
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: page redirecting problem

Post 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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: page redirecting problem

Post 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.
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

Re: page redirecting problem

Post 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);
?>
Post Reply