redirecting to next page
Moderator: General Moderators
-
yasir_memon
- Forum Commoner
- Posts: 48
- Joined: Tue Aug 11, 2009 12:29 am
redirecting to next page
hi guys i want to redirect the page when i gaive correct user name and password kindly tell me how can i do this
<?php
$A=$_POST["txt1"];
$B=$_POST["txt2"];
$conn=mysql_connect('localhost','root','server') or die("Error connection server");
$db=mysql_select_db("login",$conn) or die("error connecting database");
echo "connection mysql<br/>";
$sql="select name from log where name='$A' and pwd='$B' ";
echo "connection mysql<br/>";
$res=mysql_query($sql) or die(mysql_error());
echo "connection mysql<br/>";
$count = mysql_num_rows( $res);
if($count>0)
{
// redirect to "index.php" page
}
else
{
echo "invalid user name or password";
}
?>
<?php
$A=$_POST["txt1"];
$B=$_POST["txt2"];
$conn=mysql_connect('localhost','root','server') or die("Error connection server");
$db=mysql_select_db("login",$conn) or die("error connecting database");
echo "connection mysql<br/>";
$sql="select name from log where name='$A' and pwd='$B' ";
echo "connection mysql<br/>";
$res=mysql_query($sql) or die(mysql_error());
echo "connection mysql<br/>";
$count = mysql_num_rows( $res);
if($count>0)
{
// redirect to "index.php" page
}
else
{
echo "invalid user name or password";
}
?>
Re: redirecting to next page
Hello,
Providing your not outputting anything prior to using this, you could use a header redirect.
Thanks 
Providing your not outputting anything prior to using this, you could use a header redirect.
Code: Select all
header('Location: http://www.me.com/');
-
yasir_memon
- Forum Commoner
- Posts: 48
- Joined: Tue Aug 11, 2009 12:29 am
Re: redirecting to next page
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\log.php:6) in C:\wamp\www\log.php on line 16
when i am using header this message is occuring and page is not redirecting kindly tell me how can i do this
when i am using header this message is occuring and page is not redirecting kindly tell me how can i do this
-
yasir_memon
- Forum Commoner
- Posts: 48
- Joined: Tue Aug 11, 2009 12:29 am
Re: redirecting to next page
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\log.php:6) in C:\wamp\www\log.php on line 16
when i am using header this message is occuring and page is not redirecting kindly tell me how can i do this
<?php
$A=$_POST["txt1"];
$B=$_POST["txt2"];
$conn=mysql_connect('localhost','root','server') or die("Error connection server");
$db=mysql_select_db("login",$conn) or die("error connecting database");
echo "connection mysql<br/>";
$sql="select name from log where name='$A' and pwd='$B' ";
echo "connection mysql<br/>";
$res=mysql_query($sql) or die(mysql_error());
echo "connection mysql<br/>";
$count = mysql_num_rows( $res);
if($count>0)
{
header("Location: http://index.php");
}
else
{
echo "invalid user name or password";
}
?>
when i am using header this message is occuring and page is not redirecting kindly tell me how can i do this
<?php
$A=$_POST["txt1"];
$B=$_POST["txt2"];
$conn=mysql_connect('localhost','root','server') or die("Error connection server");
$db=mysql_select_db("login",$conn) or die("error connecting database");
echo "connection mysql<br/>";
$sql="select name from log where name='$A' and pwd='$B' ";
echo "connection mysql<br/>";
$res=mysql_query($sql) or die(mysql_error());
echo "connection mysql<br/>";
$count = mysql_num_rows( $res);
if($count>0)
{
header("Location: http://index.php");
}
else
{
echo "invalid user name or password";
}
?>
Re: redirecting to next page
He said "Providing your not outputting anything prior to using this". You obviously are. You need to reorganise your code so that the header() bit is done before anything else is sent to the user. Try deleting all the echo statements.
Re: redirecting to next page
Remove All echo statements used before the header() redirect.......and try again..........
-
yasir_memon
- Forum Commoner
- Posts: 48
- Joined: Tue Aug 11, 2009 12:29 am
Re: redirecting to next page
thx for ur replies my this problem is resolved
- turbolemon
- Forum Commoner
- Posts: 70
- Joined: Tue Jul 14, 2009 6:45 am
- Location: Preston, UK
Re: redirecting to next page
You could use output buffering to capture all output before the header, then output errors if you don't redirect. http://us2.php.net/manual/en/ref.outcontrol.php
Re: redirecting to next page
That's a pretty nasty performance overhead that you can avoid just by organising your code better. I wouldn't recommend it.turbolemon wrote:You could use output buffering to capture all output before the header, then output errors if you don't redirect. http://us2.php.net/manual/en/ref.outcontrol.php
In other news.. I'm following you on Twitter now (@onion2k).
Re: redirecting to next page
Dont forget to put exit() after your header() as the script will continue to run after your header() which can cause some headaches!